Agent Jobs

Everything To Right Of Slash

If you’ve ever seen a full folder path, and file name in the MSDB system tables; one of the first things you need to do is get just the path, or just the file name. There’s a few ways you can get these returned, but this is the way I use.

-- get only the file names to the right of the slash.
	right(physical_device_name, charindex('\', reverse('\' + physical_device_name)) - 1) from 

-- get the path to the left of the last slash.  basically gives you the full path to where the file resides.
	reverse(right(reverse(physical_device_name), len(physical_device_name) - charindex('\',reverse(physical_device_name),1) + 1)) from 


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s