![]() |
| |||||||
![]() | « Previous Thread | Next Thread » |
| | LinkBack (1) | Thread Tools | Display Modes |
| |||
| Yeah, I tried it without the conversion, (see below) and I get no error's, but the email does go NOW. I changed the dates in the 3 records to match today's date and it should have sent the email like it did before. But of course I now selecting the email address and date now. But I"m going to put the conversion part back in and try it again. I'm looking on line to see if there is something about that datetime conversion error. Any other ideas let me know. Code: USE [peebman]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_proc_happyBirthday2]
AS
SET NOCOUNT ON
declare @birth datetime, @email varchar(150)
declare row cursor for
select email, birth from email where birth = getdate()
open row
fetch row into @birth, @email
while @@fetch_status = 0
begin
fetch row into @birth, @email
IF @birth = getdate()
Begin
declare @body1 varchar(100)
set @body1 = 'You are reminded to finish your PDQ!'---'Server EXEC msdb.dbo.sp_send_dbmail
@recipients = @email,
@subject = 'My Mail Test',
@body = @body1,
@body_format = 'html';
end
else if @birth <> getdate()
BEGIN
EXEC msdb.dbo.sysmail_stop_sp
End
end
close row
Deallocate row
return
|
| Sponsored Links |
| |||
| Okay Jmurrayhead, I finally got everything to work. I appreciate the links you sent me they help as well, but it works now. I can schedule for reminder emails to be sent out using sql 2005 job scheduler. Here is my final stored procedure: Code: USE [peebman]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_proc_happyBirthday2]
AS
SET NOCOUNT ON
exec msdb.dbo.sysmail_start_sp
declare @birth varchar(15),
@email varchar(8000)
set @email =''
declare row cursor for
select email, birth from email where birth = CONVERT(varchar(15), GETDATE(), 101)
-- = convert(varchar(8), getdate(), 112)
open row
fetch row into @email, @birth
while @@fetch_status = 0
begin
fetch row into @email, @birth
IF @birth = CONVERT(varchar(15), GETDATE(), 101)
Begin
declare @body1 varchar(100)
set @body1 = 'You are reminded to finish your PDQ!'---'Server
EXEC msdb.dbo.sp_send_dbmail
@recipients = @email, --@BCC = @BCCList,
@subject = 'My Mail Test',
@body = @body1,
@body_format = 'html';
end
else if @birth <> CONVERT(varchar(15), GETDATE(), 101)
BEGIN
EXEC msdb.dbo.sysmail_stop_sp
End
end
close row
Deallocate row
return
And I converted getdate to a varchar to match the birth(datecolumn) in the table. That worked as well as the msdb.dbo.sysmail_start_sp code to shoot the email. also before in the begin of loop I had: Code: fetch row into @birth, @email Code: fetch row into @email, @birth So thinks again for the help, sorry for all the postings. Hopfully this post will help other programmers out who want to sent reminder emails using SQL 2005 instead of using executables on the server. Thanks again ![]() |
| ||||
| Glad you were able to figure out the rest. Don't worry about all the postings, that's what this place is for ![]()
__________________ jmurrayhead Did I help you out? Make me popular by clicking the icon!If you found a post helpful, please click the button in the lower right-hand corner of the post.Powered by ASP.Net |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dynamic Stored Procedure | jmurrayhead | Microsoft SQL Server | 16 | March 26th, 2008 11:19 AM |
| Permissions on Tables, Stored Procedures, etc. | theChris | Microsoft SQL Server | 2 | March 24th, 2008 11:49 AM |
LinkBacks (?)
LinkBack to this Thread: http://www.developerbarn.com/sql-development/206-if-statement-stored-procedure.html | ||||
| Posted By | For | Type | Date | |
| In need of advise - ASP Free | This thread | Refback | May 29th, 2008 07:40 AM | |
| Sponsored Links |
| ASP.NET Resource Index a directory of ASP.NET tutorials, applications, scripts, assemblies and articles for the novice to professional developer. Free Web Directory Including Chats and Forums Resources, Offer automatic, instant and free directory submissions. | URLZ Web Directory URLZ Web Directory Free Web Directory - Add Your Link The Little Web Directory | Free Web Directory Pegasus free web directory is a free directory organised by categories. Web Directory & SEO Services dirroot web directory |