how to using distinct in XML SQL using stored procedure

有些话、适合烂在心里 提交于 2019-12-13 05:47:53

问题


SELECT DISTINCT
    CD.CASE_NO AS CaseNumber , 
    CE.PROCEEDING_ID AS ProceedingId, 
    PR.AC_STATE_CD AS ForeclosureStatecode, 
    0 AS STATUS, 
    GETDATE() AS CreatedDate, 
    1 AS CreatedBy, 
    GETDATE() AS ModifiedDate, 
    1 AS ModifiedBy,
            (
            select * from TBL_PROPERTY FOR XML PATH('T')
            )
            from TBL_CASE_DETAIL CD WITH(NOLOCK)
                    INNER JOIN TBL_AUCTION_DETAIL AD WITH(NOLOCK) ON AD.CASE_DETAIL_ID = CD.CASE_DETAIL_ID
                    LEFT JOIN TBL_AUCTION_PROPERTY_MAPPING TAPM WITH(NOLOCK) ON TAPM.AUCTION_ID = AD.AUCTION_ID
                    LEFT JOIN TBL_PROPERTY PR WITH(NOLOCK) ON PR.PROPERTY_ID = TAPM.PROPERTY_ID
                    LEFT JOIN TBL_AUCTION_PROCEEDING_MAPPING APM WITH(NOLOCK) ON APM.AUCTION_ID = AD.AUCTION_ID

    FOR XML PATH('Foreclosure')

Hi Guys, This is my modified code to get a distinct result. but now property part cannot display properly..

This is the result I get it. suppose open another tab for property lets say have 3 property.. so in 1 tab of foreclosure,inside foreclosure have 3 property data, then close foreclose tab..
https://gyazo.com/8a54690c88df3e9bb0dd7ff916c6f86c Thank You.


回答1:


If I get this right, the only thing you have to add is ,TYPE. Otherwise your inner SELECT ... FOR XML PATH() is filled i as text with all forbidden characters escaped...

Try:

(
    select * from TBL_PROPERTY FOR XML PATH('T'),TYPE
)


来源:https://stackoverflow.com/questions/38761090/how-to-using-distinct-in-xml-sql-using-stored-procedure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!