子查询在sql server中返回多个值 [英] subquery returning multiple values in sql server
本文介绍了子查询在sql server中返回多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在sql server中返回多个值的子查询是查询结果,当我在()claues
中使用时。
我的实际要求是
我将一个varchar(100)传递给一个存储过程,其中一组数字用逗号分隔
示例'110,112,125'
并使用了一个函数:
SELECT * 来自 Tbl_Order 其中 orderid ( 选择 dbo.split( @ param )
但当 @paramis
为空时则没有记录。所以需要将其更改为(orderid)中的位置。我写道:
SELECT * 来自 Tbl_Order 其中 orderid in ( case @ param ' ' 然后 orderid else (选择 dbo.split( @ param ))
但是得到子查询错误。
传递参数为空时更好的解决方案是什么
解决方案
看看这里:在SQL IN子句中使用逗号分隔值参数字符串 [ ^ ]
尝试:
SELECT * 来自 Tbl_Order 其中 orderid
(< span class =code-keyword> case 何时 @ param = ' ' 然后 orderid
else (选择 dbo.Spl它( @ param )
) end )
假设您的存储过程接受 ONE varchar(100)类型的参数...
现在你是将参数传递给函数.....并将函数输出到过程...所以如果你的函数返回多个值,那么将遇到Error子查询返回多个值...你的存储过程接受一个参数,但是你传递了多个参数..如果你可以发布函数和存储过程....我们可以帮助..
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:
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:
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
解决方案
Have a look here: Using comma separated value parameter strings in SQL IN clauses[^]
Try:
SELECT * from Tbl_Order where orderid in (case when @param='' then orderid else (select dbo.Split(@param) )end)
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..
这篇关于子查询在sql server中返回多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文