Author |
Topic |
MikeSaunders
Starting Member
11 Posts |
Posted - 2013-10-07 : 15:30:38
|
Hello again,I am running into a problem importing a string containing an array into a table.My string looks like '[{mark,peters,mr}{jane,fonda,mrs}{john,doo,mr}{james,bond,mr}]'I want to import this into a temp table that looks like:ID, Fname, Lname, Sex1, mark, peters, mr2, jane, fonda, mrs3, john,doo,mr4, james,bond,mrCan someone help me with this? I really have no clue how to solve this.Thanks a lot!Mike |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-10-07 : 15:55:57
|
Not a very pleasant task, but something like this example:DECLARE @x VARCHAR(256) = '[{mark,peters,mr}{jane,fonda,mrs}{john,doo,mr}{james,bond,mr}]';SELECT *FROM (SELECT *FROM dbo.delimitedsplit8k( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE(@x,'[',''), ']',''), '}{','}'), '{',''), '{]','') ,'}')WHERE Item <> '') aCROSS APPLY dbo.DelimitedSplit8K(Item,',') bPIVOT (MAX(b.Item) FOR b.ItemNumber IN ([1],[2],[3]))P |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-08 : 00:10:19
|
DelimitedSplit8K function is from herehttp://www.sqlservercentral.com/articles/Tally+Table/72993/------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
MikeSaunders
Starting Member
11 Posts |
Posted - 2013-10-08 : 02:44:50
|
Hello all,Thanks for your help. The solutions you've provided are super and far beyond my current skill level.Learned a lot, Thanks again!!!Mike |
|
|
|
|
|