Jump to content
Sign in to follow this  
kris1988edwards

ELSE IF Statement

Recommended Posts

Good morning,

 

I am trying to return specific values depending on the value of the WJCStatusID, for example if WJCStatusID = < 4 but > 2 return "In production"

 

SQL QUERY: 

 

SELECT tblWJCItem.AddedDescription, 
    tblWJC.WJCPrefix + Convert(Varchar(10),tblWJC.WJCNo) AS OurRef, 
    tblWJCItem.MaterialName, tblStockFamily.StockFamily, 
    tblWJCItem.WeightToSend, 
    tblWJC.DateCreated,
    tblWJC.WJCStatusID
FROM tblWJC 
 INNER JOIN tblWJCItem ON tblWJC.WJCID = tblWJCItem.WJCID 
 INNER JOIN tblStockFamily ON tblWJCItem.ProductFamilyID = tblStockFamily.StockFamilyID
 

IF (tblWJC.WJCStatusID) < 2 THEN  'Pre Production'
   ELSE IF (tblWJC.WJCStatusID) < 4 THEN 'In Production'
   ELSE IF (tblWJC.WJCStatusID) > 4 THEN 'Ready To Ship'
    ELSE 'Awaiting Lab Results';

I am quite new to the world of mssql so I maybe doing something wrong which is quite simply to fix. Can any body help?

Edited by kris1988edwards

Share this post


Link to post
Share on other sites

Use a CASE statement in your select query.

 

SELECT
   CASE 
      WHEN tblWJC.WJCStatusID < 2  THEN 'Pre Production'
      WHEN tblWJC.WJCStatusID < 2  THEN 'In Production'
      ...
Edited by kicken

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.