Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
jasonwills
Contributor II
Contributor II

Looping through SQL data

Hi All,

after some help here, as i'm not sure where to start - and i hope i explain it properly too 😉

I have a SQL data source, and it represents a tree style structure, something like:

IDSerialNumberParentSerialNumberName
    
1123454444

Test 1

2678923333

Test 2

3776454444

Test 3

44444 

Parent 1

53333 

Parent 2

 

So, looking at the sample data above  there are two "parents" with 1 having 2 sub entries and the second only having 1.

Hopefully that is the structure explained OK.

I can import the data OK, however i am wanting to do other things with the data, So, my question is, what syntax do i need to loop through each record that has a "ParentSerialNumber" of 4444 for instance.

Thanks for any help

Jason

Labels (2)
3 Replies
jasonwills
Contributor II
Contributor II
Author

Hi All, just wanting to expand a little to help explain.

i have a SQL table - i am importing it through the script as so:

LoadIntoList:

Sql SELECT
t.SerialNumber as SerialNumber
FROM
tableName as t
WHERE t.ParentSerialNumber= '4444';

So this will give me a list of all records who have a ParentSerialNumber of 4444.

What i'd then like to do is to run another SQL statement to import other records from a different table, but looping through and using each 'SerialNumber' obtained from the previous statement as a variable.

Cheers

Jason

Nadi_Clarke
Contributor II
Contributor II

Have you used HierarchyBelongsTo for all hierarhy in Qlik already?

1) temp1:

HierarchyBelongsTo (NodeID, AncestorID, NodeName, AncestorID, AncestorName, DepthDiff)

LOAD * LoadIntoList

2) Leave only ISNULL(AncestorName) = 1

3) for each i in FieldValueList (NodeID)

 

jasonwills
Contributor II
Contributor II
Author

hi @Nadi_Clarke ,

i wasn't even aware of this - thanks for the pointers, i will investigate and have a look.

Regards

Jason