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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Cycle FOR/WHILE/LOOP ETC.

Hi to everyone...

I have this problem about loops:

there is a long string that i have to divide in different parts but i'd like to use a cycle instead of rewriting many times the same code, changing the values in the SUBTRING FUNCTION!

this is my code:

SET Y= 9

FOR A=1 TO 10

TABLE_1:

SELECT SUBSTR(XXX, Y, 15) AS COLUMN_A

FROM TAB

LET Y=Y+15

NEXT

I'm glad of receive suggestions!!!

i'm really new

thanks to everyone!!

1 Solution

Accepted Solutions
Not applicable
Author

I could reach the aim

but with MID and LOAD it doesnt work!!

this is the perfect result i got:

SET Y=9;

FOR A=1 TO 10

SELECT

SUBTR(TAB.F1, $(Y), 15)

FROM TAB

/*WHERE XXX*/;

LET Y=$(Y)+15;

NEXT

View solution in original post

7 Replies
Vegar
MVP
MVP

You missed some semicolons and use the wrong function(?)

SET Y= 9;

FOR A=1 TO 10

     TABLE_1:

     LOAD

          mid(F1, $(Y), 15) AS COLUMN_A

     RESIDENT

          TAB;

     LET Y= $(Y) + 15;

NEXT

CELAMBARASAN
Partner - Champion
Partner - Champion

Is the dividing the strings only depends upon the size? because you specified 15?

any delimiters between the parts?

diegofcaivano
Partner - Creator
Partner - Creator

Hi.

I'm not sure what you are trying to accomplish, but you must place the variables inside $() to be evaluated.

SET Y=9;

FOR A=1 TO 10

     LOAD

          MID(X_FIELD, $(Y), 15) AS COLUMN_$(A)

     FROM X.QVD (qvd);

     LET Y=$(Y)+15;

NEXT

Hope it helps.

Not applicable
Author

because every 15 characters there are a field i want:

ex:

123456789pizza_______maccheroni_____mafia__________berlusconi_____ etc...

i would like

column_1        column_2           column _3            column_4              column_5

pizza              maccheroni         mafia                   berlusconi             ...........

Vegar
MVP
MVP

Take a look at this qvw file using Join.

TAB:

LOAD * INLINE [

    F1

    12345678pizza__________maccheroni_____mafia__________berlusca_______ etc..

];

SET Y= 9;

FOR A=1 TO 5

join LOAD

F1,

MID(F1, $(Y), 15) AS COLUMN_$(A)

RESIDENT TAB;

LET Y= $(Y) + 15;

NEXT

drop field F1;

Message was edited by: Vegar Arntsen, Lie Added the actual script I used in qvw.

Not applicable
Author

1)i feel stupid

2)your file is really good. but in my case the string that u call "F1" is in the database (in the table TAB):

THIS SHOULD BE: MID(TAB.F1, $(Y), 15))

so i'm not able to traslate ur code in relation to my aims.

thanks!!

Not applicable
Author

I could reach the aim

but with MID and LOAD it doesnt work!!

this is the perfect result i got:

SET Y=9;

FOR A=1 TO 10

SELECT

SUBTR(TAB.F1, $(Y), 15)

FROM TAB

/*WHERE XXX*/;

LET Y=$(Y)+15;

NEXT