SQL Server 2000 Question?

/*
This piece of code use xp_smtp_sendmail untility.
It suppose to lookup email addresses in the email table, send the email to the people still havn't send their timecard yet. However It only send the email to the last person in the table. I wonder where it is wrong?
大俠們,快出手啊*/



Use IT

declare
@TO NVARCHAR(4000),
@rc INT


Declare MyCursor Cursor For

Select email_addr+',' From email Where Stat = 'O'

Open MyCursor

Fetch Next From MyCursor Into @TO

While @@Fetch_Status = 0

BEGIN

Print @To

Fetch Next From MyCursor Into @To



exec @rc = master.dbo.xp_smtp_sendmail
@FROM = N'timecard_admin@aed.org',
@to = @TO,
@FROM_NAME = N'Timecard_Admin',
@priority = N'NORMAL',
@subject = N'This is just a testing email.',
@message = N'Your timesheet is overdue, please send it ASAP.',
@type = N'text/plain',
@server = N'mail.aed.org'
select RC = @rc
End

Close MyCursor

Deallocate MyCursor

所有跟帖: 

打PP - 先 exec, 最後再 Fetch Next -royyor- 給 royyor 發送悄悄話 (0 bytes) () 02/22/2006 postreply 14:31:01

請您先登陸,再發跟帖!