Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing Null value in query

Status
Not open for further replies.

ItHurtsWhenIThink

Technical User
Sep 1, 2007
60
US
I need to repalce a null date with a date plus 10 days.

Here is what I thought would work.

sql="SELECT App.PMDate, App.Title, App.Event, App.PMEndDate, App.PMRecur,"
sql=sql & " Uni.FDID,App.UnitID, Uni.VehicleID"
sql=sql & " FROM AppPM App,"
sql=sql & " Units Uni"
sql=sql & " WHERE App.UnitID=Uni.UnitID"
sql=sql & " AND App.DeptID =" & Request.Cookies("DeptID")
sql=sql & " AND isnull(App.PMEndDate," & DateAdd("d",10,Date) & ") AS EndDate > '" & Date & "'"

Clean Version:

SELECT
App.PMDate, App.Title, App.Event, App.PMEndDate, App.PMRecur,Uni.FDID,App.UnitID, Uni.VehicleID"

FROM AppPM App,Units Uni

WHERE App.UnitID=Uni.UnitID"
AND App.DeptID =" & Request.Cookies("DeptID")
AND isnull(App.PMEndDate,DateAdd("d",10,Date)) AS EndDate > Date()

It bombing at the isNull

Thanks
 
Code:
SELECT App.PMDate
     , App.Title
     , App.Event
     , App.PMEndDate
     , App.PMRecur
     , Uni.FDID
     , App.UnitID
     , Uni.VehicleID
  FROM AppPM AS App
INNER
  JOIN Units AS Uni
    ON Uni.UnitID = App.UnitID
 WHERE App.DeptID = " & Request.Cookies("DeptID")
   AND COALESCE(App.PMEndDate,DATEADD("d",10,GETDATE())) > GETDATE()

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top