We're using Jeff Moden's DelimitedSplit8K table valued function published in the following article [url=http://www.sqlservercentral.com/articles/Tally+Table/72993/]http://www.sqlservercentral.com/articles/Tally+Table/72993/[/url]Our system vendor is upgrading from SQL 2000 to SQL 2014 and we have found that an implicit conversion error occurs when converting varchar to numeric using the DelimitedSplit8K function in the where clause. Using the following code, the DelimitedSplit8K function works without error on the existing SQL 2000 database but not on the new SQL 2014 database (collation is the same on both databases Latin1_General_CI_AS). Before we update all the SSRS reports and SQL objects that use the DelimitedSplit8K function in the where clause I'm keen to understand if there is a SQL configuration option we've overlooked that will keep it converting varchar to numeric implicitly.[code="sql"]set nocount on--declare a table variable to store some made up data about organisation invoices--note the data type of the org_id field is numeric(10,0)declare @invoice table (inv_id int,inv_amt money,org_id numeric(10,0))--populate the table variable with some made up data to test with--the table contains invoice data for organisations 1, 2 and 3insert into @invoice values (1,10987.89,1)insert into @invoice values (2,90978.00,3)insert into @invoice values (3,11786.67,2)insert into @invoice values (4,78096.12,2)--declare and set a variable to store a comma separated list of organisation idsdeclare @org_list varchar(8000)set @org_list = '2,3'--use the comma separated list of org_id as criteriaaselect *from @invoice iwhere i.org_id in (select item from BH.DelimitedSplit8K(@org_list,','))[/code] The function works fine on SQL 2000 and SQL 2005 but in SQL 2008 and SQL 2014 I get the following error message:[color=#FF0000]Msg 8114, Level 16, State 5, Line 12Error converting data type varchar to numeric.[/color]What am I missing? Is there something I can do to the DelimitedSplit8K function or is there a SQL configuration issue I need to resolve?Casting the org_id field in the example above to an integer works but I would need to do this in many SQL objects and SSRS reports. The following MSDN article suggests conversion from varchar to numeric is implicit [url=https://msdn.microsoft.com/en-us/library/ms191530.aspx]https://msdn.microsoft.com/en-us/library/ms191530.aspx[/url]Interestingly, the implicit conversion is successful when the DelimitedSplit8K function is joined to other tables. For example:[code="sql"]--declare and set a variable to store a comma separated list of organisation idsdeclare @org_list varchar(8000)set @org_list = '2,3'--use the comma separated list of org_id as criteriaaselect *from @invoice iinner join BH.DelimitedSplit8K(@org_list,',') ds on i.org_id = ds.Item[/code]Any help greatly appreciated.
↧