Re: query didnt work in xp_sendmail

  • Hi,

    I have a query 'select * from t_srf_rqst where no_id = (select MAX(no_id) from t_srf_rqst)', which works in Query Analyzer'.Hwever, when I use it with xp_sendmail like this:

     EXEC master..xp_sendmail @recipients = 'john123@yahoo.com',

         @query = 'select * from t_srf_rqst where no_id = (select MAX(no_id) from t_srf_rqst)',

         @subject = 'New SQL Installation Request'

    I got the following error message:

    ODBC error 208 (42S02) Invalid object name 't_srf_rqst'.

    ODBC error 208 (42S02) Invalid object name 't_srf_rqst'.

    Can someone tell me what's wrong?

    Thanks in advance.

    John

  • John,

     

    Have you tried the following:??

    SELECT * FROM databasename.owner.t_srf_rqst???

    The xp_sendmail runs from master and your table probably isn't in master.  I think that once you tell it where to look this should work for you.

     

    Good Luck,

    AJ



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • AJ,

    You are right!! I misseed a parameter @dbuse, which tells SQL the database that query is going to run again. Now I have another issue: the result is a mess. How do I format it the way I want?

    Thanks again for your help.

     

    P.S. Query Result:

    no_id fnm_nm

    lnm_nm

    bsunt_nm

    ph_cd

    cell_cd

    appl_nm

    srv_nm

    opsys_nm

    vrsn_nm

    coll_nm

    lic_nm

    dtd_dt

    insl_nm

    cmnt_tx

    ----------- --------------------------------------------------

    --------------------------------------------------

    --------------------------------------------------

    --------------------------------------------------

    --------------------------------------------------

    --------------------------------------------------

    --------------------------------------------------

    --------------------------------------------------

    --------------------------------------------------

    --------------------------------------------------

    --------------------------------------------------

    -----------------------

    --------------------------------------------------

    -----------------------------------------------------------------------

    -----------------------------------------------------------------------

    -----------------------------------------------------------------------

    -------------------------------------

    7 John

    Lee

    2019892354

    WWW

    Windows 2000 Enterprise

    SQL 2000 Enterprise

    Other

    Per Processor mode

    1900-01-01 00:00:00.000

    SG

    test-test

  • Try the @Width= 'your size here'  parameter.

  • I tried @width, however, the format of the query result was still not good.

     

  • I always use as an attachment instead of the body of the email.

    @attach_results = 'true'

  • That parameter makes lots sense. thanks again for your help!

    Have a nice day.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply