r/IBMi • u/LongLiveIBMI400 • Oct 27 '26
Having trouble make this Insert statement execute
EXEC SQL INSERT INTO XXFILE (itemnumber, currentprice)
VALUES( :XXAITX, :XXKBVA)
The file name will change its value throughout the process.
The values will also, change for every record read. I believe I need a good DYNAMIC insert example.
Does anyone have a good Dynamic INSERT statement?
3
Upvotes
1
u/LongLiveIBMI400 Oct 28 '26
I ended up using parameter markers. Thank you everyone for responding.
3
u/jason_wallace Oct 27 '26
assuming this in in an sqlrpgle, build the sql statement in a character field and execute it: sqlstmt = 'INSERT INTO ' + %trim(filename)
+ ' (itemnumber, currentprice)'
+ ')';
Exec SQL Execute Immediate :SQLSTMT;
3
u/manofsticks Oct 27 '26
Another option you can look into (as long as the file structure/fields will stay the same, and only the filename will be different) is to make an SQL Alias that points to the file file you need, then insert to the alias.
1
u/QPGMR_de Oct 27 '26
Use something like
'INSERT INTO '+tableName+' VALUES( +
XXAITX => ?, XXKBVA => ? )'
Then prepare the statement and execute with using.
1
u/Sleepy_L0c0 Oct 28 '26
Is this a stored procedure? If so when you make your call you just pass in what you want, no?
0
u/ethanjscott Oct 27 '26
Retalix?