Forum.
I am working with IBM System i Version 7.1.
I am having issues in the source code with the following merge statement so I copied it over to the database client to utilize the "Run SQL Scripts" functionality.
Rather than replacing the coded in @Variables in the statement I wanted to declare local variables so that I could test the statement as is.
The added the following 'declare and set' lines and I get the following error:
declare @groupId smallint
set @groupId = 99
declare @groupName varchar(40)
set @groupName = 'Sam'
declare @groupId smallint
SQL State: 42601
Vendor Code: -104
Message: [SQL0104] Token SMALLINT was not valid. Valid tokens: DYNAMIC SENSITIVE ASENSITIVE INSENSITIVE. Cause . . . . . : A syntax error was detected at token SMALLINT. Token SMALLINT is not a valid token. A partial list of valid tokens is DYNAMIC SENSITIVE ASENSITIVE INSENSITIVE. This list assumes that the statement is correct up to the token. The error may be earlier in the statement, but the syntax of the statement appears to be valid up to this point. Recovery . . . : Do one or more of the following and try the request again: -- Verify the SQL statement in the area of the token SMALLINT. Correct the statement. The error could be a missing comma or quotation mark, it could be a misspelled word, or it could be related to the order of clauses. -- If the error token is , correct the SQL statement because it does not end with a valid clause.Processing ended because the highlighted statement did not complete >successfully
I have tried adding semicolons to the end of each line and begin and end statements and still no success.
Below is the whole statement I am trying to execute:
declare @groupId smallint
set @groupId = 99
declare @groupName varchar(40)
set @groupName = 'Sam'
merge into database.table as t
using ( values( cast(@groupId as smallint)
,cast(@groupName as varchar(40))
))
as caz( group_id
, group_name
)
on t.group_id = caz.group_id
when matched then update
set t.group_name = caz.group_name
when not matched then
insert ( group_id
, group_name
)
values (caz.group_id
, caz.group_name
);
Any help is appreciated.
Please let me know if I may provide anymore information.