简体   繁体   English

SQL Job运行一些select语句'\\'附近的语法不正确。 [SQLSTATE 42000](错误102)

[英]SQL Job running a few select statements Incorrect syntax near '\'. [SQLSTATE 42000] (Error 102)

I have a SQL job that contains a few select statements (4 views and 1 text). 我有一个SQL作业,其中包含一些select语句(4个视图和1个文本)。

EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'Database Email',
    @recipients = 'dbcheck@xxx.com',
    @subject = 'SQL Replication Deletion Check',
    @query = 'SELECT '\\server1\folder1\SQL\check.sql' AS [Script]
SELECT * FROM [repserv].[dbo].[1repdupecheck]
SELECT * FROM [repserv].[dbo].[2repdupecheck]
SELECT * FROM [repserv].[dbo].[3repdupecheck]
SELECT * FROM [repserv].[dbo].[4repdupecheck]',
    @attach_query_result_as_file = 1;

I currently get the following error when running it. 我目前在运行它时遇到以下错误。

Message
Executed as user: SERVER1\sqlusr. Incorrect syntax near '\'. [SQLSTATE 42000] (Error 102).  The step failed.

Now I have also tried taking out the line with the '\\' in and it works so I can only assume a bracket or something needs to be put around the back slashes in the select text. 现在,我也尝试去掉带有'\\'的行,它可以正常工作,因此我只能假设在选择文本中的方括号或反斜杠周围需要放置一些内容。

您需要转义反斜杠和引号

'SELECT ''\\\\server1\\folder1\\SQL\\check.sql'' AS [Script]

在下面的帮助下得到了它,只需添加双单引号即可(不需要在反斜杠上加倍)

'SELECT ''\\server1\folder1\SQL\check.sql'' AS [Script]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQLSTATE 42000(错误102)')附近的语法不正确 - SQLSTATE 42000 (Error 102) Incorrect syntax near ')' SQL 服务器作业 - “订单”附近的语法不正确。 [SQLSTATE 42000](错误 102) - SQL Server Job - Incorrect syntax near 'order'. [SQLSTATE 42000] (Error 102) T-SQL 作业失败,“ ”附近的语法不正确。 [SQLSTATE 42000](错误 102) - T-SQL Job fail with Incorrect syntax near ' '. [SQLSTATE 42000] (Error 102) 错误:“ EHP_VEHICLE”附近的语法不正确。 SQLState:42000错误代码:102 - Error:Incorrect syntax near 'EHP_VEHICLE'. SQLState: 42000 ErrorCode:102 SQL错误(102):“>”附近的语法不正确 - SQL Error (102): Incorrect syntax near '>' SQL错误(102):“ =”附近的语法不正确 - SQL Error (102): incorrect syntax near “=” SQL Server 错误 102 “附近的语法不正确” - SQL Server Error 102 Incorrect Syntax near " (42000,[42000] [Microsoft][ODBC Driver 17 for SQL 服务器][SQL Server] s. (102) (SQLExecDirectW) 附近的语法不正确) - (42000, [42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near s. (102) (SQLExecDirectW)) ';' 附近的语法不正确 (Microsoft SQL Server 错误 102) - Incorrect Syntax near ';' (Microsoft SQL Server Error 102) 无法运行查询:SQLSTATE [42000]:[Microsoft] [SQL Server Native Client 11.0] [SQL Server]')'附近的语法不正确 - Failed to run query: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near ')'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM