backslash issue in advanced query sqlserver

backslash issue in advanced query sqlserver

  
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?


well, bit puzzled myself and ended up with this

SELECT {User}.[Name], {User}.[Username]
FROM {User}
WHERE {User}.[Username] = 'FOO'+ char(92) + @Somename
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.