Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 6th, 2006, 07:22 AM
Registered User
 
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Email to todays Birthday users

Hi

Im trying to set up a stored procedure which queries a table of users (userdetails)who have a birthday on the present day (field name 'dob') and then sends them a Happy birthday email.

My thinking is that I need to write a query to find the email adds of all users with a birthday on the present day.

so far I have this

SELECT email FROM userdetails WHERE DAY(userdetails.dob) = DATEPART(DAY,GETDATE()) and MONTH(userdetails.dob) = DATEPART(MONTH,GETDATE())

This returns the email add of users with birthdays today.

My question is how can I use the result of this query to populate my @to parameter

im using dbo.sp_send_cdosysmail to send the mail.

My other question is how can I get it to personlise the mailbody with the users name?

Any help would be great - I think im a long way off at the moment.

Thanks

Tim



 
Old September 6th, 2006, 07:35 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

First some links:

This KB article should point you in the right direction with using the CDONTS stored procedure:

http://support.microsoft.com/default.aspx/kb/312839

You may also want to look into:

http://www.sqldev.net/xp/xpsmtp.htm

which is a much better alternative then CDONTS.

Now to answer your question about getting the email address into the 'To' field. Since you will, no doubt, have multiple birthdays on the same day, I would suggest selecting all of the days birthdays into a Temp table and then :shudder: use a cursor to loop through that table populating the to field with the current email address.

Your second question about personaliazation, inside the Cursor create 2 variables, one that is the message body and one that is the name of the user and do something like this:

Set @messageBody = @messageBody + ' ' + @userName

That should add the users name to the message for you.

hth.

"The one language all programmers understand is profanity."
 
Old September 6th, 2006, 08:24 AM
Registered User
 
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks fpr ypur reply - I'll see how I get on with it!!

Thanks again

Tim






Similar Threads
Thread Thread Starter Forum Replies Last Post
Send Auto Mail for Birthday wishes bspradeep Classic ASP Professional 4 February 28th, 2007 06:13 AM
Pulling a Users Email from AD or Exchange Zeus_Man General .NET 0 September 14th, 2006 09:33 AM
Generate birthday wish Prabhakar_dt Classic ASP Basics 8 January 29th, 2005 02:09 AM
Default Value = Todays Date cej2583 SQL Server 2000 2 July 28th, 2003 10:55 PM
Selecting Data Based on Todays Date worshiploud Classic ASP Basics 2 June 29th, 2003 07:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.