General information
Forum:
Microsoft SQL Server
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
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only