SQLExecQuery link database tables

MPullen

New Member
Joined
Apr 8, 2002
Messages
13
I've trying to retrieve data from our database using SQLExecQuery.
I'm having trouble with the formula to link tables together.
So far I've tried as follows, but it doesn't work:
SQLExecQuery DB, "SELECT CLIENTS.NAME, CLIENTS.TEL_1, LEASES.START_DATE FROM ONSETC_MERGED_CLIENTS INNER JOIN ONSETC_MERGED_LEASES ON ONSETC_MERGED_CLIENTS.CLIENT_ID = ONSETC_MERGED_LEASES.CLIENT_ID WHERE LEASES.LEASE_ID = '1234'"

I'm not sure on the INNER JOIN part.
Is this the correct formula?

Any help would be much appricated.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I've just tried a different formula, but still no success!
SQLExecQuery DB, "SELECT CLIENTS.NAME, CLIENTS.TEL_1, LEASES.START_DATE FROM ONSETC_MERGED_CLIENTS CLIENTS, ONSETC_MERGED_LEASES LEASES WHERE LEASES.CLIENT_ID = CLIENTS.CLIENT_ID AND LEASES.LEASE_ID = '1234'"

Please help!
 
Upvote 0
DatabaseName = "SELECT CLIENTS.NAME, CLIENTS.TEL_1, LEASES.START_DATE FROM ONSETC_MERGED_CLIENTS INNER JOIN ONSETC_MERGED_LEASES ON ONSETC_MERGED_CLIENTS.CLIENT_ID = ONSETC_MERGED_LEASES.CLIENT_ID WHERE LEASES.LEASE_ID = '1234'"
queryString = _
"SELECT * FROM product.dbf WHERE (product.ON_ORDER<>0)"
myJoin = SQLOpen("DSN=" & DatabaseName)
SQLExecQuery myJoin, queryString
Set output = Worksheets("Sheet1").Range("A1")
SQLRetrieve myJoin, output, , , True
SQLClose myJoin

I cannot test this, but "DatabaseName" may need to be the result of your join within the database product. So, DatabaseName is not a join statement but the table name of the resulting join. You cannot use SQLExec without SQLOpen! Hope this helps? JSW
 
Upvote 0

Forum statistics

Threads
1,214,415
Messages
6,119,375
Members
448,888
Latest member
Arle8907

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top