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
 General SQL Server Forums
 New to SQL Server Programming
 Sending a message via stored procedure

Author  Topic 

OwamAthi
Starting Member

4 Posts

Posted - 2009-10-11 : 10:27:06
good day people.

can you please assist me in sending a message via a stored procedure.
example:if a certain condition is reached then send a message to certain people.

code of condition.

declare @counter

set @counter=(select * from NumberofUsers where User_Count = 100)
if @counter= 100
begin
*** this is where i want to send the email to the system administrators.
end

Your assistance will be highly appreciated. Thanks

Bongs Zwane

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-10-11 : 12:01:36
Your select seems not to make any sense but I think it is only an example...
Which SQL Server version?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

OwamAthi
Starting Member

4 Posts

Posted - 2009-10-12 : 01:39:10
SQL server 2008

Bongs Zwane
Go to Top of Page

OwamAthi
Starting Member

4 Posts

Posted - 2009-10-13 : 01:24:35
oh i managed to create the stored proc. thanks for the input. the code is as follows:

create PROCEDURE spWriteStringToFile
(
@String Varchar(max), --8000 in SQL Server 2000
@Path VARCHAR(255),
@Filename VARCHAR(100)

--
)
AS
DECLARE @objFileSystem int
,@objTextStream int,
@objErrorObject int,
@strErrorMessage Varchar(1000),
@Command varchar(1000),
@hr int,
@fileAndPath varchar(80)

set nocount on

select @strErrorMessage='opening the File System Object'
EXECUTE @hr = sp_OACreate 'Scripting.FileSystemObject' , @objFileSystem OUT

Select @FileAndPath=@path+'\'+@filename
if @HR=0 Select @objErrorObject=@objFileSystem , @strErrorMessage='Creating file "'+@FileAndPath+'"'
if @HR=0 execute @hr = sp_OAMethod @objFileSystem , 'CreateTextFile'
, @objTextStream OUT, @FileAndPath,2,True

if @HR=0 Select @objErrorObject=@objTextStream,
@strErrorMessage='writing to the file "'+@FileAndPath+'"'
if @HR=0 execute @hr = sp_OAMethod @objTextStream, 'Write', Null, @String

if @HR=0 Select @objErrorObject=@objTextStream, @strErrorMessage='closing the file "'+@FileAndPath+'"'
if @HR=0 execute @hr = sp_OAMethod @objTextStream, 'Close'

if @hr<>0
begin
Declare
@Source varchar(255),
@Description Varchar(255),
@Helpfile Varchar(255),
@HelpID int

EXECUTE sp_OAGetErrorInfo @objErrorObject,
@source output,@Description output,@Helpfile output,@HelpID output
Select @strErrorMessage='Error whilst '
+coalesce(@strErrorMessage,'doing something')
+', '+coalesce(@Description,'')
raiserror (@strErrorMessage,16,1)
end
EXECUTE sp_OADestroy @objTextStream
EXECUTE sp_OADestroy @objTextStream

Bongs Zwane
Go to Top of Page
   

- Advertisement -