带有连接和拆分数据的TSQL查询

时间:2013-11-24 21:47:31

标签: sql sql-server tsql

我的存储过程设置如下:

BEGIN
SET NOCOUNT ON;
        BEGIN
            SELECT  A.[campaignID],
                    A.[campaignTitle],
                    A.[campaignDesc],
                    A.[campaignType],
                    A.[campaignStatus],
                    A.[dataNeeded],
                    A.[duration],
                    A.[whoCreated],
                    B.[type],
                    CONVERT (VARCHAR (20), dateCreated, 100) AS dateCreated
            FROM   [dbo].[Tags_Campaigns] A
            INNER JOIN  [dbo].[Tags_Data_Types] B
            ON A.campaignType = B.id
            WHERE A.[campaignID] = @campaignID
            FOR    XML PATH ('campaign'), TYPE, ELEMENTS, ROOT ('root');
        END 
END

它连接在一个存储类型的表上:

enter image description here

我的输出生成如下:

            <root>
             <campaign>
            <campaignID>31</campaignID>
            <campaignTitle>Testing</campaignTitle>
            <campaignDesc>This is a test campaign to see what happens with stuff.</campaignDesc>
            <campaignType>2</campaignType>
            <campaignStatus>Active</campaignStatus>
            <dataNeeded>2,1</dataNeeded>
            <duration>21</duration>
            <whoCreated>carl</whoCreated>
            <type>Case</type>
            <dateCreated>Nov 23 2013  6:48PM</dateCreated>
          </campaign>
        </root>

正如你所看到的,它加入了我想要的东西,但它只从1,2输入中得到了其中一个。

我怎样才能让结果看起来像

  <type>PayPal Account,Case</type>
  <dataNeeded>1,2</dataNeeded>

0 个答案:

没有答案