Solved

SQL Server 2005 Script

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
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…

706 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

16 Experts available now in Live!

Get 1:1 Help Now