Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL Server 2005 Script

Posted on 2007-03-27
2
Medium Priority
?
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

609 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