如何在 SQL Server 中转义反斜杠
问题描述:
DECLARE @Query nvarchar(max)
SET @Query ='DECLARE @Test nvarchar(max)
SELECT @Test = ''\a'\b'\c''
SELECT @Test
PRINT @Query
exec sp_executesql @Query
我正在尝试以 \a\b\c 的形式获得输出.上面的错误可能是因为我无法转义\字符.
I am trying to get an output as \a\b\c. The above error is probably because I am not able to escape the \ character.
答
你不需要转义反斜杠(只有内部单引号):
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