I wrote a trigger in the development environment which runs SQL Server 2008. I then tried to execute it in production, which runs SQL Server 2005.
I'm getting the following error:
Msg 102, Level 15, State 1, Procedure trg_issues_update, Line 97
Incorrect syntax near ','.
The query looks like this:
INSERT INTO users (username, firstname, surname, pwd, emailaddress, resetpwd, comment, apikey, active)
VALUES (@username, @first_name, @last_name, @password, @email, NULL, 'Comment: ' + CAST(@issueid AS VARCHAR), 'None', '1');
UPDATE: This is the part of the trigger where most of the variables are declared/set:
IF (SELECT projectid FROM inserted) = 55 AND (SELECT issuestatusid FROM inserted) = 28 BEGIN
DECLARE @full_name nvarchar (255)
SET @full_name = (SELECT fielddata FROM customfielddata WHERE issueid = @issueid AND customfieldid = 84)
DECLARE @first_name nvarchar (255)
SET @first_name = SUBSTRING(@full_name, 1, CHARINDEX(' ', @full_name) - 1)
DECLARE @last_name nvarchar (255)
SET @last_name = SUBSTRING(@full_name, CHARINDEX(' ', @full_name) + 1, LEN(@full_name) + 1)
DECLARE @email nvarchar (255)
SET @email = (SELECT fielddata FROM customfielddata WHERE issueid = @issueid AND customfieldid = 85)
DECLARE @location nvarchar (255)
DECLARE @domain nvarchar (255)
DECLARE @username nvarchar (255)
SET @location = (SELECT fielddata FROM customfielddata WHERE issueid = @issueid AND customfieldid = 86)
SET @domain = (SELECT fielddata FROM customfielddata WHERE issueid = @issueid AND customfieldid = 87)
IF @location = 'Canada' BEGIN SET @username = 'ORG1\' + UPPER(@domain) END
ELSE SET @username = 'ORG2\' + UPPER(@domain)
DECLARE @password binary (16)
SET @password = CONVERT(BINARY(16), HashBytes('MD5', ''), 2)
DECLARE @comment nvarchar (500)
SET @comment = 'APPR-' + CAST(@issueid AS VARCHAR)
INSERT INTO users (username, firstname, surname, pwd, emailaddress, resetpwd, comment, apikey, active)
VALUES (@username, @first_name, @last_name, @password, @email, NULL, @comment, 'None', '1');
DECLARE @userid NUMERIC(10,0)
SET @userid = (SELECT userid FROM users WHERE username = @username)
INSERT INTO globalgroupmembership (globalgroupid, userid, created)
VALUES (1, @userid, CURRENT_TIMESTAMP), (3, @userid, CURRENT_TIMESTAMP)
END
I assume it's because of the 2005 vs 2008 differences, but can't figure out what exactly is wrong.
trg_issues_update?VALUES (1, @userid, CURRENT_TIMESTAMP), (3, @userid, CURRENT_TIMESTAMP)2005 doesn't support theVALUES(etc), (etc)For that line, use either multipleINSERTstatements orSELECTwithUNION ALL