Home Forums SQL Server 2005 T-SQL (SS2K5) Choosing the faster option; Stored Procedure or Function? RE: Choosing the faster option; Stored Procedure or Function?

  • Todd - assuming that we're dealing with SQL2005, you actually have a few options. One is the "xml trick" - which looks something like this:

    SELECT t1.SomeID,

    STUFF((SELECT ','+t2.SomeCode

    FROM dbo.TestData t2

    WHERE t1.SomeID = t2.SomeID

    FOR XML PATH('')),1,1,''

    )

    FROM dbo.TestData t1

    GROUP BY t1.SomeID

    (stolen as is right out of Jeff's article on concatenation)

    http://www.sqlservercentral.com/articles/Test+Data/61572/[/url]

    The second is - you can actually build a user-defined Aggregate in CLR, to do the concatenation. Books online sports the code for the concatenation aggregate right here:

    http://msdn.microsoft.com/en-us/library/ms131056.aspx

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?