Solved

SQL Server 2005 Script

Posted on 2007-03-27
2
210 Views
Last Modified: 2010-03-19
How would you write a SQL Script to check a record for a field called DateStamptxt of type smalldatetime and test --if it is equal to current day or previous day. Then return success/failor to say message should send or not to Database Mail?

Thanks JK

                                                     
0
Comment
Question by:fsuedu
2 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 18800271
IF EXISTS (SELECT 1 FROM urTable WHERE DateStampTxt > = CAST(CONVERT(varchar,GETDATE() -2, 112) AS DATETIME) )
 Exec master..xp_SendMail ''
Else
0
 
LVL 11

Expert Comment

by:Ved Prakash Agrawal
ID: 18800361

Hi refer to the link to configure the database mail
http://www.databasejournal.com/features/mssql/article.php/3626056



IF EXISTS (SELECT 1 FROM urTable WHERE DateStampTxt > = CAST(CONVERT(varchar,GETDATE() -2, 112) AS DATETIME) )
BEGIN
declare @body1 varchar(100)
set @body1 = 'Server :'+@@servername+ ' My First Database Email '
EXEC msdb.dbo.sp_send_dbmail @recipients=test@yahoo.com',
    @subject = 'My Mail Test',
    @body = @body1,
    @body_format = 'HTML' ;
END
ELSE
BEGIN
----whatever you want vam do here
END


0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now