This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @tblXML TABLE ( | |
UID int IDENTITY(1,1), | |
Software XML | |
) | |
INSERT INTO @tblXML (Software) VALUES ('<root><program><name>AAA</name></program><program><name>BBB</name></program></root>') | |
INSERT INTO @tblXML (Software) VALUES ('<root><program><name>CCC</name></program><program><name>DDD</name></program></root>') | |
INSERT INTO @tblXML (Software) VALUES ('<root><program><name>AAA</name></program><program><name>DDD</name></program></root>') | |
DECLARE @Software XML | |
DECLARE @tblAll TABLE ( | |
Name nvarchar(max) | |
) | |
--設定指標 | |
DECLARE tmpCursor CURSOR FAST_FORWARD FOR | |
SELECT TOP 100 [Software].query('//program//name') FROM @tblXML | |
OPEN tmpCursor --開啟指標 | |
FETCH NEXT FROM tmpCursor INTO @Software --設定讀取變數 | |
--迴圈讀取 | |
WHILE @@FETCH_STATUS = 0 | |
BEGIN | |
--PRINT CAST(@Software as nvarchar(max)) | |
INSERT INTO @tblAll | |
SELECT n.value('.','nvarchar(max)') | |
FROM @Software.nodes('//name') t(n) | |
FETCH NEXT FROM tmpCursor INTO @Software | |
END | |
CLOSE tmpCursor --關閉指標 | |
DEALLOCATE tmpCursor --移除指標 | |
SELECT NAME, COUNT(NAME) 'Total' FROM @tblAll | |
GROUP BY NAME |