Hi;
I've just found what I think is a bug in the syntax validator algorithm for error 137;
The code below reproduces the escenario:
create database test137
go
use test137
go
create type dbo.testtype as table (col1 int null)
go
create function dbo.testfn (@minormax bit, @testable dbo.testtype readonly) returns int as
begin
return 1
end
go
declare @myxml xml = '<root some="0" />'
declare @mytable dbo.testtype;
insert @mytable values (19), (5), (22), (8848);
select dbo.testfn(t.minmax, @mytable) -- works good
from @myxml.nodes('root') r(x)
cross apply ( select minmax = r.x.value('@some', 'bit') ) t;
go
declare @myxml xml = '<root some="0" />'
declare @mytable dbo.testtype;
insert @mytable values (19), (5), (22), (8848);
select dbo.testfn(r.x.value('@some', 'bit'), @mytable) -- fail, undocumented reason.
from @myxml.nodes('root') r(x);
go
drop function dbo.testfn
drop type testtype
go
use master
go
drop database test137
go
Notice that the line commented with "works good" do the same query than the other commented with "fails".
I'm running this sql versión: Microsoft SQL Server 2014 - 12.0.2000.8 (X64)
Feb 20 2014 20:04:26
Copyright (c) Microsoft Corporation
Standard Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)