How Do I....

  • How do I return multiple columns from a single row Select to be used in variables within some TSQL script?

    What I need to accomplish is the equivalent of:

    DECLARE @Var1 money, @Var2 money

    SELECT Column1, Column2 FROM Table WHERE ID=1

    SET @Var1=Column1

    SET @Var2=Column2

    Of course, the two SET statements fail with unknown column names.

    While SET @Var1=(SELECT Column1 FROM Table WHERE ID=1)

    I haven not been able to find a method for doing this for multiple columns within a single SELECT or UDF.

    Currently, I'm using an sProc with several OUTPUT params that in turn uses a cursor to FETCH the column values and return them. This doesn't seem efficient and I cannot help but think there is a better/easier way.

    Any suggestions would be appreciated.

  • quote:


    How do I return multiple columns from a single row Select to be used in variables within some TSQL script?

    would be appreciated.


    Try:

    SELECT @Var1 = Column1, @Var2 = Column2 FROM Table WHERE ID=1

  • Thanks - thought for sure I tried those variations - obviously not.

    So much for long weekends of banging on TSQL - I need to stick to .Net...

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

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