') 附近的语法不正确

发布于 2024-07-27 02:47:06 字数 1019 浏览 8 评论 0原文

我有一个 BasicMSI 项目 (Installshield 2009),它在安装过程中运行 SQL 脚本。 在安装过程中我收到以下错误。

错误 27506。执行 SQL 脚本 {SCRIPTNAME} 时出错。 第 352 行。“)”附近的语法不正确。 (102)

问题是我在脚本的第 352 行没有任何“)”,而且如果我使用 SQL Management Studio Express 运行该脚本,该脚本也可以正常工作。

谁能告诉我问题是什么以及如何解决它? 谢谢。

附言。 我无法将脚本错误处理选项设置为“出错时,转到下一条语句”,因为它不会创建我的一些外键。

IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRIGGER_NAME]'))
EXEC dbo.sp_executesql @statement = N'
CREATE TRIGGER [dbo].[TRIGGER_NAME]
ON [dbo].[TABLE_NAME]                  -- LINE: 352
INSTEAD OF INSERT
AS
BEGIN 
DECLARE @Count INT;
SET @Count = (SELECT COUNT([Name]) 
                FROM TABLE_NAME
                WHERE IsDeleted = 0 AND [Name] IN (SELECT [Name] FROM INSERTED));

IF @Count > 0
BEGIN
    RAISERROR (''Error Message.'', 16, 1);
    Rollback;   
END
ELSE
BEGIN
    INSERT INTO dbo.TABLE_NAME SELECT {Columns} FROM INSERTED;
    SELECT CONVERT(BigInt,SCOPE_IDENTITY()) AS [value]
END
END
' 
GO

I have a BasicMSI project (Installshield 2009) that runs a SQL script during the installation process.
During the installation I receive the following error.

Error 27506.Error executing SQL script {SCRIPTNAME}. Line 352. Incorrect syntax near ')'. (102)

The problem is that I don't have any ')' at line 352 of the script and also the script works without any problems if I run it with SQL Management Studio Express.

Can anyone tell me what is the problem and how can I fix it?
Thanks.

PS. I cannot set the script error handling option to "On Error, Goto Next Statement" because therefor it will not create some of my foreign keys.

IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRIGGER_NAME]'))
EXEC dbo.sp_executesql @statement = N'
CREATE TRIGGER [dbo].[TRIGGER_NAME]
ON [dbo].[TABLE_NAME]                  -- LINE: 352
INSTEAD OF INSERT
AS
BEGIN 
DECLARE @Count INT;
SET @Count = (SELECT COUNT([Name]) 
                FROM TABLE_NAME
                WHERE IsDeleted = 0 AND [Name] IN (SELECT [Name] FROM INSERTED));

IF @Count > 0
BEGIN
    RAISERROR (''Error Message.'', 16, 1);
    Rollback;   
END
ELSE
BEGIN
    INSERT INTO dbo.TABLE_NAME SELECT {Columns} FROM INSERTED;
    SELECT CONVERT(BigInt,SCOPE_IDENTITY()) AS [value]
END
END
' 
GO

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鱼忆七猫命九 2024-08-03 02:47:06

我遇到了类似的错误(一个带有“)”作为违规字符,一个带有“;” 作为违规角色)。 然后我注意到当InstallShield导入我的脚本时,它改变了“>” 到“>” 和“<” 到“<” 和“&” 到“&”。 在 InstallShield 脚本编辑器中对导入的脚本进行搜索和替换以进行这三个替换,解决了我的问题。

I was getting similar errors (one with ')' as the offending character, one with ';' as the offending character). Then I noticed that when InstallShield imported my scripts, it had changed ">" to ">" and "<" to "<" and "&" to "&". Doing search-and-replace across the imported scripts in the InstallShield script editor for these three substitutions fixed the issue for me.

氛圍 2024-08-03 02:47:06

如果您编写了一个以编程方式填充的 IN 语句,只是在运行时缺少一些值,导致出现一条无效的语句“... WHERE x IN()”,则可能会出现此错误,这似乎是合理的。

这会生成该错误,而且该错误很容易在一种环境中出现,但在另一种环境中则不会出现。 如果没有实际看过剧本,很难给出更多细节。

It seems reasonable that this error might occur if you've written an IN statement, which you populate programmatically, only at runtime some values are missing, resulting in a statement saying "... WHERE x IN()", which is invalid.

This would generate that error, and also, it is an error that could easily appear in one environment but not another. It is hard to give more detail than that without actually seeing the script.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文