A. Boy
A. Boy

Reputation: 47

Retrieving escape character (\) from variable

So I'm trying to write a query in SQL that retrieves everything after the backslash. What I'm doing right now to get the position of the backslash is this:

INSTR('xx\yy', '\\')

The problem is that the escape character is being executed before the search so it will never find the character. I know this is happening because LENGTH('xx\yy') returns 4.

Ideally I would put a second escape character in but I can't do that because I'm retrieving the value from whoami.exe and putting it into a variable. So my variable looks something like 'company\username'. Obviously I would like to retrieve username but the escape character is evaluated before I can get its position.

Does anyone have any advice?

Thanks

Upvotes: 0

Views: 107

Answers (1)

Civette
Civette

Reputation: 538

If there is only one backslash

("Part1\Part2" -split "\\")[1]

Upvotes: 1

Related Questions