BookmarkSubscribe
Choose Language Hide Translation Bar
EDW
EDW
New Contributor

Selecting Data from Different Tables

I have two data tables, dt1 and dt2, and I am trying to use the function, "For Each Row", to parse through dt1, then within that loop evaluate corresponding data in dt2.In order to make sure a line of code is grabbing data from the right table, do I have to precede it with "Current Data Table (dt1 / dt2)" or the send operator, "<<"? Let me provide a sample block of code and allow you to tweak as necessary.

row_count = 1;
For Each Row (
	item_of_interest = dt1[row_count,1]; //Grab the value in the first column
	dt2 << If ( Contains ( dt2[0,1], item_of_interest), //Look through column 1 in dt2 for that specified value in dt1
		Write("Yes\!n"),
		Write("No\!n");
	);
	row_count++;
);

Thank you!

 

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Selecting Data from Different Tables

Here is the syntax of how I typically do what you are looking for:

Names default to here(1);
dt1=data table(?????);
dt2=data table(?????);

For( i = 1, i <= N Rows( dt1 ), i++,
	item_of_interest = Column( dt1, 1 )[i]; //Grab the value in the first column
	theRows = dt2 << get rows where( Column( dt1, 1 ) == item_of_interest );
	If( N Rows( theRows ) > 0, //Look through column 1 in dt2 for that specified value in dt1
		Write( "Yes\!n" )
	,
		Write( "No\!n" )
	);
);
Jim
1 REPLY 1
txnelson
Super User

Re: Selecting Data from Different Tables

Here is the syntax of how I typically do what you are looking for:

Names default to here(1);
dt1=data table(?????);
dt2=data table(?????);

For( i = 1, i <= N Rows( dt1 ), i++,
	item_of_interest = Column( dt1, 1 )[i]; //Grab the value in the first column
	theRows = dt2 << get rows where( Column( dt1, 1 ) == item_of_interest );
	If( N Rows( theRows ) > 0, //Look through column 1 in dt2 for that specified value in dt1
		Write( "Yes\!n" )
	,
		Write( "No\!n" )
	);
);
Jim