Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2008
    Posts
    2

    Unanswered: query rsult to a variable

    how to assign a query result to a variable in sql server 2005

  2. #2
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    if there is only one row in the result, you do it like this:

    select @var1=col1, @var2=col1 from mytable where col3='asdf'

    if there is more than one row in the result, you can dump the result in a temp table or table variable:

    insert #temp
    select col1, col2 from mytable where col3='asdf'

Posting Permissions

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