“Subquery returned more than 1 value” error

喜欢而已 提交于 2021-02-17 06:04:31

问题


SELECT [schoolname] AS combinationschools, 
       CASE 
         WHEN [schoolname] LIKE '%/%' THEN (SELECT value 
                                            FROM 
         [dbo].[Split]('/', '#6/#9E/#9M')) 
       END          AS schoolname 
FROM   [dbo].[schools]; 

i'm getting q sql error like wise-

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.


回答1:


When you use a subquery like this, you can only have one record in the result set for each record. Clearly your table Split has more than one record.

Use a join instead of a subquery. Or make this a correlated subquery by joining it to the schools table in the subquery or pull only the Max or min record or make some sort of where clause in thw subquery to get only one record. Without seeing the table structures and data is is hard to determine exactly what to do.




回答2:


That's because Select value from [dbo].Split is returning more than one value.




回答3:


I think your split function will return a table which you cannot catch in single row in the given example split function will return following three row which is not possible to catch in single row

#6
#9E
#9M 

i think you should be missing to pass some variable in split function

Please pass somthing in Select value from [dbo].Split



来源:https://stackoverflow.com/questions/19406512/subquery-returned-more-than-1-value-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!