Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi Guys ,
i have very urgent requirement on looping concept .
Below is my scenario .
Everytime Year column should concatenate with P1 to P13 .
So instead of writing it 13 times can i have in loop .
Please suggest me .
Thanks in advance
load distinct
EmpKey ,
AutonumberHash128(DeptKey) as DepKey,
Year&'P01' As YearPeriod
Resident Emp ;
concatnate
load distinct
EmpKey ,
AutonumberHash128(DeptKey) as DepKey,
Year&'P02' As YearPeriod
Resident Emp ;
concatnate
load distinct
EmpKey ,
AutonumberHash128(DeptKey) as DepKey,
Year&'P03' As YearPeriod
Resident Emp ;
May be like this:
Table:
LOAD 0 as Dummy
AutoGenerate 0;
For i = 1 to 13
Concatenate (Table)
LOAD DISTINCT
EmpKey,
AutonumberHash128(DeptKey) as DepKey,
Year&'P'&Num($(i), '00') As YearPeriod
Resident Emp ;
NEXT
DROP Field Dummy;
How about this?
LOAD DISTINCT
EmpKey
,autonumberhash128(DeptKey) as DepKey
,Year&'P'&num(iterno(),'00') as YearPeriod
RESIDENT Emp
WHILE iterno()<=13
;
Or this?
LOAD DISTINCT
EmpKey
,autonumberhash128(DeptKey) as DepKey
,Year&'P'&subfield('01,02,03,04,05,06,07,08,09,10,11,12,13',',') as YearPeriod
RESIDENT Emp
;
Perhaps silly when it's just 01 - 13, but useful if it was some other sort of distinct values.
John, I guess IterNo() is more optimal method than subfield function method.
I would guess so as well. The other method would be more if we were building values like 2016 Apple, 2016 Grape, and 2016 Banana.
Thank you John , its working