0

I want to pass variable number parameters to sql query. As an example:

select column1  
from Table    
where column2 in ( '0080','0010')    
group by column1    
having count(distinct column2) >= 2

In the where clause, 2 arguments 0080 and 0010 are used. But this number of arguments can vary based on the input from user. As an example it could be like this:

select column1  
from Table    
where column2 in ( '0080','0010', '0020', '0050', '0060')    
group by column1    
having count(distinct column2) >= 5

So, this number of arguments is not fixed and it will be passed by the user from an .xml file.

How can we pass a variable number of arguments to the query? As the number of arguments is not fixed and it can be changed from time to time, can we use an array or something similar?

4
  • is this a stored procedure or dynamic? Commented Oct 22, 2012 at 19:41
  • 1
    You need to build the query in some other language; likely the same language with which you now read that .XML . Commented Oct 22, 2012 at 19:42
  • 1
    This has been asked a number of times. It's not possible without modifying the query. Commented Oct 22, 2012 at 19:43
  • Let's assume it as a stored one Commented Oct 22, 2012 at 19:45

1 Answer 1

1

I would suggest you try to load the arguments into a temporary table and use that in the where clause in a subquery. In particular if your argument list becomes very large, this is much more scalable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.