Click here to Skip to main content
16,022,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am inserting a file name + date+milliseconds in DB.
But when i retrive that record i need to get only file name.

Ex;-

Id Filename

1 policies.doc_date_milliseconds
2 login.xls_date_milliseconds
3 user.pdf_date_milliseconds


Output:-

policies.doc
login.xls
user.pdf

Thanks in advance
Posted
Comments
Member 8490201 15-Dec-11 1:08am    
Do you want the name of the db it self or the file(of the db)
name date and so on

1 solution

try this query..

SQL
SELECT Id, SUBSTRING(Filename,1,(CHARINDEX('_',Filename,1)-1)) as 'file' from tablename


hope it works..
 
Share this answer
 
Comments
RaisKazi 15-Dec-11 1:34am    
OP's comments added as a solution. -

Hi karthik

Thanks for your reply.

It's working, but some times the file names consists "_" also

Ex:- Policies_names.xls_date_milliseconds
login_users_names.pdf_date_milliseconds

like this
RagSuchi 29-Dec-11 0:10am    
Thanks for your advice RaisKazi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900