Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Database Mail Query

Author  Topic 

daipayan
Posting Yak Master

181 Posts

Posted - 2012-03-26 : 01:50:16
Dear All,

I need help from you. I am having a VIEW named as todayBday where it'll show Present day B'day List of Employees in following format:
-------------------------------------------------------
Name | Email | DOB
-------------------------------------------------------
John Carter | john@gmail.com | 3/26/1985 12:00:00 AM
Mia Suzki | mia@hotmail.com | 3/26/1978 12:00:00 AM
-------------------------------------------------------

Now my query is how to send the Birthday Wish to the Following Employees using MS SQL Database Mail.

For you information, I had already created Email Profile & tested the mail sending configuration, it's working. But don't know how connect the same with the VIEW and send mail using Column data.

Hope I can make you understand my query, please help.

Regards,
Daipayan
Software Programmer


Application has reported a 'Not My Fault' in module KRNL.EXE in line 0200:103F

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2012-03-26 : 02:25:49
Pseudo code:

DECLARE CURSOR cur FOR SELECT ... FROM todayBday
open cur
FETCH NEXT FROM cur INTO ..., @Email

while (@@fetch_status = 0)
begin
EXEC msdb.dbo.sp_senddbmail ..., @Email

FETCH NEXT FROM cur INTO ..., @Email
end
close cur
deallocate cur


- Lumbago
My blog-> http://thefirstsql.com/2011/07/08/how-to-find-gaps-in-identity-columns-at-the-speed-of-light/
Go to Top of Page

daipayan
Posting Yak Master

181 Posts

Posted - 2012-03-26 : 02:47:12
Dear Lumbago,

I did this T-SQL:

DECLARE @p_body as nvarchar(max), @p_subject as nvarchar(max)
DECLARE @p_recipients as nvarchar(max), @p_profile_name as nvarchar(max)
DECLARE @xml NVARCHAR(MAX)

SET @p_profile_name = N'Birthday Wish Admin'
SET @p_recipients = (SELECT Stuff((SELECT N'; ' + [email] FROM [dbo].[todayBday] FOR XML PATH(''),TYPE).value('text()[1]','nvarchar(max)'),1,2,N''))
SET @p_subject = N'Wish You a Very Happy & Prosperous Birthday'
SET @p_body = '<p style="text-align: center;"><span style="color:#ff0000;"><strong><span style="font-size: 22px;">Wish YOU a very Happy & Prosperous Birthday</span></strong></span>

<span style="font-size:20px;">May the sun#39;s rays shine brightest on you today with the wind at your heals.</span>

<span style="font-size:20px;">Happy Birthday.</span>'

EXEC msdb.dbo.sp_send_dbmail
@profile_name = @p_profile_name,
@recipients = 'admin@xyz.com',
@blind_copy_recipients = @p_recipients,
@body = @p_body,
@body_format = 'HTML',
@subject = @p_subject


I paste the following T-SQL in JOB.

quote:
Originally posted by Lumbago

Pseudo code:

DECLARE CURSOR cur FOR SELECT ... FROM todayBday
open cur
FETCH NEXT FROM cur INTO ..., @Email

while (@@fetch_status = 0)
begin
EXEC msdb.dbo.sp_senddbmail ..., @Email

FETCH NEXT FROM cur INTO ..., @Email
end
close cur
deallocate cur


- Lumbago
My blog-> http://thefirstsql.com/2011/07/08/how-to-find-gaps-in-identity-columns-at-the-speed-of-light/



Regards,
Daipayan
Software Programmer


Application has reported a 'Not My Fault' in module KRNL.EXE in line 0200:103F
Go to Top of Page
   

- Advertisement -