mrtaikandi
mrtaikandi

Reputation: 6968

Incorrect syntax near ')'

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

Upvotes: 0

Views: 1031

Answers (2)

Jason Brubaker
Jason Brubaker

Reputation: 163

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 "&gt;" and "<" to "&lt;" and "&" to "&amp;". Doing search-and-replace across the imported scripts in the InstallShield script editor for these three substitutions fixed the issue for me.

Upvotes: 1

David Hedlund
David Hedlund

Reputation: 129832

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.

Upvotes: 0

Related Questions