我的查詢返回所有調用。我需要將返回的XML值分爲4列:將SQL XML解析回SQL列
FirstCallDate,SecondCallDate,ThirdCallDate,LastCallDate。
當前查詢:
SELECT AllCalls FROM
(
SELECT
( SELECT startdate
FROM mycalls i WITH (NOLOCK) WHERE i.phone = d.phone FOR XML AUTO)
AS AllCalls
FROM [MYDB].[dbo].[Accounts] d WITH (NOLOCK)
WHERE SubmittedDate BETWEEN @MyStartDate AND @MyEndDate
) e
這有時會返回:
- NULL
- 我STARTDATE = 「2012-02-29T13:50:37」/>
- 我startdate =「2012-02-29T14:20:58」/> i startdate =「2012-02-29T14:21:13」/>(刪除開始括號)
- 3 +日期
- 4 +紅棗
- 5 +紅棗
- 等
所以我回來查詢應該看起來像下面的SQL,但每列應該只持有1個日期。
SELECT FirstCallDate, SecondCallDate, ThirdCallDate, LastCallDate
FROM
(
SELECT
( SELECT startdate
FROM mycalls i WITH (NOLOCK) WHERE i.phone = d.phone FOR XML AUTO)
AS AllCalls
FROM [MYDB].[dbo].[Accounts] d WITH (NOLOCK)
WHERE SubmittedDate BETWEEN @MyStartDate AND @MyEndDate
) e
關於如何將XML解析回SQL列的任何想法?