Author |
Topic |
mkhalid
Starting Member
9 Posts |
Posted - 2007-10-14 : 03:33:17
|
Hi,I need some help in splitting up my data.table is as followsProductID ComboProductIDs123 125,124,126124 127,21,245I need a query or function to display the data as followsProductID ComboProductIDs123 125123 124123 126124 127124 21124 245like it was never comma delimitted in the first place.is this possible. |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
mkhalid
Starting Member
9 Posts |
Posted - 2007-10-14 : 03:37:45
|
tried it, didnt seem to get it working. |
|
|
mkhalid
Starting Member
9 Posts |
Posted - 2007-10-14 : 03:40:24
|
there are two columns the first one is an identity productid and the second column has comma delimitted data. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-10-14 : 03:44:35
|
the number of value in the comma delimited data is it always 3 ? KH[spoiler]Time is always against us[/spoiler] |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-10-14 : 05:25:16
|
Not easy in SQL 2000 if there are a variable number of items.Any chance that you are using SQL 2005?Kristen |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-14 : 10:07:25
|
Can you wait until tomorrow? I have a way to do a "cross apply" in SQL Server 2000 without function. E 12°55'05.25"N 56°04'39.16" |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-10-14 : 10:18:38
|
that should be interesting. _______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-14 : 10:51:59
|
Could be. It is a variant of the code Kristen borrowed from me to do V3 split function. E 12°55'05.25"N 56°04'39.16" |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-10-14 : 10:54:14
|
"I have a way to do a "cross apply" in SQL Server 2000 without function."Heretofore thought to be impossible ... <BaitedBreath!> |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-10-14 : 12:35:12
|
quote: Originally posted by Peso Can you wait until tomorrow? I have a way to do a "cross apply" in SQL Server 2000 without function. E 12°55'05.25"N 56°04'39.16"
I gotta see this. KH[spoiler]Time is always against us[/spoiler] |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-10-14 : 12:41:44
|
Sorry, Peso won't be in tomorrow, I've given him a job in marketing |
|
|
mkhalid
Starting Member
9 Posts |
Posted - 2007-10-14 : 13:20:39
|
comma delimitted data is a varchar(500) therefore it has more than 3 values. |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-10-14 : 14:13:52
|
Are you using SQL 2005?Kristen |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-10-14 : 14:26:06
|
well since he posted in 2000 forum i doubt it _______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-10-14 : 15:23:21
|
Indeed, that's why I asked But I got no answer the first time, so I have now asked again. If the OP is on SQL 2005 then Cross Apply would make the job easy, but if its SQL2000 then its going to be Loops, Cursors and Peso's "String + Gum" ...Kristen |
|
|
mkhalid
Starting Member
9 Posts |
|
mkhalid
Starting Member
9 Posts |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-15 : 02:22:20
|
[code]DECLARE @Sample TABLE (Col1 VARCHAR(6), Col3 VARCHAR(200))INSERT @SampleSELECT '123', '125,124,126' UNION ALLSELECT '124', '127,21,245'--SELECT Col1,-- Data--FROM @Sample--CROSS APPLY fnParseList(',', Col3)SELECT a.Col1, SUBSTRING(',' + a.Col3 + ',', n.Number + 1, CHARINDEX(',', ',' + a.Col3 + ',', n.Number + 1) - n.Number - 1) AS [Value] FROM @Sample AS aINNER JOIN master..spt_values AS n ON n.Type = 'p'WHERE n.Number > 0 AND SUBSTRING(',' + a.Col3 + ',', n.Number, 1) = ',' AND n.Number < LEN(',' + a.Col3 + ',')[/code]Also blogged at http://weblogs.sqlteam.com/peterl/archive/2007/10/15/Cross-apply-in-SQL-Server-2000.aspx E 12°55'05.25"N 56°04'39.16" |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-10-15 : 02:27:10
|
interesting!_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-10-15 : 02:29:07
|
you should put this on dotnetkicks, peter._______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
|
|
Next Page
|