Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I'm working on an incremental load script and need to obtain the last Primary Key loaded (originates from an identify column in SQL).
In the below script I can not get Max(PriKeyItem) to return any results into the vMaxKey variable. If I change Max to Count results are obtained.
Item:
LOAD *
FROM
MaxPriKey:
LOAD Max('PriKeyItem') AS "maxPK" Resident Item;
LET vMaxKey = FieldValue('maxPK',1);
//LET vMaxKey=peek('maxPK',-1,'MaxPriKey');
Thanks in advance for any suggestions -
Brett
TableName:
LOAD *
FROM
MaxPriKey:
LOAD Max(PriKeyItem) AS maxPK Resident TableName;
LET vMaxKey = Peek('maxPK',0,'MaxPriKey');
dont use single quotes in max function otherwise it will take it as text and max will not work use below
Item:
LOAD *
FROM
MaxPriKey:
LOAD Max(PriKeyItem) AS "maxPK" Resident Item;
LET vMaxKey = FieldValue('maxPK',1);
//LET vMaxKey=peek('maxPK',-1,'MaxPriKey');
hope this helps
Thanks guys. I could have sworn the count function worked with the single quotes (and returned a value > 1) but maybe not.
if your primary key is in string format then use the following
LOAD Maxstring(PriKeyItem) AS "maxPK" Resident Item;
Use distinct for the second table, you could be getting more than one value for Max(PriKeyItem)
TableName:
LOAD *
FROM
MaxPriKey:
NoConcatenate
LOAD Distinct Max(PriKeyItem) AS maxPK Resident TableName;
LET vMaxKey = Peek('maxPK');
hope this helps.