BUILD Dynamic SQL STING

  • I need to create a SQLSTRING that builds while it cycles through a cursor.

    I have this

    @SQLSTRING = + Colums1 +','

     

    I need it to give me something like this

    @SQLSTRING = Column1, Column1, Column1... Until I cycle through the cursor.

     

    Thanks

    _WM

  • You don't need a cursor:

    declare @SQLString varchar(max)

    select @SQLString = isnull(@SQLString,'') + Column1 + ',' from myTable

    set @SQLString = substring(@SQLString, 1, len(@SQLString) - 1)

    select @SQLString

     

  • thanks

    -WM

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

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