Author |
Topic |
obewankanoochie
Starting Member
24 Posts |
Posted - 2007-09-26 : 18:17:26
|
I've got a table with a list of directories. I need to output all the directories that are at least 3 directories deep. Here's an example of the entries:1) Sports2) Sports/Football3) Sports/Football/American4) Sports/Football/American/College_and_University5) Sports/Football/American/College_and_University/NCAA_Division_III6) Sports/Football/American/College_and_University/NCAA_Division_III/Atlantic_Central_Football_Conference7) Sports/Football/American/College_and_University/NCAA_Division_III/Atlantic_Central_Football_Conference/Frostburg_State8) Sports/Darts9) Sports/Darts/Organizations10) Sports/Darts/Organizations/United_States11) Sports/Darts/Organizations/United_States/AlabamaI need to run a query that only results in 4,5,6,7,10,11, or anything with at least 3 slashes "/" in it.Please tell me that this is possible. I'm out of ideas. Thanks. |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-09-26 : 19:16:46
|
[code]SELECT *FROM sampletableWHERE LEN(directory) - LEN(REPLACE(directory, '/', '')) >= 3[/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-09-26 : 19:44:33
|
quote: Originally posted by khtan
SELECT *FROM sampletableWHERE LEN(directory) - LEN(REPLACE(directory, '/', '')) >= 3 KH[spoiler]Time is always against us[/spoiler]
Hey thats smart Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
|
|
obewankanoochie
Starting Member
24 Posts |
Posted - 2007-09-26 : 20:20:12
|
quote: Originally posted by dinakar
quote: Originally posted by khtan
SELECT *FROM sampletableWHERE LEN(directory) - LEN(REPLACE(directory, '/', '')) >= 3 KH[spoiler]Time is always against us[/spoiler]
Hey thats smart Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/
Very clever. Thank you! |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-09-27 : 02:58:04
|
What about this?SELECT DirectoryFROM SampleTableWHERE Directory LIKE '%/%/%/%' E 12°55'05.25"N 56°04'39.16" |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-09-27 : 02:59:37
|
And if you want it "dynamic"...SELECT ID, dataFROM @SampleWHERE data LIKE '%' + REPLICATE('/%', 3) E 12°55'05.25"N 56°04'39.16" |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-09-27 : 04:22:54
|
quote: Originally posted by Peso What about this?SELECT DirectoryFROM SampleTableWHERE Directory LIKE '%/%/%/%' E 12°55'05.25"N 56°04'39.16"
That's an smarter solution ! KH[spoiler]Time is always against us[/spoiler] |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-09-27 : 04:30:01
|
Thank you!I thought this is a better solution because it also works on TEXT datatype columns. E 12°55'05.25"N 56°04'39.16" |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-09-27 : 05:35:38
|
"it also works on TEXT datatype columns"Blimey! Some hefty hierarchy in your organisation! |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-09-27 : 06:33:16
|
Not so many levels rather than lengthy "catchy" names. E 12°55'05.25"N 56°04'39.16" |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-09-27 : 06:36:37
|
"lengthy "catchy" names"Ah yes! The Antidisestablishmentarianism department ... |
|
|
|