Assigning Multiple Variables

  • I want to assign multiple variables using a single  select statement. For example:

    DECLARE @var1 varchar(10)

    DECLARE @var2 varchar(10)

    SELECT col1, col2 into @var1, @var2 from table where....

    Can you do this sort of thing in 1 statement? What's the quickest way without resorting to loops, cursors, or temp tables?

     

    cheers

  • Select @var1=col1, @var2=col2 from table where....

    HTH

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 1 (of 1 total)

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