setting multiple variables in one line

  • I am migrating from Sybase and am trying to replicate the functionality of the following in one line without using multiple select @variable = ... statements or opening a cursor

    Select Col1, Col2, Col3 ... From Table into @var1, @var2, @var3 ...

    Any help would be appreciated.

  • Select @var1 =Col1, @var2 =Col2, @var3 = Col3

    From mytable

    Where ....

    For the Cursor:

    declare MyCURSOR cursor

    for Select Col1, Col2, Col3

    from mytable

    open MyCursor

    set nocount on

    fetch next from MyCursor into

    @var1, @var2, @var3

    while @@fetch_status = 0

    begin

    Do Somthing

    fetch next from MyCursor into

    @var1, @var2, @var3

    end

    close MyCursor

    deallocate MyCursor

    Good Luck!

    Edited by - EPol29 on 04/12/2002 07:45:04 AM

  • Thank you very much

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

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