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)
 How to get second set numbers from dot to hyphen

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2010-08-16 : 16:11:48
I have lot of filenames in this format.
"1062.1818-FuncSpecdocument.doc"
how to get second set number starting from dot to hyphen.

with the above example it should give the result as 1818

i have almost 100,000 file names now want to fetch all the id's.

Thank you very much for the helpful info.

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-08-16 : 16:14:16
If all filenames are in the same format, like you mentioned...then this should work.
declare @d varchar(200)
set @d = '1062.1818-FuncSpecdocument.doc'
select parsename(replace(@d,'-','.'),3)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-17 : 10:33:15
SELECT SUBSTRING(@d,CHARINDEX('.',@d)+1,CHARINDEX('-',@d)-CHARINDEX('.',@d)-1)

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-08-19 : 09:06:24
quote:
Originally posted by vijayisonly

If all filenames are in the same format, like you mentioned...then this should work.
declare @d varchar(200)
set @d = '1062.1818-FuncSpecdocument.doc'
select parsename(replace(@d,'-','.'),3)



Beware that this may not work for all set of data if some have more than three dots

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -