I have a string which is a output from a function eg: "1,3,16,..,..". I used the following sql query and ran it in the query builder in VS and it didn't give me any syntax errors.
SELECT ItemID, Name, RelDate, Price, Status FROM item_k WHERE (ItemID = cast(charindex(',',@itemIDs) as int))
I gave 3,16 as the @itemID parameter values, but it didn't give the desired results.
Then I used the following SQL query (without charindex):
SELECT ItemID, Name, RelDate, Price, Status FROM item_k WHERE (ItemID = @itemIDs)
I gave 3 as the @itemID parameter value, and I got a result for it. I also gave 16 (on a separate occasion) as the @itemID parameter value, and I got a result for it. Concludes that there are values for ItemID 3 & 16.
Why doesn't SQL query with charindex give me any result?
I can't seem to figure out the issue here, please help.
Thanks.