3

I have a column called 'path' in my table which could look similar to:

\server\directory\subdirectory \server\directory\subdirectory\subdirectory

I'm trying to write a query that will only bring up entries that have, say at least 0-4 \'s and no more.

I can't seem to figure it out, I though something like:

SELECT Path FROM Share_table where CHARINDEX('\',path) < 5

But I have no success with the above line...Any help would be greatly appreciated.

ertuu85
  • 79
  • 1
  • 6

1 Answers1

3

Replace \ with empty string and find the difference with total length. Here is one way

where len(path) - len(replace(path,'\','')) < 5
Pரதீப்
  • 91,748
  • 19
  • 131
  • 172