Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Subquery Case Error

Author  Topic 

daipayan
Posting Yak Master

181 Posts

Posted - 2009-10-12 : 04:55:42
Hello,

I am facing an error in the following CASE T-SQL:
Select Right('00000' + Cast(indent.indent_ID As VarChar(5)), 5) As 'Sr. No.',
indent.financial_year,
indent.[from],
indent.[to],
indent.indent_date,
indent.menu,
indent.required_date,
indent_details.item_name,
indent_details.item_UOM,
indent_details.rate,
CASE
WHEN indent_details.qty_issued is NULL THEN (SELECT indent_details.qty_reqd FROM indent_details)
else indent_details.qty_issued
end 'Quantity',
CASE
WHEN indent_details.qty_issued is NULL THEN (SELECT (indent_details.qty_reqd*indent_details.rate) FROM indent_details)
else (indent_details.qty_issued*indent_details.rate)
end 'Rate'
From indent Inner Join
indent_details On indent.indent_ID = indent_details.IndentNumber


When am running the following T-SQL, am getting the following error:
(1 row(s) affected)

Server: 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.


Please Help!

Daipayan

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-10-12 : 05:51:54
Why are you doing a select in your case statement, especially as you are already joining to the table?!?

Select Right('00000' + Cast(indent.indent_ID As VarChar(5)), 5) As 'Sr. No.',
indent.financial_year,
indent.[from],
indent.[to],
indent.indent_date,
indent.menu,
indent.required_date,
indent_details.item_name,
indent_details.item_UOM,
indent_details.rate,
CASE
WHEN indent_details.qty_issued is NULL THEN indent_details.qty_reqd
else indent_details.qty_issued
end 'Quantity',
CASE
WHEN indent_details.qty_issued is NULL THEN (indent_details.qty_reqd*indent_details.rate)
else (indent_details.qty_issued*indent_details.rate)
end 'Rate'
From indent Inner Join
indent_details On indent.indent_ID = indent_details.IndentNumber
Go to Top of Page

daipayan
Posting Yak Master

181 Posts

Posted - 2009-10-12 : 06:23:55
Actually I was trying to do little experiment with d T-SQL, but failed

Daipayan
Go to Top of Page
   

- Advertisement -