Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I need to send a mail

StartDate - today =7

i.e., Before 7 days the mail should send the user from the start date

Help pl

Regards,
Praveen
Posted

Try:
SELECT * FROM myTable where DATEDIFF( dd, [date],GETDATE())=7
 
Share this answer
 
Comments
Reiss 28-Jul-11 3:33am    
Better solution than mine - completely forgot about DATEDIFF
Monjurul Habib 28-Jul-11 4:06am    
good call. 5
To give you an idea;
For getting the date use;

SQL
SELECT DATEADD(d,-7,GETDATE())


For sending email use;

SQL
CREATE PROCEDURE dbo.foo AS
BEGIN
    SET NOCOUNT ON
    -- do some other actions
    DECLARE @body VARCHAR(1024)
    SET @body = 'foo was fired '+
        CONVERT(VARCHAR, GETDATE())
    EXEC master..xp_smtp_sendmail
        @TO = 'you@you.com',
        @from = 'someone@somewhere.com',
        @message = @body,
        @subject = 'foo was fired.',
        @server = 'smtp.yourdomain.com'
END



For sending email options check this link[^].

For date functions have a look at here[^].

so this should give you an idea how you can do it.

Good luck.
 
Share this answer
 
Use the DATEADD [^] function

e.g.
SQL
WHERE DATEADD(d, -7, GETDATE()) >= StartDate
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900