Home Forums Programming General string of characters in separate Rows RE: string of characters in separate Rows

  • Thanks, it was very close and useful. I ended up with this :

    WITH DtlIdxcolumn (tblnm,type_desc,object_id,index_id,column_id,name)

    AS

    -- Define the CTE query.

    (

    select main.name as tblnm,main.type_desc,Sec.*

    from

    (

    select Obj.name,obj.object_id,Idx.index_id,Idx.type_desc

    from sys.indexes as Idx

    inner join

    sys.objects as Obj

    on Idx.object_id=Obj.Object_id

    ) as Main

    inner join

    (

    select idxcol.object_id,idxcol.index_id,col.column_id,col.name

    from sys.index_columns as Idxcol

    inner join

    Sys.columns as col

    on Idxcol.object_id=col.object_id and Idxcol.column_id=col.column_id

    ) as Sec

    on (Main.object_id=Sec.object_id) and (main.index_id=Sec.index_id)

    )

    Select F1.*,F2.object_id,F2.tblnm ,(case when (F2.Retievdcolumnnm) IS null then 'NOTEXISTS' else 'EXISTS' end)comments

    From

    (

    SELECT A.*,B.object_id,B.name

    FROM [PRGX_AS_DEV_SandBox_REFERENCE_TABLES].[dbo].[RequiredObjects] as A

    inner join

    [PRGX_AS_CC_SandBox_Pricing_2014].[sys].[objects] as B

    on A.IndexTable=B.name

    where ObjectType='index'

    )as F1

    Left join

    (

    Select distinct ST2.object_id,ST2.tblnm,

    substring(

    (

    Select ', '+ convert(varchar(500),rtrim(ltrim(name))) AS [text()]

    From DtlIdxcolumn as ST1

    Where (ST1.object_id = ST2.object_id) and (st1.index_id=st2.index_id)

    ORDER BY ST1.name

    For XML PATH ('')), 2, 1000

    ) [Retievdcolumnnm]

    From DtlIdxcolumn ST2

    )as F2

    on (F1.object_id=F2.object_id) and (rtrim(ltrim(upper(F1.IndexColumn)))=rtrim(ltrim((F2.Retievdcolumnnm))))