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 check the file extension and replace

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2009-01-09 : 12:46:21
I have the following variable in SP: @FilePath

It has the full filepath including filename & its extension.

How can i check the file extension if it is ".doc" or ".rtf" then replace just the file extension to ".pdf"

Thank you very much for the help.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-09 : 13:03:47
REPLACE(REPLACE(@FilePath,'.doc','.pdf'),'.rtf','.pdf')
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-01-09 : 13:11:30
select Case when substring(@Filepath,charindex('.',@filepath),4) in( '.doc','.rtf') then Replace(@filepath,right(@Filepath,4),'.pdf')else @Filepath end
Go to Top of Page

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2009-01-09 : 13:29:45
Thank you Visakh, your answers are always smart........

quote:
Originally posted by visakh16

REPLACE(REPLACE(@FilePath,'.doc','.pdf'),'.rtf','.pdf')

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-09 : 13:34:06
welcome
Go to Top of Page
   

- Advertisement -