How to escape back slash in SQL server
You do not need to escape the backslashes (only the inner single quotes):
DECLARE @Query nvarchar(max)
SET @Query ='DECLARE @Test nvarchar(max)
SELECT @Test = ''\a\b\c''
SELECT @Test'
PRINT @Query
exec sp_executesql @Query
There is in fact one place where back slashes do need to be escaped (or at least treated specially) in SQL Server.
When a backslash immediately precedes a new line in a string literal both the backslash and the new line are removed.
PRINT 'Foo\
Bar'
Returns
FooBar
The article here indicates that this is a feature of the client tools rather than TSQL itself but I don't believe this to be the case as the following code has the same result
DECLARE @X VARCHAR(100) = 'PRINT ''Foo\' + CHAR(13) + CHAR(10) + 'Bar'' '
EXEC(@X)
If you actually require a string literal with a backslash followed by carriage returns you can double them up.
PRINT 'Foo\\
Bar'