Check for a string in a file before joining tables.I open 2 excel files.I am trying to join tables only if the the list contains choice.How do I achieve this?
//Accept Product input from user and save it in a text file
R = Open("Choice.txt",
Labels(0),
Columns(
C = Character(12);
)
);
Choice = {};
Choice = R:C[1];
//Open master data list
U = Open("Volume.csv","invisible");
T = Open("List.csv","invisible");
dt = Current data table();
Column_List = dt << Get Column Names("String");
for(i = 1, i<= NItems(Column_List),i++,
if(contains(Choice,Column_List[i]),
U = Data Table( "Volume" ) <<
Join(
With( Data Table( "List" ) ),
Merge Same Name Columns,
By Matching Columns( :number = :number ),
Drop multiples( 0, 0 ),
Include Nonmatches( 0, 0 ),
Preserve main table order( 1 ),
Output Table( "Joined_With_List" )
);
);
);
Re: Check for a string in a file before joining tables.Works perfectly!
Thanks a ton
Re: Check for a string in a file before joining tables.Is this what you are looking for? If not, then I am not getting what you are after
Names Default To Here( 1 );
// Open comma separated files
dtList = Open( "<THE path="" to="" the="" list="" file="">\list.csv" );
dtVolume = Open( "<THE path="" to="" the="" volume="" file="">\volume.csv" );
// Read in the choice value
choice = Load Text File( "C:\Users\txjim\Documents\choice.txt" );
// Find out if choice is in the List data table and if so,
// join the tables. If not, then set the Volume data table
// to be the processing data table.
If( Contains( dtList:Company << get values, choice ),
dtProcess = dtVolume << Join(
With( dtList ),
Merge Same Name Columns,
Match Flag( 0 ),
By Matching Columns( :Product Type = :Product Type ),
Drop multiples( 0, 0 ),
Include Nonmatches( 0, 0 ),
Preserve main table order( 1 ),
Output Table( "Process" )
),
dtProcess = dtVolume
);</THE></THE>
Re: Check for a string in a file before joining tables.Thanks for the response.I did not explain the issue well.Sorry about that.
Volume file is dynamic.If the choice variable is present in the list file,I need to join Volume and List tables.If not I use the Volume table as is for further manipulations.I have attached all 3 files.Stuck with this problem for quite a while.
Any help appreciated.
Re: Check for a string in a file before joining tables.I think the below script will get you closer to what you want. I don't have the format of your "Choice" variable, so I could not really test the code, but I think it will provide you with a method that will get you what you want
//Accept Product input from user and save it in a text file
R = Open( "Choice.txt", Labels( 0 ), Columns( C = Character( 12 ) ) );
Choice = {};
Choice = R:C[1];
//Open master data list
U = Open( "Volume.csv", "invisible" );
T = Open( "List.csv", "invisible" );
// Delete columns from the List data table that are not
// found in the Choice memory variable
Column_List = T << Get Column Names( "String" );
For( i = 1, i <= N Items( Column_List ), i++,
If( Contains( Choice, Column_List[i] ) == 0,
T << Delete Columns( Column_Names[i] )
)
);
newU = U << Join(
With( T ),
Merge Same Name Columns,
By Matching Columns( :number = :number ),
Drop multiples( 0, 0 ),
Include Nonmatches( 0, 0 ),
Preserve main table order( 1 ),
Output Table( "Joined_With_List" )
);