
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
combining attribute tables after a generic load
Hi I have a generic load script that results in 8 attribute tables Now I would like to join them into one table. I tried joining them but that didn't work,
also I've seen other solutions that refer to the inline[] option instead of using the generic prefix however I have too many lines and don't think I can use the inline option.
I also tried some of the for loop solutions I've seen but also am getting stuck.
generic LOAD
AnswerResultJPA_ID as surveyResponseJPA_ID,
attributes_KEY,
attributes;
[AnswerResultJPA_attributes]:
SELECT "AnswerResultJPA_ID",
attributes,
"attributes_KEY"
FROM SR."db_owner"."AnswerResultJPA_attributes"
;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@danaleota1 and if you try ?
[AnswerResultJPA_attributes]:
LOAD
AnswerResultJPA_ID,attributes_KEY,attributes
;
SELECT "AnswerResultJPA_ID",
attributes,
"attributes_KEY"
FROM SR."db_owner"."AnswerResultJPA_attributes"
;
DATA:
Generic LOAD AnswerResultJPA_ID as surveyResponseJPA_ID,
attributes_KEY, attributes resident AnswerResultJPA_attributes;
CombinedGenericTable:
Load distinct AnswerResultJPA_ID as surveyResponseJPA_ID resident AnswerResultJPA_attributes;
drop table AnswerResultJPA_attributes;
FOR i = NoOfTables()-1 to 0 STEP -1
LET vTable=TableName($(i));
IF WildMatch('$(vTable)', 'DATA.*') THEN
LEFT JOIN ([CombinedGenericTable]) LOAD distinct * RESIDENT [$(vTable)];
DROP TABLE [$(vTable)];
ENDIF
NEXT i
Taoufiq ZARRA
"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "
(you can mark up to 3 "solutions") 😉

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was able to join the attribute tables using a similar script as yours-- thank you! But what if I have several tables I need to do this on. How would I adjust the new for loop for a second table.
generic LOAD SurveyResponseJPA_ID,
attributes_KEY,
attributes;
[tbl_survey_attributes]:
SELECT "SurveyResponseJPA_ID",
attributes,
"attributes_KEY"
FROM SurveyResults."db_owner"."tbl_survey_attributes";
Let vNoOfTables = NoOfTables();
For cnt = 0 to $(vNoOfTables)-1
Let vTableName = TableName($(cnt));
TableList:
LOAD
'$(vTableName)' as TableName
Autogenerate(1);
Next
Let vFirstTableName = Peek('TableName',0,'TableList');
Let vNumberOfRows = NoOfRows('TableList')-1;
For cnt =1 to $(vNumberOfRows)
Let vTableName =Peek('TableName',$(cnt),'TableList');
Join($(vFirstTableName))
LOAD * Resident $(vTableName);
DROP Table $(vTableName);
Next
Rename Table $(vFirstTableName) to surveyAttributes;
//now I need to do the same thing to the next table but I need to adjust the NoOfTables() and the //count
generic LOAD SurveyResponseJPA_ID,
contextData_KEY,
contextData;
[tbl_survey_context]:
SELECT "SurveyResponseJPA_ID",
contextData,
"contextData_KEY"
FROM SurveyResults."db_owner"."tbl_survey_context";
//I did '-23' because the first table had 23 attributes
Let vNoOfTables1 = NoOfTables()-23;
// I need this for loop to start at the the second table: tbl_survey_context
For cnt1 = 23 to $(vNoOfTables)-24
Let vTableName1 = TableName($(cnt1));
TableList1:
LOAD
'$(vTableName1)' as TableName1
Autogenerate(1);
Next
Let vFirstTableName1 = Peek('TableName1',0,'TableList1');
Let vNumberOfRows1 = NoOfRows('TableList1')-1;
For cnt =1 to $(vNumberOfRows1)
Let vTableName1 =Peek('TableName1',$(cnt1),'TableList1');
Join($(vFirstTableName1))
LOAD * Resident $(vTableName1);
DROP Table $(vTableName1);
Next
Rename Table $(vFirstTableName1) to surveyContext;
