Query Request

  • DECLARE @T TABLE

    (

    X CHAR(3)

    )

    INSERT INTO @T SELECT 'AAA'

    INSERT INTO @T SELECT 'BBB'

    INSERT INTO @T SELECT 'CCC'

    I need to return one row concatenation of entire rows in X field like 'AAA','BBB','CCC'

    Is there any way to archive this without using cursors.

    - Zahran -

  • HI There,

    TRy and look up the Use of CTE's, this should point you in the right direction.

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • TRy and look up the Use of CTE's, this should point you in the right direction.

    Can I use CTE in SQL Server 2000?

    - Zahran -

  • Sorry my bad.

    Forgot to see which version of SQL you using.

    CTE's are not allowed in 2000 🙁

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • Hey try this one.

    Declare @No varchar(100)

    Set @No =''

    select @No = @No + case when @No = '' then '' else ',' end + X

    from @T

    Select @No

    karthik

  • hi Zahran,

    please try this

    DECLARE @Concat as varchar(8000)

    SELECT @Concat = isnull(@Concat + ', ', '') + ltrim(rtrim(x))

    FROM @T

    -- result

    SELECT @Concat as Result

Viewing 6 posts - 1 through 5 (of 5 total)

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