Friday, February 17, 2012

extracting data from a varchar variable?

Guys.

I have some data like this one:

'Uploadfiles\CompanyID\ProjectCode\Files\File1.doc'

P.S: the values may vary each time.

I need to programmatically extract from that kind of string only file1.doc

Ho can I dynamically do it? any function? statement? etc? please help.

The idea is getting only the string after the last "\"

Thanks
Frdeclare @.t varchar(256)

select @.t = 'Uploadfiles\CompanyID\ProjectCode\Files\File1.doc'

select reverse(substring(reverse(@.t),1,patindex('%\%',reverse(@.t))-1))

No comments:

Post a Comment