要從你的questi獲得結果於:
DECLARE @string NVARCHAR(MAX) = '352306055351667,LoginId,gangadaran.s,Password,1,VersionCode,38,DistributorId,158,OrganisationId,33,MobileDate,2014\/04\/04,13,40,10,UserId,7916,LastDayClose,,BranchId,158,DownloadedDataDate,2014\/04\/04',
@xml xml
select @xml = cast('<d><q>'+REPLACE(@string,',','</q><q>')+'</q></d>' as xml);
SELECT n.v.value('q[1]','NVARCHAR(50)') as Col1,
n.v.value('q[2]','NVARCHAR(50)') as Col2,
n.v.value('q[3]','NVARCHAR(50)') as Col3,
n.v.value('q[4]','NVARCHAR(50)') as Col4,
n.v.value('q[5]','NVARCHAR(50)') as Col5,
n.v.value('q[6]','NVARCHAR(50)') as Col6,
n.v.value('q[7]','NVARCHAR(50)') as Col7,
n.v.value('q[8]','NVARCHAR(50)') as Col8,
n.v.value('q[9]','NVARCHAR(50)') as Col9,
n.v.value('q[10]','NVARCHAR(50)') as Col10,
n.v.value('q[11]','NVARCHAR(50)') as Col11,
n.v.value('q[12]','NVARCHAR(50)') as Col12,
n.v.value('q[13]','NVARCHAR(50)') as Col13,
n.v.value('q[14]','NVARCHAR(50)') as Col14,
n.v.value('q[15]','NVARCHAR(50)') as Col15,
n.v.value('q[16]','NVARCHAR(50)') as Col16,
n.v.value('q[17]','NVARCHAR(50)') as Col17,
n.v.value('q[18]','NVARCHAR(50)') as Col18,
n.v.value('q[19]','NVARCHAR(50)') as Col19,
n.v.value('q[20]','NVARCHAR(50)') as Col20,
n.v.value('q[21]','NVARCHAR(50)') as Col21,
n.v.value('q[22]','NVARCHAR(50)') as Col22,
n.v.value('q[23]','NVARCHAR(50)') as Col23,
n.v.value('q[24]','NVARCHAR(50)') as Col24
FROM @xml.nodes('/d') AS n(v)
結果:
Col1 Col2 Col3 Col4 Col5 Col6 Col7 Col8 Col9 Col10 Col11 Col12 Col13 Col14 Col15 Col16 Col17 Col18 Col19 Col20 Col21 Col22 Col23 Col24
-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- --------------------------------------------------
352306055351667 LoginId gangadaran.s Password 1 VersionCode 38 DistributorId 158 OrganisationId 33 MobileDate 2014\/04\/04 13 40 10 UserId 7916 LastDayClose BranchId 158 DownloadedDataDate 2014\/04\/04
(1 row(s) affected)
的原始數據被存儲在與逗號分隔符的單個列? – Takarii
[如何將逗號分隔值拆分爲列]可能的重複(http://stackoverflow.com/questions/10581772/how-to-split-a-comma-separated-value-to-columns) –
我認爲'LoginId:352306055351667,密碼:gangadaran.s,VersionCode:1,DistributorId:38 ...'等,所以string包含列名和數據。 – gofr1