Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2003
    Posts
    11

    Unanswered: one line of results

    I am trying to do a select statement where the results show up in one line like a,b,c,d,e...

    I think I'm on the right track with the following code, but I have no idea what direction to go in. (I think my notes are not totally correct, but heck they're my notes. :-))

    @UM is getting wiped out after each into @UM, how do I make it add to @UM

    declare @UM varchar(3000) --declares variable
    DECLARE abc CURSOR FOR --declares object for recordset
    SELECT CONDCD FROM IBACOSTOCK GROUP BY CONDCD ORDER BY CONDCD
    OPEN abc --stores results in recordset variable
    FETCH NEXT FROM abc --grabs one line from recordset
    INTO @UM --stores line into variable
    SELECT CONDCD FROM IBACOSTOCK GROUP BY CONDCD ORDER BY CONDCD
    WHILE (@@FETCH_STATUS = 0) --as long as there are records in the recordset
    begin
    FETCH NEXT FROM abc --grabs next line from recordset
    INTO @UM --stores new line into variable
    end
    SELECT @um
    CLOSE abc --go back to while statement
    DEALLOCATE abc --erase recordset
    GO

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    How about...

    DECLARE @UM

    SET @UM = ''

    SELECT @UM = @UM + CONDCD
    FROM IBACOSTOCK
    GROUP BY CONDCD ORDER BY CONDCD
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Feb 2003
    Posts
    11
    Yeah. I'm slow. I looked at my code afterwards and summed it up, and that's what I got. Thanks!

Posting Permissions

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