SQL Server Error:"SQL Server Subquery returned more than 1 value" -


"subquery returned more 1 value. not permitted when subquery follows =, !=, <, <= , >, >= or when subquery used expression."

i got wired error message while debugging following code:

    when not exists(select  1                        defs with(nolock)                       defaultname = @default_currency                     , defaultvalue= @currency)     , not exists( select  1                        supp with(nolock)                       pint    = @id                     , currency= @currency)            "not valid."  

i couldn't find wrong code regarding error message. moreover, error message disappear when changed 'and' 'or'.

    when not exists(select  1                        defs with(nolock)                       defaultname = @default_currency                     , defaultvalue= @currency)     or not exists(  select  1                        supp with(nolock)                       pint    = @id                     , currency= @currency)             "not valid."  

i need use 'and' condition, how remove error?

(all @ variable in code snippet not table variable.)

thanks in advance.

the error tells 1 of subqueries, don't think these subqueries 1 give error. if use , 'exist' ( or 'not exist' ) can use top 1, because need check 1 row.

this means can use:

when not exists(select top 1 1                        defs with(nolock)                       defaultname = @default_currency                     , defaultvalue= @currency)     or not exists(  select top 1  1                        supp with(nolock)                       pint    = @id                     , currency= @currency) 

but not causing error. example code same , works fine:

declare @table1 table (     id int,     value nvarchar(100) )  declare @subquery table (     id int,     value nvarchar(100) )  insert @table1 values (1, 'one') insert @table1 values (2, 'two') insert @table1 values (3, 'three') insert @subquery values (1, 'also one') insert @subquery values (3, 'also three') insert @subquery values (5, 'also five')   select * @table1 sourcetable not exists (select 1 @subquery id = sourcetable.id)      , not exists (select 1 @subquery value = sourcetable.value) 

so think must in part of query.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -