Results 1 to 3 of 3
  1. #1
    Join Date
    May 2003
    Location
    Southern California
    Posts
    2

    Unhappy Unanswered: Getting a variable to display result in querry analyzer

    Hello - I am trying to get a variable to display the result in querry analyzer. Its a simple stored procedure If I run the simple select statement I get the single result, if I use the select with the varaible I get just the completed querry without a result.

    --Here is the basic statement;
    select DSC from APDTEST where APDTESTID =0050 return

    --Here is the result
    /*-----------------------------
    select DSC from APDTEST where APDTESTID =0050 return
    -----------------------------*/
    DSC
    --------------------------------------------------
    Test

    (1 row(s) affected)
    -----------------------------*/

    --Here it is again with a variable;
    declare @o_Output as char(500)

    select @o_Output=DSC from APDTEST where APDTESTID =0050 return

    --Here ais the result
    /*-----------------------------
    declare @o_Output as char(500)

    select @o_Output=DSC from APDTEST where APDTESTID =0050 return
    -----------------------------*/


    Basically I want to see if the value of the '@o_Output' variable will display the same result via the select as the basic select in Querry Analyzer.

    cheers,

    andrew

  2. #2
    Join Date
    Jan 2003
    Location
    Leamington Spa, UK
    Posts
    17
    This line:

    select @o_Output=DSC from APDTEST where APDTESTID =0050 return

    simply, assigns the value to the variable. To see it in QA, either select it out or print it, eg.

    SELECT @o_Output

    or

    PRINT @o_Output

    If this query only ever returns 1 row (ie. APDTESTID is the primary key), you may consider using an OUTPUT parameter instead. Take a look in BOL (Books Online) for more info.

    macka.

  3. #3
    Join Date
    May 2003
    Location
    Southern California
    Posts
    2

    Re: Getting a variable to display result in querry analyzer

    Thank you so much. I did try the print before but realized now that if I had the return at the end of the select it did not work. I removed the return and it gave me the result.

    Again - thanks.


    Originally posted by andrewdorian
    Hello - I am trying to get a variable to display the result in querry analyzer. Its a simple stored procedure If I run the simple select statement I get the single result, if I use the select with the varaible I get just the completed querry without a result.

    --Here is the basic statement;
    select DSC from APDTEST where APDTESTID =0050 return

    --Here is the result
    /*-----------------------------
    select DSC from APDTEST where APDTESTID =0050 return
    -----------------------------*/
    DSC
    --------------------------------------------------
    Test

    (1 row(s) affected)
    -----------------------------*/

    --Here it is again with a variable;
    declare @o_Output as char(500)

    select @o_Output=DSC from APDTEST where APDTESTID =0050 return

    --Here ais the result
    /*-----------------------------
    declare @o_Output as char(500)

    select @o_Output=DSC from APDTEST where APDTESTID =0050 return
    -----------------------------*/


    Basically I want to see if the value of the '@o_Output' variable will display the same result via the select as the basic select in Querry Analyzer.

    cheers,

    andrew

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •