How to choose returned column name in a SELECT FOR XML query?

后端 未结 6 796
时光取名叫无心
时光取名叫无心 2021-02-06 20:49

MS SQL has a convenient workaround for concatenating a column value from multiple rows into one value:

SELECT col1
 FROM table1
 WHERE col2 = \'x\'
 ORDER by col         


        
6条回答
  •  逝去的感伤
    2021-02-06 21:23

    stored procedure

    declare @requestResultXML xml
    
    set @requestResultXML =
                (
                    SELECT 'NPOIT-1.0' AS '@Interface',
                    (
                        select  'Query'     as '@Type',
                                'GetBill'   as '@Query',
                                'True'      as '@CompressResult'
                            FOR XML PATH('Head'), TYPE
                    ),
                    (
                        select  @pin        as '@PIN',
                                @period     as '@Period',
                                @number     as '@Number',
                                @barcode    as '@Barcode'
                            FOR XML PATH('QueryParams'), TYPE
                    )   as Data
    
                    FOR XML PATH('DataExchangeModule')              
                )
    
    select @requestResultXML as GetBillRequest
    

提交回复
热议问题