Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I would like to find the highest possible ID in the table of the incremental load script in the document table
In the Document_Header table, I see the largest ID but can not be saved as a variable.
vMaxDokID is empty
What's wrong with me?
Document_Header:
SQL SELECT
max(ID)
FROM "DOCUMENT_HEADER"
WHERE DOCUMENTDATE <=$(alguskpv_SQL)
;
LET vMaxDokID= Peek('MaxDokID',0, 'MinMax');
Try this?
Document_Header:
Load
*
Inline [
ID
0
1
2
3
4
5
6
];
LEFT JOIN (Document_Header)
Document_ID:
Load
max(ID) as MaxID
Resident Document_Header;
LET vMaxDokID = Peek('MaxID', 0 , 'Document_Header');
Drop Table Document_Header;
IF you do not use the JOIN it will create two tables 1, Document_Header and 2, Document_ID. So when the variable is reading from Document_Header there is no field MaxID hence no data in it. You can also try like:
Document_Header:
Load
*
Inline [
ID
0
1
2
3
4
5
6
];
//LEFT JOIN (Document_Header)
Document_ID:
Load
max(ID) as MaxID
Resident Document_Header;
LET vMaxID = Peek('MaxID', 0 , 'Document_ID');
Drop Table Document_Header, Document_ID;
The below code will retain the maxid in the variable vMaxDokID. Hope this helps.
Document_Header:
Load
Max(ID) as MaxID;
Load
*
Inline [
ID
0
1
2
3
4
5
6
];
LET vMaxDokID = Peek('MaxID');
Hi Rein, The first parameter of Peek is the field name, second the index (starting at zero), and 3rd the table name, so, if you don't assign an alias to max(ID) the field will be called 'max(ID)' -or 'MAX(ID)'?- and the table is 'Document_Header', so based on the script in the first post:
Document_Header:
SQL SELECT
max(ID)
FROM "DOCUMENT_HEADER"
WHERE DOCUMENTDATE <=$(alguskpv_SQL)
;
LET vMaxDokID= Peek('max(ID)',0, 'Document_Header');
Do this step by step.
It's fairly easy to debug this, if you do it step-by-step.