Author |
Topic |
raysefo
Constraint Violating Yak Guru
260 Posts |
Posted - 2007-04-11 : 09:38:20
|
Hi,I have a field like below, (KODSTR) and i would like to get 150.01 and below. How can i do it?KODSTR150 150.01 150.01.01 150.01.01.01 150.01.01.02 .. 150.01.02 150.01.02.01... 150.01.02.08 150.01.01.08.01 150.01.01.08.02 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-11 : 09:41:20
|
select *from table1where KODSTR LIKE '150.01%'Peter LarssonHelsingborg, Sweden |
|
|
raysefo
Constraint Violating Yak Guru
260 Posts |
Posted - 2007-04-11 : 15:20:43
|
if i want to get from 150.01 and below till 150.01.02.01, what should i do? |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-11 : 15:22:44
|
select *from table1where KODSTR >= '150.01' AND KODSTR <= '150.01.02.01'Peter LarssonHelsingborg, Sweden |
|
|
raysefo
Constraint Violating Yak Guru
260 Posts |
Posted - 2007-04-12 : 02:54:43
|
But i dont need 150.01.01!What i need is 150.01, 150.01.02, and lastly 150.01.02.01 NOT others. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-04-12 : 03:04:42
|
quote: Originally posted by raysefo But i dont need 150.01.01!What i need is 150.01, 150.01.02, and lastly 150.01.02.01 NOT others.
What is the logic ? How do you decide what is required and what is not ?Please explain clearly KH |
|
|
raysefo
Constraint Violating Yak Guru
260 Posts |
Posted - 2007-04-12 : 06:56:53
|
This is a tree structureKODSTR150 ----> Base150.01 ------> First root150.01.01 ----------> Second Root150.01.01.01 -------------> Third Rootand so on.if something like this is needed 150.01.02.08, then i should need to get (if i need to get from first root)150.01 --------> first root150.01.02 -----------> second root150.01.02.08 -------> third rootWhat i need is only the related roots. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-12 : 07:20:08
|
select *from table1where KODSTR >= '150.01' AND KODSTR <= '150.01.02.08'Peter LarssonHelsingborg, Sweden |
|
|
raysefo
Constraint Violating Yak Guru
260 Posts |
Posted - 2007-04-12 : 08:39:19
|
Peso,thanks for your reply but, there are more kodstr that i sent in my first post. and your answer will bring 150.01.01 as well which i dont need them |
|
|
raysefo
Constraint Violating Yak Guru
260 Posts |
Posted - 2007-04-12 : 08:41:21
|
here is a small part of KODSTR,150 150.01 150.01.01 150.01.01.01 150.01.01.02 150.01.01.03 150.01.01.04 150.01.01.05 150.01.01.06 150.01.01.07 150.01.01.08 150.01.01.08.01 150.01.01.08.02 150.01.01.08.03 150.01.01.08.04 150.01.01.08.05 150.01.01.08.06 150.01.01.08.07 150.01.01.08.08 150.01.01.08.09 150.01.01.08.10 150.01.01.08.11 150.01.01.08.12 150.01.01.08.13 150.01.01.09 150.01.01.11.01 150.01.01.11.02 150.01.01.12 150.01.01.13 150.01.01.14 150.01.01.15 150.01.01.16 150.01.01.17 150.01.01.18 150.01.01.19 150.01.01.20 150.01.01.20.01 150.01.01.20.02 150.01.01.20.03 150.01.01.20.04 150.01.01.20.05 150.01.01.20.06 150.01.01.20.07 150.01.01.20.08 150.01.01.20.09 150.01.01.20.10 150.01.01.20.11 150.01.01.20.12 150.01.01.20.13 150.01.01.20.14 150.01.01.20.15 150.01.01.20.16 150.01.01.20.17 150.01.02 150.01.01.09.01 150.01.01.09.02 150.01.01.09.03 150.01.01.09.04 150.01.01.10 150.01.01.11 150.01.02.10 150.01.02.10.01 150.01.02.10.02 150.01.03 150.01.03.01 150.01.03.01.01 150.01.03.01.02 150.01.03.01.03 150.01.03.01.04 150.01.03.01.05 150.01.03.01.06 150.01.03.01.07 150.01.03.01.08 150.01.03.01.09 150.01.03.01.11 150.01.03.01.12 150.01.03.01.13 150.01.03.01.14 150.01.03.01.15 150.01.03.01.16 150.01.03.01.17 150.01.03.01.18 150.01.03.02 150.01.03.02.01 150.01.03.02.02 150.01.03.02.03 150.01.03.02.04 150.01.03.02.05 150.01.02.01 150.01.02.02 150.01.02.03 150.01.02.04 150.01.02.05 150.01.02.06 150.01.02.07 150.01.02.08 150.01.02.09 150.01.03.02.15 150.01.03.02.16 150.01.03.02.17 150.01.03.02.18 150.01.03.02.19 150.01.03.03 150.01.03.03.01 150.01.03.03.02 150.01.03.03.03 150.01.04 150.01.04.01 150.01.04.02 150.01.04.03 150.01.04.03.01 150.01.04.03.02 150.01.04.04 150.01.04.04.01 150.01.04.04.02 150.01.04.04.03 150.01.04.05 150.01.04.05.01 150.01.04.06 150.01.04.06.01 150.01.04.07 150.01.04.08 150.01.04.09 150.01.04.10 150.01.05 150.01.03.02.06 150.01.03.02.07 150.01.03.02.08 150.01.03.02.09 150.01.03.02.10 150.01.03.02.11 150.01.03.02.12 150.01.03.02.13 150.01.03.02.14 150.01.05.02 150.01.05.02.01 150.01.05.02.02 150.01.05.03 150.01.05.03.01 150.01.05.03.02 150.01.05.03.03 150.01.05.03.04 150.01.05.03.05 150.01.06 150.01.06.01 150.01.06.02 150.01.06.03 150.01.06.04 150.01.06.05 150.01.06.06 150.01.06.07 150.01.06.08 150.01.06.09 150.01.07 150.01.07.01 150.01.07.02 150.01.07.03 150.01.07.04 150.01.07.05 150.01.07.06 150.01.07.07 150.01.07.08 150.01.05.01 150.01.05.01.01 150.01.05.01.02 150.01.05.01.03 150.01.05.01.04 150.01.05.01.05 150.01.05.01.06 150.01.05.01.07 150.01.05.01.08 150.01.05.01.09 150.01.05.01.10 150.01.07.18 150.01.07.19 150.01.07.20 150.01.07.21 150.01.07.22 150.01.07.23 150.01.07.24 150.01.07.25 150.01.07.26 150.01.07.27 150.01.07.28 150.01.07.29 150.01.08 150.01.08.01 150.01.08.01.01 150.01.08.01.02 150.01.08.01.03 150.01.08.01.04 150.01.08.01.05 150.01.08.01.06 150.01.08.01.07 150.01.08.01.08 150.01.08.02 150.01.08.02.01 150.01.08.02.02 150.01.08.02.03 150.01.08.02.04 255.10.02.03.05 150.01.07.09 150.01.07.10 150.01.07.11 150.01.07.12 150.01.07.13 150.01.07.14 150.01.07.15 150.01.07.16 150.01.07.17 150.02.02 150.02.02.01 150.02.02.02 150.02.02.03 150.02.02.04 150.02.02.05 150.02.02.06 150.02.02.07 150.02.02.08 150.02.03 150.02.03.01 150.02.03.02 150.02.03.03 150.02.03.04 150.02.03.05 150.02.03.06 150.02.03.07 150.02.03.08 150.02.03.09 150.02.04 150.02.04.01 150.02.04.02 150.02.04.03 150.02.04.04 150.02.04.05 255.10.02.03.06 150.02 150.02.01 150.02.01.01 150.02.01.02 150.02.01.03 150.02.01.04 150.02.01.05 150.02.01.06 150.02.01.07 150.02.01.08 150.02.01.09 150.02.01.10 150.02.05.02.03 150.02.05.02.04 150.02.05.02.05 150.02.05.02.06 150.02.05.03 150.02.05.03.01 150.02.05.03.02 150.02.05.03.03 150.02.05.04 150.02.05.04.01 150.02.05.04.02 150.02.05.04.03 150.02.05.04.04 150.02.05.04.05 150.02.05.05 150.02.05.05.01 150.02.05.05.02 150.02.05.05.03 150.02.05.05.04 150.02.05.06 150.02.05.06.01 150.02.05.06.02 150.02.05.06.03 150.02.05.07 150.02.05.07.01 150.02.04.06 150.02.05 150.02.05.01 150.02.05.01.01 150.02.05.01.02 150.02.05.01.03 150.02.05.01.04 150.02.05.01.05 150.02.05.01.06 150.02.05.01.07 150.02.05.01.08 150.02.05.02 150.02.05.02.01 150.02.05.02.02 150.03.01.01.01 150.03.01.01.02 150.03.01.01.03 150.03.01.01.04 150.03.01.01.05 150.03.01.01.06 150.03.01.01.07 150.03.01.01.08 150.03.01.01.09 150.03.01.01.10 150.03.01.01.11 150.03.01.01.12 150.03.01.01.13 150.03.01.02 150.03.01.02.01 150.03.01.02.02 150.03.01.02.03 150.03.01.02.04 150.03.01.02.05 150.03.01.03 150.03.01.03.01 150.03.01.03.02 150.03.01.03.03 150.03.01.03.04 150.03.01.03.05 150.02.05.07.02 150.02.05.07.03 150.02.05.07.04 150.02.05.07.05 150.02.05.07.06 150.02.05.07.07 150.02.05.07.08 150.02.05.08 150.03 150.03.01 150.03.01.01 150.03.01.04.06 150.03.01.04.07 150.03.01.04.08 150.03.01.05 150.03.01.05.01 150.03.01.05.02 150.03.01.05.03 150.03.01.05.04 150.03.01.05.05 150.03.01.05.06 150.03.01.05.07 150.03.01.05.08 150.03.01.05.09 150.03.01.05.10 150.03.01.05.11 150.03.01.05.12 150.03.01.05.13 150.03.01.05.14 150.03.01.05.15 150.03.01.06 150.03.01.06.01 150.03.01.06.02 150.03.01.06.03 150.03.01.06.04 150.03.01.06.05 150.03.01.03.06 150.03.01.04 150.03.01.04.01 150.03.01.04.02 150.03.01.04.03 150.03.01.04.04 150.03.01.04.05 255.10.02.03.07 150.03.01.08.01 150.03.01.08.02 150.03.01.08.03 150.03.01.08.04 150.03.01.08.05 150.03.01.08.06 150.03.01.08.07 150.03.01.09 150.03.01.09.01 150.03.01.09.02 150.03.01.09.03 150.03.01.09.04 150.03.01.09.05 150.03.01.09.06 150.03.01.09.07 150.03.01.09.08 150.03.01.09.09 150.03.01.09.10 150.03.01.10 150.03.01.10.01 150.03.01.10.02 150.03.01.10.03 150.03.01.10.04 150.03.01.10.05 150.03.01.11 150.03.01.06.06 150.03.01.07 150.03.01.07.01 150.03.01.07.02 150.03.01.07.03 150.03.01.07.04 150.03.01.07.05 150.03.01.08 150.03.01.12.05 150.03.01.12.06 150.03.01.12.07 150.03.01.12.08 150.03.01.13 150.03.01.13.01 150.03.01.13.02 150.03.01.13.03 150.03.01.13.04 150.03.01.14 150.03.01.14.01 150.03.02 150.03.02.01 150.03.02.01.01 150.03.02.01.02 150.03.02.01.03 150.03.02.01.04 150.03.02.01.05 150.03.02.01.06 150.03.02.01.07 150.03.02.01.08 150.03.02.01.09 150.03.02.01.10 150.03.02.02 150.03.02.02.01 150.03.01.11.01 150.03.01.11.02 150.03.01.11.03 150.03.01.11.04 150.03.01.11.05 150.03.01.12 150.03.01.12.01 150.03.01.12.02 150.03.01.12.03 150.03.01.12.04 150.03.02.03.05 150.03.02.03.06 150.03.02.03.07 150.03.02.03.08 150.03.02.03.09 150.03.02.03.10 150.03.02.03.11 150.03.02.03.12 150.03.02.03.13 150.03.02.03.14 150.03.02.03.15 150.03.02.03.16 150.03.02.03.17 150.03.02.03.18 150.03.02.03.19 150.03.02.03.20 150.03.02.03.21 150.03.02.03.22 150.03.02.03.23 150.03.02.03.24 150.03.02.03.25 150.03.02.03.26 150.03.02.03.27 150.03.02.03.28 150.03.02.02.02 150.03.02.02.03 150.03.02.02.04 150.03.02.02.05 150.03.02.02.06 150.03.02.02.07 150.03.02.02.08 150.03.02.03 150.03.02.03.01 150.03.02.03.02 150.03.02.03.03 150.03.02.03.04 150.09.05.04 150.03.02.05.06 150.03.02.05.07 150.03.02.05.08 150.03.02.05.09 150.03.02.05.10 150.03.02.05.11 150.03.02.05.12 150.03.02.05.13 150.03.02.05.14 150.03.02.05.15 150.03.02.05.16 150.03.02.05.17 150.03.02.05.18 150.03.02.05.19 150.03.02.05.20 150.03.02.05.21 150.03.02.05.22 150.03.02.05.23 150.03.02.05.24 150.03.02.06 150.03.02.06.01 150.03.02.06.02 150.03.02.06.03 150.03.02.06.04 150.03.02.03.29 150.03.02.04 150.03.02.04.01 150.03.02.04.02 150.03.02.04.03 150.03.02.04.04 150.03.02.04.05 150.03.02.04.06 150.03.02.05 150.03.02.05.01 150.03.02.05.02 150.03.02.05.03 150.03.02.05.04 150.03.02.05.05 150.03.02.07.08 150.03.02.07.09 150.03.02.07.10 150.03.02.07.11 150.03.02.07.12 150.03.02.07.13 150.03.02.08 150.03.02.08.01 150.03.02.08.02 150.03.02.08.03 150.03.02.08.04 150.03.02.08.05 150.03.02.08.06 150.03.02.08.07 150.03.02.08.08 150.03.02.08.09 150.03.02.08.10 150.03.02.09 150.03.02.09.01 150.03.02.09.02 150.03.02.09.03 150.03.02.09.04 150.03.02.09.05 150.03.02.10 150.03.02.06.05 150.03.02.06.06 150.03.02.06.07 150.03.02.06.08 150.03.02.06.09 150.03.02.06.10 150.03.02.07 150.03.02.07.01 150.03.02.07.02 150.03.02.07.03 150.03.02.07.04 150.03.02.07.05 150.03.02.07.06 150.03.02.07.07 150.03.02.12.01 150.03.02.12.02 150.03.02.12.03 150.03.02.12.04 150.03.02.12.05 150.03.02.12.06 150.03.02.12.07 150.03.02.13 150.03.02.13.01 150.03.02.13.02 150.03.02.13.03 150.03.02.13.04 150.03.02.13.05 150.03.02.13.06 150.03.02.13.07 150.03.02.13.08 150.03.02.13.09 150.03.02.13.10 150.03.02.13.11 150.03.02.13.12 150.03.02.13.13 150.03.02.13.14 150.03.02.13.15 150.03.02.13.16 150.03.02.10.01 150.03.02.10.02 150.03.02.10.03 150.03.02.10.04 150.03.02.10.05 150.03.02.10.06 150.03.02.10.07 150.03.02.11 150.03.02.11.01 150.03.02.11.02 150.03.02.11.03 150.03.02.11.04 150.03.02.12 150.03.02.14 150.03.02.14.01 150.03.02.14.02 150.03.02.14.03 150.03.02.14.04 150.03.02.14.05 150.03.02.14.06 150.03.02.14.07 150.03.02.14.08 150.03.02.14.09 150.03.02.14.10 150.03.02.14.11 150.03.02.14.12 150.03.02.15 150.03.02.15.01 150.03.02.15.02 150.03.02.15.03 150.03.02.15.04 150.03.02.15.05 150.03.02.15.06 150.03.02.15.07 150.03.02.15.08 150.03.02.15.09 150.03.02.15.10 150.03.02.13.17 150.03.02.13.18 150.03.02.13.19 150.03.02.13.20 150.03.02.13.21 150.03.02.13.22 150.03.02.13.23 150.03.02.13.24 150.03.02.13.25 150.03.02.13.26 150.03.02.13.27 150.03.02.13.28 150.03.02.13.29 150.03.02.16.03 150.03.02.16.04 150.03.02.16.05 150.03.02.16.06 150.03.02.16.07 150.03.02.16.08 150.03.02.16.09 150.03.02.16.10 150.03.02.16.11 150.03.02.16.12 150.03.02.16.13 150.03.02.16.14 150.03.02.17 150.03.02.17.01 150.03.02.17.02 150.03.02.17.03 150.03.02.17.04 150.03.02.17.05 150.03.02.17.06 150.03.02.17.07 150.03.02.17.08 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-12 : 09:08:33
|
This?-- Prepare sample dataDECLARE @KodStr TABLE (Data VARCHAR(99))INSERT @KodStrSELECT '150' UNION ALLSELECT '150.01' UNION ALLSELECT '150.01.01' UNION ALLSELECT '150.01.01.01' UNION ALLSELECT '150.01.01.02' UNION ALLSELECT '150.01.02' UNION ALLSELECT '150.01.02.01' UNION ALLSELECT '150.01.02.08' UNION ALLSELECT '150.01.01.08.01' UNION ALLSELECT '150.01.01.08.02'-- Show the expected outputSELECT MIN(y.Data) AS DataFROM ( SELECT k2.Data, RANK() OVER (ORDER BY LEN(k2.Data)) AS RecID FROM @KodStr AS k1 INNER JOIN @KodStr AS k2 ON LEN(k2.Data) >= LEN(k1.Data) AND k2.Data >= k1.Data WHERE k1.Data = '150.01' ) AS yGROUP BY y.RecIDORDER BY y.RecID Peter LarssonHelsingborg, Sweden |
|
|
|