SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to get second set numbers from dot to hyphen
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

cplusplus
Aged Yak Warrior

541 Posts

Posted - 08/16/2010 :  16:11:48  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
1836 Posts

Posted - 08/16/2010 :  16:14:16  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 08/17/2010 :  10:33:15  Show Profile  Reply with Quote
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

India
22772 Posts

Posted - 08/19/2010 :  09:06:24  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000