Diagnose my SQL problem...

Soldato
Joined
15 Feb 2003
Posts
8,327
Location
NJ/NY, USA
Hi all, I'm having a little problem with a pretty basic database query.

I'm using embedded Visual Basic and a Pocket Access Database, which may confuse things as it doesn't support loads of stuff, but ignoring that for the time being, how does the following look....

SQL = "SELECT Cardio.CardioName, Cardio.Time, Cardio.Distance, Cardio.Cals FROM Cardio, Session WHERE Session.UserID = '" & CurrentUser & "' AND Cardio.CardioName = '" & ExName & "' AND Session.SessionID = Cardio.SessionID ORDER BY Cardio.CardioName ASC"

My intention is to pull out all the records from the cardio table of a particular user for a given excercise. As you'll see if you look at the ERD, the Cardio table itself doesn't contain the User ID, but rather a Session ID that can be associated with a user in the session table, so I need to reference 2 tables.

The variable CurrentUser holds the ID of the user currently using the system, and the ExName variable holds the name of an excercise which is chosen from a list, which is in turn taken from a table holding valid excercises - both variables are holding the correct values.

However, the problem I have is that I get the following error (which isn't exactly very verbose): "The command contained one or more errors". Anyone got any ideas?

The table structure is as below....

ERD.GIF
 
Sorted it using an INNER JOIN....

SQL = "SELECT Cardio.CardioName, Cardio.Time, Cardio.Distance, Cardio.Cals FROM cardio INNER JOIN session ON Session.SessionID = Cardio.SessionID WHERE Cardio.CardioName = '" & ExName & "' AND Session.UserID = '" & CurrentUser & "'"


Case closed.
 
Back
Top Bottom