Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to implement IIF (immediate IF) in the Select List
Message
From
23/03/2005 08:30:09
 
 
To
23/02/2005 05:51:10
Raoshan Kumar
Softinfo Systems Pvt. Ltd.
New Delhi, India
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00989543
Message ID:
00998375
Views:
25
Hello Mr:

There's no way to do this in SQL SERVER, because don't exist a Function like IIF o DECODE(Oracle) to emulate this, but you can do this:

Use subquery inside the principal query. How?

This your Code:
SELECT ItemCode, SUM(IIF(XnType='PUR', XnQty, 0) AS Purchase, ;
SUM(IIF(XnType='SLS', XnQty, 0) AS Sale ;
FROM rf GROUP BY ItemCode


SELECT a.itemcode,

(SELECT ISNULL(SUM(xnQty),0) FROM rf WHERE XnType = 'PUR' and rf.itemcode = a.itemcode) As Purchase,

(SELECT ISNULL(SUM(xnQty),0) FROM rf WHERE XnType = 'SLS' and rf.itemcode = a.itemcode) As Sale,

FROM rf a
GROUP BY itemCode

Bye.
Previous
Reply
Map
View

Click here to load this message in the networking platform