Scamquist
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_RC V,101)as RECEIPT,
CONVERT(VARCHAR,pl.DATE_RQ ST,101) as REQUEST, DATEDIFF(DAY, pl.DATE_RQST,pl.DATE_RCV) AS DAY
Any help will be appreciated.
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_RC
CONVERT(VARCHAR,pl.DATE_RQ
Any help will be appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
Thank you for the assist and the explaination.
ASKER
CASE WHEN ISNULL( DATEDIFF(DAY, pl.DATE_RQST,pl.DATE_RCV),