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

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 substring query

Author  Topic 

Yak Posting Veteran

88 Posts

Posted - 2015-09-23 : 17:55:19
i have the table to store the value:\\file0\shares\_Reporting\Q\BR01\Test.txt

how can i select to get only the file name which is Test.txt?


Posting Yak Master

129 Posts

Posted - 2015-09-25 : 05:04:18
create table test(strVal varchar(max))
insert into test values('\\file0\shares\_Reporting\Q\BR01\Test.txt')
select REVERSE(substring(reverse(strVal),0,PATINDEX('%\%',reverse(strVal)))) from test

Murali Krishna

You live only once ..If you do it right once is enough.......
Go to Top of Page

- Advertisement -