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 2000 Forums
 SQL Server Development (2000)
 Passing recordset results.

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-09-07 : 09:55:54
Don writes "I could use some help in the form of an explanation.

I'm using jmail call from a stored procedure to send mail.
Everything is working fine except I can't figure out how to send query results.

Here's my code.
create Procedure dbo.sp_send_mail
@sender varchar(100),
@sendername varchar(100)='',
@serveraddress varchar(255)='popserver',
@recipient varchar(255),
@recipientBCC varchar(200)='',
@recipientCC varchar(200)='',
@attachment varchar(100) ='',
@subject varchar(255),
@mailbody text
-----------------------------------------------------
Running this in Query Analyzer

EXEC master.dbo.sp_send_mail
@recipient = 'lefiks@yahoo.com',
@subject = 'Reminder'
@mailbody = 'Here is where I want the results of a Query',
@sender = 'test@here.com'

The above code does work and would send -- Here is where I want the results of a Query -- as the message body.

I've tried using these:
@mailbody = 'select * from tec.dbo.contacts',
Results --> select * from tec.dbo.contacts
The query not the results were sent.

@mailbody = select * from tec.dbo.contacts,
Results -->Incorrect syntax near keyword select
Error in Query Analyzer

I tried using examples like this also:

DECLARE @body varchar(8000)
SELECT @body = select * from tec.dbo.contacts

and then @mailbody = @body,
but I get a syntax error on the select statement.

Any help would be appreciated including articles that I can read.
I've been unable to find any articles explaining how to accomplish this.

Thanking you in advance
Don Lefik
lefiks@yahoo.com"
   

- Advertisement -