PDA

View Full Version : Help with SQL Statement


tige247759
07-08-2009, 11:38 AM
I have a results page made with DataAssist. I need to join data from 4 tables in an access database so that the common names get displayed instead of the number relations. Here is my modified SQL Statement:

"SELECT tasktypes.*, tasks.*, projects.*, clients.* FROM ((projects INNER JOIN clients on projects.clientid = clients.clientid) INNER JOIN tasks on projects.projectid = tasks.projectid) INNER JOIN tasks on tasktypes.tasktypeid = tasks.tasktypeid"

It worked fine until I added the 3rd join. Now I get this error:

Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error in JOIN operation.

Can anyone help with this?

PS:

The one that worked fine looked like this:

"SELECT tasks.*, projects.*, clients.* FROM (projects INNER JOIN clients on projects.clientid = clients.clientid) INNER JOIN tasks on projects.projectid = tasks.projectid"

It returned the common name for the client and the project. Now I just want the common name for the task to be in there as well.

Ray Borduin
07-08-2009, 11:46 AM
You join the same table twice!?

INNER JOIN tasks on projects.projectid = tasks.projectid) INNER JOIN tasks on tasktypes.tasktypeid = tasks.tasktypeid"


Notice INNER JOIN tasks appears twice

tige247759
07-08-2009, 12:14 PM
Yup, I know (this is the first time I have ever tried hand coding SQL so I know it sucks)

In the tasks table, I reference a projectid (projects table), a clientid (clients table) and a tasktypeid (tasktypes table). How do I make sure all the id numbers are joined with their counterparts in the other three tables?

Ray Borduin
07-08-2009, 12:24 PM
Instead of:

INNER JOIN tasks on tasktypes.tasktypeid = tasks.tasktypeid

use:

INNER JOIN tasktypes on tasktypes.tasktypeid = tasks.tasktypeid

tige247759
07-08-2009, 12:32 PM
Yes, that worked. I see it clearly now. Now all of the DataAssist server behaviors have a red exclamation mark beside them, but the page is loading correctly and displaying the correct data. Thanks so much for your help.