Solved

SQL Server 2005 Script

Posted on 2007-03-27
2
221 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

786 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