SQL Server 2000 Question?

來源: 2006-02-22 12:06:13 [舊帖] [給我悄悄話] 本文已被閱讀:

/*
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