Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all .
I have a table from which I need to load a fields. For example table |I have like this one:.
Num | A | B | C | F1 | F2 | FN |
1 | 22 | 27 | 24 | u | ||
2 | 22 | 27 | 24 | u | u | |
3 | 22 | 23 | 25 | u |
From this tableI need to Load field "Num", all fields starting with F and A or B or C.
Also I have an internal parameter vParam that may be equal "A" or "B" or "Null()". In case if vParam = A, than I should load field "Num", field "A" field (and not B or C) and all fields starting with F, if vParam = B, then "Num", field B,all fields starting with F . And if vParam = Null() then loading "Num", C, all fields starting with F .
Please, help me to understood how I may do Load from file with conditions I've described?
P.S.
If vParam = A resulted table should be like
Num | A | F1 | F2 | FN |
1 | 22 | u | ||
2 | 22 | u | u | |
3 | 22 | u |
If vParam = B resulted table should be like
Num | B | F1 | F2 | FN |
1 | 27 | u | ||
2 | 27 | u | u | |
3 | 23 | u |
If vParam = C resulted table should be like
Num | C | F1 | F2 | FN |
1 | 24 | u | ||
2 | 24 | u | u | |
3 | 25 | u |
Hi @Peony ,
Thanks for the update question. I think I've got your answer.
// Create table with paramater values to loop over
ParamTable:
LOAD * INLINE [
ParamField
A
B
C
];
// Set basetable
BaseTable:
LOAD * INLINE [
Num, A, B, C, F1, F2, FN
1, 22, 27, 24, u, , ,
2, 22, 27, 24, , u, u,
3, 22, 23, 25, , , u,
];
// Set loop
FOR i = 0 TO NUM(NOOFROWS('ParamTable')-1);
// Set variable with paramater value
LET vParam = PEEK('ParamField',$(i),'ParamTable');
Table_A:
LOAD
Num,
'$(vParam)' AS ParamValue, // Get the paramater value (A, B or C) to see which field is fetched
$(vParam) AS ParamResult, // Get the field value from field A, B, or C
F1,
F2,
FN
RESIDENT BaseTable;
NEXT i;
DROP TABLE BaseTable,ParamTable;
This results in the following table.
Num | ParamResult | ParamValue | F1 | F2 | FN |
1 | 22 | A | u | ||
3 | 22 | A | u | ||
2 | 22 | A | u | u | |
1 | 27 | B | u | ||
3 | 23 | B | u | ||
2 | 27 | B | u | u | |
1 | 24 | C | u | ||
3 | 25 | C | u | ||
2 | 24 | C | u | u |
Hi @Peony ,
It isn't really clear what you want to do. But I think I can help you a bit further by directing you to a crosstable load.
CROSSTABLE (Character,Number) LOAD * INLINE [
Num, A, B, C, F1, F2, FN
1, 22, 27, 24, u, , ,
2, 22, 27, 24, , u, u,
3, 22, 23, 25, , , u,
];
In that case the result will be like this. And that should make it more easy for you to make your selections.
Num | Character | Number |
1 | F2 | |
1 | FN | |
2 | F1 | |
3 | F1 | |
3 | F2 | |
1 | F1 | u |
2 | F2 | u |
2 | FN | u |
3 | FN | u |
1 | A | 22 |
2 | A | 22 |
3 | A | 22 |
3 | B | 23 |
1 | C | 24 |
2 | C | 24 |
3 | C | 25 |
1 | B | 27 |
2 | B | 27 |
Hi @avkeep01 . Thank you for trying to help me.
Unfortunately, your solution is not the result I need. I added some changes to the my post. Hopefully now it’s clearer what I'm looking for as a result.
Hi @Peony ,
Thanks for the update question. I think I've got your answer.
// Create table with paramater values to loop over
ParamTable:
LOAD * INLINE [
ParamField
A
B
C
];
// Set basetable
BaseTable:
LOAD * INLINE [
Num, A, B, C, F1, F2, FN
1, 22, 27, 24, u, , ,
2, 22, 27, 24, , u, u,
3, 22, 23, 25, , , u,
];
// Set loop
FOR i = 0 TO NUM(NOOFROWS('ParamTable')-1);
// Set variable with paramater value
LET vParam = PEEK('ParamField',$(i),'ParamTable');
Table_A:
LOAD
Num,
'$(vParam)' AS ParamValue, // Get the paramater value (A, B or C) to see which field is fetched
$(vParam) AS ParamResult, // Get the field value from field A, B, or C
F1,
F2,
FN
RESIDENT BaseTable;
NEXT i;
DROP TABLE BaseTable,ParamTable;
This results in the following table.
Num | ParamResult | ParamValue | F1 | F2 | FN |
1 | 22 | A | u | ||
3 | 22 | A | u | ||
2 | 22 | A | u | u | |
1 | 27 | B | u | ||
3 | 23 | B | u | ||
2 | 27 | B | u | u | |
1 | 24 | C | u | ||
3 | 25 | C | u | ||
2 | 24 | C | u | u |
@avkeep01 Yes, you got may idea correct! Thank you for help!