• pooja.sharma 54426 (1/15/2014)


    declare @cols NVARCHAR(MAX)

    select @cols = STUFF((SELECT distinct ',' + QUOTENAME(c.propName)

    FROM PropertyDef c where objecttypeid = 3

    FOR XML PATH(''), TYPE

    ).value('.', 'NVARCHAR(MAX)')

    ,1,1,'')

    So you're saying that you're trying to pass @cols into the second function as a comma delimited list?

    I'm thinking you don't need 2 functions at all. Can you provide DDL and some consumable sample data for your PropertyDef table?

    With that I (or someone else if I'm not around) would surely be able to provide you some tested code.

    You should also show us exactly how the final output list should look.

    Note: You're thinking row by agonizing row (RBAR) here. You need to shift your thinking to set-based to get to a proper solution.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St