March 1, 2012 at 4:04 pm
Can we write a Sql Query in the Then Clause of CASE Statement as shown below:
DECLARE @Type INT
SET @Type=10
'Count'=
CASE
WHEN @Type=10 THEN SELECT COUNT(ItemId) FROM Item WHERE ....
WHEN @Type=20 THEN SELECT COUNT(ItemId FROM ItemSupport WHERE ....
END
Thanks!!!
March 1, 2012 at 4:16 pm
You very well can, as long as the statement you are using after the THEN clause does not return more than 1 value (1 column 1 row)
March 1, 2012 at 7:01 pm
Yes but you need to encapsulate the SELECT in parenthesis and, as ColdCoffee identified, it must return only 1 value.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 12, 2012 at 12:25 pm
Thanks guys for all the responses!!!
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply