Query中的单独XML行

时间:2014-09-11 13:55:45

标签: sql sql-server xml

我有以下查询:

DECLARE @INSERTED AS TABLE
(
    PTTD_Id int,
    PTTD_PTT_Id int,
    PTTD_ShirtNumber    int,
    PTTD_FromDate   date,
    PTTD_ToDate date,
    PTTD_CreateDate datetime,
    PTTD_ModifiedDate   datetime,
    PTTD_ModifiedBy int
)

INSERT INTO @INSERTED
SELECT  *
FROM    TblPlayerToTeamDetails
WHERE   PTTD_Id IN (165402, 194835)


DECLARE @TblQueuesPendingMessages AS TABLE
( 
    QPM_QueueUriId INT,
    QPM_Message nvarchar(max), 
    QPM_Properties nvarchar(max)
)


--^^ Just to simulate ^^








DECLARE @GameIds AS TABLE
(
MatchFixture_Id INT
)
INSERT INTO @GameIds
SELECT      MatchFixture_Id
FROM        @INSERTED AS I
    JOIN    TblPlayerToTeam ON I.PTTD_PTT_Id = PlayerToTeam_Id
    JOIN    TblMatchFixture ON PlayerToTeam_Team IN (MatchFixture_HomeTeam, MatchFixture_AwayTeam) 
    AND     MatchFixture_Kickoff BETWEEN PlayerToTeam_FromDate AND ISNULL(PlayerToTeam_ToDate, '3000-01-01')
    AND     MatchFixture_Kickoff BETWEEN PTTD_FromDate AND ISNULL(PTTD_ToDate, '3000-01-01')
WHERE       MatchFixture_Kickoff BETWEEN DATEADD(DAY, -1, GETUTCDATE()) AND DATEADD(DAY, 1, GETUTCDATE())


INSERT INTO @TblQueuesPendingMessages
( 
    QPM_QueueUriId,
    QPM_Message, 
    QPM_Properties
)
VALUES
(
    7,
    (
        SELECT      
                CAST(I.PTTD_PTT_Id AS NVARCHAR)             AS 'PlayerId' , 
                CAST(I.PTTD_ShirtNumber AS NVARCHAR)        AS 'ShirtNumber',
                CAST(PlayerToTeam_Team AS NVARCHAR)         AS 'TeamId',
                CAST(I.PTTD_ModifiedDate AS NVARCHAR)       AS 'ModifiedDate'
        FROM    @INSERTED AS I
        JOIN    TblPlayerToTeam ON I.PTTD_PTT_Id = PlayerToTeam_Id
        JOIN    TblMatchFixture ON PlayerToTeam_Team IN (MatchFixture_HomeTeam, MatchFixture_AwayTeam) 
        AND     MatchFixture_Kickoff BETWEEN PlayerToTeam_FromDate AND ISNULL(PlayerToTeam_ToDate, '3000-01-01')
        AND     MatchFixture_Kickoff BETWEEN PTTD_FromDate AND ISNULL(PTTD_ToDate, '3000-01-01')
        WHERE   MatchFixture_Kickoff BETWEEN DATEADD(DAY, -1, GETUTCDATE()) AND DATEADD(DAY, 1, GETUTCDATE())
        FOR     XML PATH('PlayerDetails'), ROOT('Message')
    ),

       (SELECT  Ids.Matchfixture_Id AS 'GameId'  FROM @GameIds AS Ids
       FOR XML PATH('Properties'),ELEMENTS) 
)


--Just for simulate:
SELECT  *
FROM    @TblQueuesPendingMessages

结果是我得到1行2 xml数据,我希望每个数据都是一个saparate行,这是可能的吗?

0 个答案:

没有答案