I have been able to do this in the past using sprintf() to create an sql statement based on a list of user selected id's. But now I am wanting to make an sql statement based on a user selected list of multiple fields, from multiple tables, and I'm at a loss.
I have a database with multiple tables:
TBL1
Date Program Name Type height width
5/22 E7 Square angle 5 5
5/22 H9 Circle smooth 4 4
9/9 E7 Circle smooth 7 7
10/10 R8 Triangle angle 10 5
TBL2
Date Program Name Value1 Value2
5/22 E7 Square 5 2.4
5/22 H9 Circle 10 43
9/9 E7 Circle 3.2 9
10/10 R8 Triangle 999 1
TBL3
Type 1 2 3
angle a g h
smooth b c d
And I have a dataframe of rows I want to get from the database
df
Date Program Name
5/22 E7 Square
9/9 E7 Circle
10/10 R8 Triangle
I need to dynamically generate an SQL statement for gathering the data that I need. So I would need to get the Date, Program, Name, Type, Value1, and Value2 for every Date, Program, and Name in my df.
I was trying to figure out if sqlinterpolate could handle this, but it doesn't seem like it can?
I would join TBL1 and TBL3 WHERE Type=Type, and then join the VALUES from TBL2 all only for the rows where Date, Program, and Name matched my df.
Desired output from the sql return:
Date Program Name Type 1 2 3 Value1 Value2
5/22 E7 Square angle a g h 5 2.4
9/9 E7 Circle smooth b c d 3.2 9
10/10 R8 Triangle angle a g h 999 1
Thoughts?