134
Views
2
Comments
backslash issue in advanced query sqlserver
Question
Hi,

I need to compare a value in the database which contains a backslash.

so my query looks like this 

SELECT {User}.[Name], {User}.[Username], 'FOO\' + @Somename
FROM {User}
WHERE {User}.[Username] = 'FOO\' + @Somename

however, the backslash will be generated as double backslash.
so the compare always fails.

how to fix this?


2016-04-21 20-09-55
J.
 
MVP
well, bit puzzled myself and ended up with this

SELECT {User}.[Name], {User}.[Username]
FROM {User}
WHERE {User}.[Username] = 'FOO'+ char(92) + @Somename
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Yeah, that works. Alternatively, you could pass "FOO\" as a separate parameter or add it to @Somename if that's the only use of it.
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.