| Author |
Topic |
|
00kevin
Yak Posting Veteran
78 Posts |
Posted - 2008-05-14 : 11:21:03
|
right now I have a stored procedure that goes through each of the Line and Body fields using a cursor. The problem is that this method is very slow. How would you experts solve this problem? any Hints or suggestions? BEFORE EXAMPLE Part Line Body Series Engine Year1 1234 A,B W ETC 19982 5678 9 91,93,94,95 W ET0 19973 345656 S,R 5,6,12 W ENC 1995 AFTER EXAMPLE Part Line Body Series Engine Year 1 1234 A W ETC 19981 1234 B W ETC 1998 2 5678 9 91 W ET0 19972 5678 9 93 W ET0 19972 5678 9 94 W ET0 19972 5678 9 95 W ET0 1997 3 345656 S 5 W ENC 19953 345656 S 6 W ENC 19953 345656 S 12 W ENC 19953 345656 R 5 W ENC 19953 345656 R 6 W ENC 19953 345656 R 12 W ENC 1995 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-05-14 : 11:43:31
|
[code]DECLARE @Sample TABLE (Example INT, Part INT, Line VARCHAR(20), Body VARCHAR(20), Series VARCHAR(2), Engine VARCHAR(4), Year SMALLINT)INSERT @SampleSELECT 1, 1234 , 'A,B', NULL , 'W', 'ETC', 1998 UNION ALLSELECT 2, 5678 , '9' , '91,93,94,95', 'W', 'ET0', 1997 UNION ALLSELECT 3, 345656, 'S,R', '5,6,12' , 'W', 'ENC', 1995SELECT Example, Part, l.Data AS Line, b.Data AS Body, Series, Engine, YearFROM @SampleOUTER APPLY fnParseList(',', Line) AS lOUTER APPLY fnParseList(',', Body) AS b[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
00kevin
Yak Posting Veteran
78 Posts |
Posted - 2008-05-14 : 13:10:33
|
| cool... I never thought I would ever get to use outer apply :) oh and nice parselist function. I see you wrote that one too. |
 |
|
|
00kevin
Yak Posting Veteran
78 Posts |
Posted - 2008-05-14 : 14:17:27
|
| so if I want to get this to work in sql 2000 I would have to make the function return a unique(part number) key and then join on that. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-14 : 14:20:51
|
| Yup you need to. and also you might need a cross join too. APPLY operator wont work in 2000. |
 |
|
|
|
|
|