Click here to Skip to main content
16,022,667 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i wrote this sub query but it give me this message:Msg 512, Level 16, State 1, Line 1 Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

What I have tried:

( select (d.ProductID) from v_accounts c,t_DormantAccounts d where (c.ProductID like ('sav9%') or c.ProductID like ('cur9%'))
and c.AccountID=d.AccountID and c.OurBranchID=d.OurBranchID ) as OriginalBranchID,
Posted
Updated 11-Sep-18 23:12pm
Comments
Member 13978939 12-Sep-18 6:09am    
Can you please provide your sample data with expected output data

Look at your query:
SQL
SELECT (d.ProductID) FROM v_accounts c, t_DormantAccounts d
   WHERE (c.ProductID LIKE ('sav9%') 
          OR c.ProductID LIKE ('cur9%'))
     AND c.AccountID=d.AccountID 
     AND c.OurBranchID=d.OurBranchID
Run that in isolation (SSMS is good for that) and it will return more than one row.
SQL can't work with more than one result where you are using that as a subquery - so you need to either alter that to return a single value:
SQL
SELECT TOP 1 (d.ProductID) FROM ...
   ORDER BY ...
Or work out a query that will only ever return a single value.

The only other alternative is to look at the whole query that is a part of and work out what you are trying to achieve better, possibly using JOIN.

But we can't do any of that for you: we don't have any access to your DB, the "outer query", or any idea what you are expecting to get as results.
 
Share this answer
 
(select top 1 (d.ProductID) from v_accounts c,t_DormantAccounts d where (c.ProductID like ('sav9%') or c.ProductID like ('cur9%'))
and c.AccountID=d.AccountID and c.OurBranchID=d.OurBranchID ) as OriginalBranchID
 
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