Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 selecting string only question

Author  Topic 

PatDeV
Posting Yak Master

197 Posts

Posted - 2009-08-18 : 14:34:43
hi,

i need to knwo how can i select only the file name out of this:

//servernase/folder/foldername/ETK.txt file

i just want to return anyfilename.txt but file name can change so i trid rtrim 7 did not work.

Thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-08-18 : 14:39:57

select
reverse(substring(reverse('//servernase/folder/foldername/ETK.txt') ,1,charindex('/',reverse('//servernase/folder/foldername/ETK.txt'))-1))




No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-08-18 : 14:42:59
[code]DECLARE @Sample TABLE
(
p VARCHAR(300)
)

INSERT @Sample
SELECT '//servernase/folder/foldername/ETK.txt'

SELECT p,
reverse(substring(reverse(p), 1, charindex('/', reverse(p)) - 1)) AS Webfred,
right(p, charindex('/', reverse(p)) - 1) AS Peso
FROM @Sample[/code]


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-08-18 : 14:49:53
quote:
Originally posted by Peso

DECLARE	@Sample TABLE
(
p VARCHAR(300)
)

INSERT @Sample
SELECT '//servernase/folder/foldername/ETK.txt'

SELECT p,
reverse(substring(reverse(p), 1, charindex('/', reverse(p)) - 1)) AS Webfred,
right(p, charindex('/', reverse(p)) - 1) AS Peso
FROM @Sample



N 56°04'39.26"
E 12°55'05.63"



Hi Peso,
your solution looks much better than mine.
This is because I am only trying to get things to work while you are (always) looking to make things speedy.

Thanks for the pointer...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -