Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Independent validation for trusted, AI-ready data integration. See why IDC named Qlik a Leader: Read the Excerpt!
cancel
Showing results for 
Search instead for 
Did you mean: 
cramkumar86
Contributor III
Contributor III

To store a variable's value in a table

As you could see below, I am trying to store a variable's value in a table when its length is greater than 0. Once the values are stored in a field, each value has to be passed to the SQL statement using a FOR loop. 

The variable 'vMonthName' doesnt seem to be showing anything. it shows NULL. Could you please help?

SET vTranMonth = '2023-01-31', '2023-03-31';

If Len(trim('$(vTranMonth)'))>0 then
TmpTable:
Load '$(vTranMonth)' as TranMonth;

For i = 1 to FieldValueCount('TranMonth')
Let vMonthName = Date(FieldValue('TranMonth', $(i)), 'YYYY-MM-DD');


SLDataLoad:

LOAD col1, col2;

SQL SELECT 'col1', 'col2' from tablename where dateval=$(vMonthName);

Next i

Else

End If

Labels (4)
1 Reply
Aurelien_Martinez
Partner - Specialist II
Partner - Specialist II

Hi,

 

You can try a script like this :

 

SET vTranMonth = 2023-01-31, 2023-03-31;

If Len(trim('$(vTranMonth)'))>0 then

TmpTable:
Load
Date#(Trim(SubField('$(vTranMonth)', ',')), 'YYYY-MM-DD') as TranMonth
AutoGenerate(1)
;

For Each vMonthName in FieldValueList('TranMonth')
// Let vMonthName = Date(FieldValue('TranMonth', $(i)), 'YYYY-MM-DD');

Trace SELECT 'col1', 'col2' from tablename where dateval=$(vMonthName);


Next vMonthName

Else

End If

Help users find answers! Don't forget to mark a solution that worked for you!