如何在 SQL Server 中转义反斜杠 [英] How to escape back slash in SQL server

查看:101
本文介绍了如何在 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

这篇关于如何在 SQL Server 中转义反斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆