Tuesday 15 April 2014

split - SQL server - Conversion failed error but not really -


I have a user-defined function to split the list of integers in the table of values, I use this as a special I am doing to parse the input to select a set of records for type types or situations.

This works: Request from * RequestStatus where the selection of [Value] from RequestStatusUID (Dbo.SplitIDs ('1,2,3', ',') Do not have it:

  Select * from requests where RequestStatusUID (dbo.SplitIDs ('1,2,3', ',' ) Select [value] from)   

query error of request " Conversions Varchar failed to convert value '1, 2, 3' into data type int . "RequestStatusUID" are integer columns on both tables. Explain both schemes. Tempt ye are functions working in unrelated questions exactly the same way. As far as I can tell it only requests table problem.

  Create a table [dbo]. [Request] ([RequestUID] int identity (1,1) NOT NULL, [that UserUID] int NOT NULL, [LocationUID] int NOT NULL, [DateOpened] on zero, [DateClosed] on zero, [RequestStatusUID] int nOT nULL, [DiscussionUID] integer zero, [RequestTypeUID] int nOT nULL, [RequestNo] varchar (16) nOT nULL, [LastUpdateUID] int nOT nULL, [LastUpdated] on not nULL, constraint [PK_Requests] primary key nonclustered ([RequestUID ]}   

This works if I use a different function varchars and I also change the RequestStatusUID column to a varchar:

  Choose * From the request where the cast (in the form of RequestStatusUID varchar (4)) (selection [value] dbo.Split ('1,2,3', ','))   

for, SplitIDs function I'm using (a modified version). the same without Split function Insert as Int finally:

  optional function [DBO]. [Splitaidi] (@tr varta) r (max), @delim four (1) = ',') Returns (as per CTE (selection 0, 1b select all of the union b, cast (CHARINDEX (@delim, @str, b) ) Returns the table as + 1 with C The Minister) where B & gt; A) Select cast (ART, A, A, B and 1; BA-1) BA-1 AS lane (AT + 1 end) as ANT) [Price] Whistle with A & gt; 0)   

I can use a convert-to-string solution but I really need to know why it is failing in the first place.

I think you'll find that this sentence performs a lot better.