Home All Groups Group Topic Archive Search About

A query within xp_sendmail

Author
8 Jul 2005 6:14 PM
qjlee
Hi, I need to specify a where conditio within a query under xp_sendmail.  The
statement is like this:
xp_sendmail
@recipients='myaddr***@mydomain.com',
@query='select * from mytable where clientcode_c='A''
and I got an error

Can you tell me where it is wrong?

Thanks,

Author
8 Jul 2005 6:37 PM
Kevin Bowker
I got my guidance for using this extended procedure from:
http://www.sqldev.net/xp/xpsmtp.htm

Looking back at that page, I don't see an '@query' parameter.

Show quote
"qjlee" wrote:

> Hi, I need to specify a where conditio within a query under xp_sendmail.  The
> statement is like this:
> xp_sendmail
> @recipients='myaddr***@mydomain.com',
> @query='select * from mytable where clientcode_c='A''
> and I got an error
>
> Can you tell me where it is wrong?
>
> Thanks,
Author
8 Jul 2005 6:45 PM
Aaron Bertrand [SQL Server MVP]
xp_sendmail (included in SQL Server) is not the same as xp_smtp_sendmail (an
add-on).





Show quote
"Kevin Bowker" <KevinBow***@discussions.microsoft.com> wrote in message
news:12693670-1564-4798-888D-5605F0206A15@microsoft.com...
>I got my guidance for using this extended procedure from:
> http://www.sqldev.net/xp/xpsmtp.htm
>
> Looking back at that page, I don't see an '@query' parameter.
>
> "qjlee" wrote:
>
>> Hi, I need to specify a where conditio within a query under xp_sendmail.
>> The
>> statement is like this:
>> xp_sendmail
>> @recipients='myaddr***@mydomain.com',
>> @query='select * from mytable where clientcode_c='A''
>> and I got an error
>>
>> Can you tell me where it is wrong?
>>
>> Thanks,
Author
8 Jul 2005 6:47 PM
Alejandro Mesa
Try escaping the single quotation mark inside the string.

> @query='select * from mytable where clientcode_c='A''

@query='select * from mytable where clientcode_c=''A'''


AMB

Show quote
"qjlee" wrote:

> Hi, I need to specify a where conditio within a query under xp_sendmail.  The
> statement is like this:
> xp_sendmail
> @recipients='myaddr***@mydomain.com',
> @query='select * from mytable where clientcode_c='A''
> and I got an error
>
> Can you tell me where it is wrong?
>
> Thanks,
Author
8 Jul 2005 6:47 PM
Ben Amada
qjlee wrote:

> Hi, I need to specify a where conditio within a query under xp_sendmail.
> The statement is like this:
> xp_sendmail
> @recipients='myaddr***@mydomain.com',
> @query='select * from mytable where clientcode_c='A''
> and I got an error
>
> Can you tell me where it is wrong?
>
> Thanks,

It looks like you need to add more single-quotation marks in your query.
You need two single quotes before and after the letter A:

@query='select * from mytable where clientcode_c=''A'''

Ben
Author
8 Jul 2005 7:38 PM
Terri
If you are using xp_smtp_sendmail you can use xp_cmdshell and bcp to write
to a file and then use the @messagefile parameter to show the contents of
the file in the table. Be aware of the security implications of xp_cmdshell
before you use it.

INSERT INTO TABLE1
select * from mytable where clientcode_c='A'

EXEC master..xp_cmdshell "bcp DatabaseName.dbo.TABLE1out
\\SERVER1\Folder1\TextFile.txt -c -T"

exec @rc = master.dbo.xp_smtp_sendmail
@to...
@from..
@Mmessage...
@messagefile = N'\\SERVER1\Folder1\TextFile.txt'
....

@query would be a great addition to xp_smtp_sendmail I would even pay for
it.

Show quote
"Ben Amada" <b**@REpoMOweVErpick.com> wrote in message
news:u9KfB2%23gFHA.1444@TK2MSFTNGP10.phx.gbl...
> qjlee wrote:
>
> > Hi, I need to specify a where conditio within a query under xp_sendmail.
> > The statement is like this:
> > xp_sendmail
> > @recipients='myaddr***@mydomain.com',
> > @query='select * from mytable where clientcode_c='A''
> > and I got an error
> >
> > Can you tell me where it is wrong?
> >
> > Thanks,
>
> It looks like you need to add more single-quotation marks in your query.
> You need two single quotes before and after the letter A:
>
> @query='select * from mytable where clientcode_c=''A'''
>
> Ben
>
>
Author
8 Jul 2005 7:17 PM
Nery Gonzalez
"qjlee" <qj***@discussions.microsoft.com> escribió en el mensaje
news:60984BAA-F911-4AB1-B915-337A1E94699B@microsoft.com...
> Hi, I need to specify a where conditio within a query under xp_sendmail.
> The
> statement is like this:
> xp_sendmail
> @recipients='myaddr***@mydomain.com',
> @query='select * from mytable where clientcode_c='A''

    @query='select * from mytable where clientcode_c Like ' + 'A'

Show quote
> and I got an error
>
> Can you tell me where it is wrong?
>
> Thanks,
Author
8 Jul 2005 7:24 PM
qjlee
Thank you.

That two single quotation works.

Thank you very much for all  your response.



Show quote
"qjlee" wrote:

> Hi, I need to specify a where conditio within a query under xp_sendmail.  The
> statement is like this:
> xp_sendmail
> @recipients='myaddr***@mydomain.com',
> @query='select * from mytable where clientcode_c='A''
> and I got an error
>
> Can you tell me where it is wrong?
>
> Thanks,

AddThis Social Bookmark Button