Good morning,
I’m trying to link a table in Database 1 to a table in Database 2.
DB1 has Table1:
- Phone_Number
- Active (“y” or “n”)
DB2 has Table2:
- Phone_Number
- Subscriber Information
I need all info from DB2.Table2 where the phone number is active in DB1.Table1.
Creating a grid with the wizard doesn’t allow (or I can’t find a way) to link across the two databases. The SQL builder doesn’t seem to allow this either.
So after multiple attempts, I thought it may be easier to just copy DB1.Table1 to a new table in DB2 each time the grid is called. Not pretty I know, but both of these databases are only updated once a day and we won’t be accessing this grid more than a few times a week.
So in “OnScriptInit” in my grid that’s just tied to DB2.Table2, I have:
sc_exec_sql (“CREATE TABLE SubCopy SELECT Phone_Number, Active FROM DB1.Table1”);
and it fails with:
Error while accessing the database:
ERROR: syntax error at or near “SELECT” LINE 1: CREATE TABLE SubCopy SELECT Phone, … ^
CREATE TABLE SubCopy SELECT Phone_Number, Active FROM DB1.Table1
So I thought maybe it was something to do with trying to connect to the other database, so as a baby step, I tried to just create a table:
sc_exec_sql (“CREATE TABLE SubCopy”);
and it fails with:
Error while accessing the database:
ERROR: syntax error at end of input LINE 1: CREATE TABLE SubCopy ^
CREATE TABLE SubCopy
So I must be missing something here. Maybe there’s a better way to do this? I’m still very new at this and would appreciate any available help with joining tables across two databases.
Thanks in advance!
Mark.