parse a string into two pieces in view?

If I have a field of type nvarchar(255), is it possible within a single select statement to split the value into two fields? For example of a given record:

dbo.image.filepath = 'e:\domain\repository\v000012.bmp'

Instead of simply saying "select filepath from image" to result in a single column containing that entire string,  I would do something like:

 "select [some code here??] as path, [some code here??] as filename from image"

where the result would be:
path = 'e:\domain\repository\'
filename = 'v000012.bmp'

I am trying to perform this split within the select statement that defines a view.


Who is Participating?
Anthony PerkinsConnect With a Mentor Commented:
Something like this perhaps:

SELECT      LEFT(filepath, LEN(filepath) - CHARINDEX('\', REVERSE(filepath))) path,
            SUBSTRING(filepath, LEN(filepath) - CHARINDEX('\', REVERSE(filepath)) + 2, LEN(filepath)) filename
FROM ...
PMH4514Author Commented:
perfect! thanks
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.