Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

Set flag in DB if the date is 5 days in the past

$
0
0

I've written some code using SQL that checks today's date and compares is to an entry in the database, which I have called EndDate.  If the EndDate is within 60 days an email will be generated. If data in the database is 60 days or more in the future it returns the data from the query.

Here is the code:

Use LOGONs
Select DateAdd(d, DateDiff(d, 0, EndDate), 0) As KeyedDate, Service, Manufactureer, [AccountNumber], GETDATE() as TodayTime
From ServiceExpiryMAtrix
where DATEDIFF(d, GETDATE(), EndDate) < 60

I have created another column in the database called expired, that I'd like to update with either yes or no if the Enddate field is over 5 days old.  The idea behind this is to control whether emails are continued to be sent once the EndDate date has passed.

I have seen that this should be done in the select query but being new to SQL I thought I'd ask the question...

James


Alter De Ruine


Viewing all articles
Browse latest Browse all 8428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>