Monday, October 20, 2008

Backslashes in SQL Queries

I keep forgetting this one so I better write it down:

Brackets ([]) work on string constants (forgive the non sql terminology) as well as fieldnames.

When passing a fully qualified domain name into a sql query 'domain\userid', the backslash will cause errors and, at lease in the SQL Management studio, it can not be escaped via double-backslash 'domain\\userid'.

To pass a backslash in, surround the string in brackets inside the ticks: '[domain\userid]'

No comments: