February 27, 2006 at 2:34 am
Dear all,
I can't work out. I would need get ordered list from a string field but this own a dynamic contents. I'm looking for
a method which provides me the ordered list by name field, how do I such thing?
i.e:
\\122.12.7.40\c\sistel\execv\dat\LOTNODOS.txt
\\OFI0675P25\VARIOS\DETALLE.TXT
c:\test\enr.txt
Thanks in advance and regards,
Enric
February 27, 2006 at 10:58 am
if you know the maximum length of the column
select myfield
from mytable
order by convert(char(maxlen),myfield)
March 2, 2006 at 12:42 am
You asked:
provide me the ordered list by name field, how do I such thing?
i.e:
\\122.12.7.40\c\sistel\execv\dat\LOTNODOS.txt
\\OFI0675P25\VARIOS\DETALLE.TXT
c:\test\enr.txt
I am not sure what you mean. What is the wanted result? Is this (using the example)
enr.txt
DETALLE.txt
LOTNODOS.txt
March 2, 2006 at 12:53 am
Yeah, it was just that.
March 2, 2006 at 1:59 am
A solution could be:
Reverse the value of the field, find the backslash, copy it including the backslash, reverse it back and remove the backslash.
When you are absolute sure that there is always a backslash you could also use:
Reverse the value of the field, find the backslash, copy it excluding the backslash, reverse it back.
Here is an example. Type this in the Query Analyzer to see how it wordks.
declare @test-2 varchar(50) set @test-2 = '\\OFI0675P25\VARIOS\DETALLE.TXT'
SELECT REPLACE(REVERSE(SUBSTRING(REVERSE(@Test),1,CHARINDEX('\',REVERSE(@Test)))),'\','')
March 2, 2006 at 2:03 am
that finally works properly:
REVERSE(substring(REVERSE(DATASOURCE),1,charindex('\',REVERSE(DATASOURCE)) -1)) AS F
Thanks to all for your comments.
March 2, 2006 at 2:30 am
OK, that is precise what I meant with my second solution.
But it gives a problem when the string is empty, or contains no backslash.
So, not knowing what values in real occur in your database, I gave you the most secure solution.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply