Dynamic Columns in SQLNode

 7 Replies
 0 Subscribed to this topic
 52 Subscribed to this forum
Sort:
Author
Messages
d
Basic Member Send Private Message
Posts: 4
Basic Member
Is there a way to loop through the results of a SQL query without having to specify the actual name of the column? For Example;

If there is a SQLQuery node that returns a bunch of results. I know inside of the SQLNode loop I can do something like:
SQLQuery3040_1
SQLQuery3040_2
SQLQuery3040_3
To get the data returned in column 1,2,3

but as soon as I try to build the SQLQuery counter
SQLQuery3040_+testCounter

I can't seam to get the data out of the SQLQuery Node.

My Code (Note that this SQL query node builds out the CurrentRecordType and Date to use correctly:
SQL QueryNode:
select <.!CurrentRecordType>,HRORGANIZATION,* from <.!CurrentRecordType> where USTIMESTAMP >= '<.!DateToUseShort>' and EMPLOYEE = 90103397

then if I assign a string variable with SQLQuery3040_2 for example the HROrganization from the query is returned... But if I try  testCounter =2 then  SQLQuery3040_+testCounter i get nothing





Kyle Jorgensen
Veteran Member Send Private Message
Posts: 122
Veteran Member
Data returned from a SQL Query node can be referenced in these manners:
[code] NODENAME_ NODENAME_ _ NODENAME_ NODENAME__ [/code]
d
Basic Member Send Private Message
Posts: 4
Basic Member
Thanks Kyle,

What I am trying to do is reference 
NODENAME_<COLUMN_NUM>

but where is dynamic. For example if testCounter=1 SQLQuery3040_1 works, but i want to make the _1 be dynamic, what would be the syntax? I've tried SQLQuery3040_testCounter SQLQuery3040_<.!testCounter> 'SQLQuery3040_'+testCounter and countless others

Woozy
Veteran Member Send Private Message
Posts: 709
Veteran Member

It sounds like you are trying to use a single variable as a reference, and loop through all SQL node output fields using that one reference?  Something like this:

ref_var = 1;
while (ref_var <= 20) {
   save_var = SQLNode100_ref_var;
   ...
   do stuff with savevar value
   ...
   ref_var++;
}

Unfortunately, I don't think you can reference the node output values using variables this way - as least I've never found a way to do it.  I'd love for someone to prove me wrong...

Kelly Meade
J. R. Simplot Company
Boise, ID
d
Basic Member Send Private Message
Posts: 4
Basic Member
Yes woozy that is what i am looking for.

Sad news

Back to the drawing board i guess
Woozy
Veteran Member Send Private Message
Posts: 709
Veteran Member

Do you have a huge number of fields being returned?  What exactly are you trying to do?  Maybe there is another way.

I could envision changing your SQL query to output a delimited file, and then use the DataIterator node to parse it for processing. 

You could also build a delimited file from your SQL using JavaScript, but you'd have to allow for the maximum number of fields that could be returned.  Then you could follow that with a data iterator.

if ((SQLNode1000_1 !== "undefined" && SQLNode1000_1.length > 0)) {
    csv_string = SQLNode1000_1;
    csv_string += ",";
}
if ((SQLNode1000_2 !== "undefined" && SQLNode1000_2.length > 0)) {
    csv_string = SQLNode1000_2;
    csv_string += ",";
}
...
etc.


Kelly Meade
J. R. Simplot Company
Boise, ID
Woozy
Veteran Member Send Private Message
Posts: 709
Veteran Member
Ha HA!  Check THIS out...

Attached is a sample flow (it's in IPA format - but you'll need to change the extension from ".txt to ".lpd"). 

If you are still on PFI, attached is a PDF with the node details.

Maybe something like this would work for you?
Attachments
Kelly Meade
J. R. Simplot Company
Boise, ID
d
Basic Member Send Private Message
Posts: 4
Basic Member
Thank you Woozy, I'll play with this and see if I can get something like it to work. We range from 30 to 100 columns processed this way so it will be a little messy. but when is lpd code ever pretty?

Still holding out that someone will know a way to reference to SQL Nodes the other way.