Link to home
Start Free TrialLog in
Avatar of Scamquist
ScamquistFlag for United States of America

asked on

If Statement in SQL Stored Procedure

I have the select statement below.

I am trying to create an if statement if the alias DAY is Null or > 0 then a new alias Late should = 1 otherwise it would be zero.  Everything I tried messes up the prior selections.

SELECT    distinct  ph.NAME_VND_ORDFM as Name_Vend,ph.ID_PO as PO_NBR,  pl.ID_REL_ORD AS PO_REL,pl.ID_LINE_PO AS PO_LN,  CONVERT(VARCHAR,pl.DATE_RCV,101)as RECEIPT,
                      CONVERT(VARCHAR,pl.DATE_RQST,101) as REQUEST, DATEDIFF(DAY, pl.DATE_RQST,pl.DATE_RCV) AS DAY

Any help will be appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Scamquist

ASKER

Your answer worked.  Can you explain the syntax, mainly the ,100)>0

CASE WHEN ISNULL( DATEDIFF(DAY, pl.DATE_RQST,pl.DATE_RCV), 100) > 0 THEN 1 ELSE 0 END IsLate
if the value returned is null, the isnull(xxx, 100) will return 100.
as you said that null value returned should also display 1 as result, I used 100 as value, 1 or 99999 would have worked the same way.
Thank you for the assist and the explaination.