Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
alutz54
Contributor III
Contributor III

Convert a String to a List of Strings

I have a string that looks like "MAY,APR,MAR,FEB,JAN,DEC" but I want it to be a list of strings separated on the comma so that I can pass the list as a variable into a future SQL SELECT.

Labels (1)
1 Solution

Accepted Solutions
MarcoWedel

Are you looking for something like this?

 

SET string = '"MAY,APR,MAR,FEB,JAN,DEC"';
LET strings = Replace(string,',','","');

 

MarcoWedel_0-1683908513526.png

 

View solution in original post

7 Replies
alutz54
Contributor III
Contributor III
Author

 Do I have to create a table and do a Load SubField(Field,',') as [List of Strings]?

Kushal_Chawda

@alutz54  you have string but how it is stored? Is it stored in one of the column in table? If so how does column value looks like. Do you want to create a list from that column?

alutz54
Contributor III
Contributor III
Author

Sorry, I am creating a variable of the previous 6 fiscal periods so that I can use that variable to filter a future SQL SELECT. So the string is stored as a variable that I created is stored as a variable.

MarcoWedel

Are you looking for something like this?

 

SET string = '"MAY,APR,MAR,FEB,JAN,DEC"';
LET strings = Replace(string,',','","');

 

MarcoWedel_0-1683908513526.png

 

alutz54
Contributor III
Contributor III
Author

Yes! The Replace function is exactly what I was looking for. Thank you, I am very new to Qlik Sense. If I may ask one more question, I have a SQL SELECT later on in this code where I am using the above list of strings as a filter in a WHERE clause. How would I reference the strings variable? The $(strings) format is not working.

Kushal_Chawda

@alutz54  If you are going to use this string in SQL query not sure if double code works so instead try single quotes

SET string = '"MAY,APR,MAR,FEB,JAN,DEC"';
LET strings = replace(Replace(string,',',''','''),'"',chr(39));
Chanty4u
MVP
MVP

Try this 

LET string = 'MAY,APR,MAR,FEB,JAN,DEC';

LET strings = Chr(39) & Replace(string, ',', Chr(39) & ',' & Chr(39)) & Chr(39);

LOAD *

FROM YourTable

WHERE Month IN ($(strings));