Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How To Next CASE Statements
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01434983
Message ID:
01434986
Views:
46
>I'm trying to covert this MS Access query to SQL:
>
>
>SELECT  MOS_OLPHKEY
>              MOS_OLREFNO
>             Sum(IIf(MOS_STATUS=4,0,IIf(MOS_STATUS=3,IIf(MOS_QTY_REC>MOS_QTY,MOS_QTY,MOS_QTY_REC),MOS_QTY))) AS [Booked Qty]
>FROM MOS
>GROUP BY MOS_OLPHKEY, MOS_OLREFNO
>
>
>Here's what I have, but I don't it's not right. I could use some help with the syntax:
>
>
>
>SELECT  MOS_OLPHKEY
>              MOS_OLREFNO, 
>              CASE MOS_STATUS 
>                  WHEN 4 THEN 0
>                  WHEN 3 THEN 
>                     CASE WHEN MOS_QTY_REC > MOS_QTY THEN
>                           MOS_QTY
>                     ELSE
>                           MOS_QTY_REC
>                     END
>                   ELSE
>                          MOS_QTY
>                   END as AS [Booked Qty]
>	FROM MOS
>	GROUP BY MOS_OLPHKEY, MOS_OLREFNO
>
IMHO you translated the code correctly, just probably need to add the name of the field as I did.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform