Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
OmarBenSalem

Put all the values of a field into a variable (loop maybe?)

Hi guys, stalwar1

Suppose I have a table containg a field Alert:

load Alert inline [

Alert

alert1

alert2

alert3

];

How to do to store all of the alerts (alert1, alert2 and alert3) into a variable?

the goal is to store all this values ito a database as a final objectif; for this, I want to be able to loop all the alerts one by one, and everytime store one value into the destination column, till all the values are stored.

Hope my question is clear enough?

17 Replies
OmarBenSalem
Author

Yes you can;

see :

alerts:

load Alert inline [

Alert

alert1

alert2

alert3

];

For i = 1 to FieldValueCount('Alert')

     LET vAlert  = FieldValue('Alert', $(i));

Table: 

//LOAD $(vAlert) as alert AutoGenerate 1 ;

load FieldValue('Alert', $(i)) as alert resident alerts; 

STORE  alert FROM Table INTO [lib://OBS/class.txt]

(txt);

NEXT i;

Capture.PNG

But the loop logic (the next i is false)

Capture.PNG

Now when I try your code:

I have this errorCapture.PNG

OmarBenSalem
Author

Thanks, I'm trying to store it in database table, so I need to have each value apart

sunny_talwar

May be DROP Table Table after every loop?

alerts:

load Alert inline [

Alert

alert1

alert2

alert3

];

For i = 1 to FieldValueCount('Alert')

    LET vAlert  = FieldValue('Alert', $(i));

Table:

//LOAD $(vAlert) as alert AutoGenerate 1 ;

load FieldValue('Alert', $(i)) as alert resident alerts;

STORE  alert FROM Table INTO [lib://OBS/class.txt]

(txt);

DROP Table Table;

NEXT i;

OmarBenSalem
Author

Try it like this Sunny ! It works !

alerts:

load Alert inline [

Alert

alert1

alert2

alert3

];

FOR Each a in FieldValueList('Alert')

dim:

let vAlert = a;

LOAD '$(vAlert)'  as Alerts AutoGenerate 1;

Store dim into [lib://OBS/class.txt] (txt);

NEXT a

sunny_talwar

You want to store alert1 alert2 and alert3 in a text file? why loop?

OmarBenSalem
Author

As I told, I want to store all of my alerts into a database; for that, I'll have to loop each value, put into a variable, store it into the database using a procedure and so on; so I had to do it using variables.

I can't directly use the field Alert..

OmarBenSalem
Author

It would be sthing like this:

lib Connect To databaseName;

FOR Each a in FieldValueList('Alert')

let vAlert=a;

sql use databaseName

exec writeBack'$(vAlert)';

next a

sunny_talwar

This worked for me

alerts:

LOAD * INLINE [

    Alert

    alert1

    alert2

    alert3

];

For i = 1 to FieldValueCount('Alert')

    LET vAlert  = FieldValue('Alert', $(i));

Table:

NoConcatenate

LOAD '$(vAlert)' as alert

AutoGenerate 1;

STORE alert FROM Table INTO [class$(i).txt] (txt);

DROP Table Table;

NEXT i;