Click here to Skip to main content
15,911,711 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
subquery returning multiple values in sql server is query result when i used where in() claues.

My actual requirement is

I passed a varchar(100) to a stored procedure which have set of numbers separated by comma
Example '110,112,125' and used a function:
SQL
SELECT * from Tbl_Order where orderid in(select dbo.split(@param) 


But when @paramis is empty then getting no records. So need to change this to where in(orderid). And I wrote as:
SQL
SELECT * from Tbl_Order where orderid in(case @param when '' then orderid else (select dbo.split(@param)) 


But getting subquery error.
What is the better solution when passing argument is blank
Posted
Updated 15-Jul-13 0:30am
v2

 
Share this answer
 
Try:

SQL
SELECT * from Tbl_Order where orderid in
(case when @param='' then orderid
else (select dbo.Split(@param)
)end)
 
Share this answer
 
Comments
vipinsethumadhavan 15-Jul-13 7:04am    
dbo.Split result is more than one row so getting same error
changed else to select * from dbo.Split(@param)
Assuming that your Stored Procedure accepts ONE Parameter of type varchar(100)...
now you are passing the parameter to a function..... and the output of the function to the procedure... so if your function Returns more than one value then the Error "sub-query returning multiple values" Will be encountered... Because your stored Procedure accepts one parameter but you are passing more than one parameter..if you can post the function and stored-procedure.... we can help..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900