Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 30, 2012 05:16 AM by MohanadHaddadin
Sep 05, 2008 01:26 PM|LINK
I was wondering if it was possible to pass a dynamic parameter to the the SQL 'IN' operator in a query that is created in the .xsd (data) layer.
The hardcoded version works like it should:
SELECT * FROM t_items WHERE id_item IN (1,2,4)
The problem is that I need this to be dynamic, thus the 1,2,4 part could be different each time, so 1,3,5,6,7 is possible too, as is an empty parameter.
I realised I'd need to be able to create extra parameters, or find another way to have the data returned as one block, if at all that is possible.
I have the ID's in a Set class (created by Seth Peck), to filter out duplicates, can I use this data to create parameters on-the-fly?
Passing parameters C#
Sep 08, 2008 09:29 AM|LINK
As far as I know, it can't be achieved. The text will not be parsed.
The solution to achieve that is to create a stored procedure which can parse the text. For your question, you can pass the collection as a string value into stored procedure. Please take a try.
Dec 30, 2012 05:16 AM|LINK
I know this is a very late reply but I hope this will work if you want to parametarize it. you can use 'COALESCE' as the following:
declare @IN_IDs nvarchar(max)
SELECT @IN_IDs =
* from t_items WHERE ( @IN_IDs)