|
-
May 29th, 2007, 09:26 AM
#1
Thread Starter
Frenzied Member
[2005] SQL Join question
I've got 2 tables (USviews & USviewsDescription). I'm trying to get data from both to put into a datatable. I keep getting an error message about the SQL statement being incorrect near the WHERE clause. I've never done JOIN statements before, could someone tell me what's the matter if at all possible?
vb Code:
sel = "SELECT * FROM USviews NATURAL JOIN USviewsDescription WHERE UV_SessionID = myint"
UV_SessionID is a column name in the USviews table. Is it just the simple fact my logic is totally wrong and I can't do this or is there another reason? I also tried specifying: WHERE USviews.UV_SessionID = myInt
and also tried replacing myInt with an Integer value but nothing worked. I'm obviously doing something completely wrong. Can anyone shed some light on it?
-
May 29th, 2007, 09:31 AM
#2
Fanatic Member
Re: [2005] SQL Join question
vb Code:
sel = "SELECT * FROM USviews NATURAL JOIN USviewsDescription ON UV_SessionID = myInt"
-
May 29th, 2007, 09:37 AM
#3
Re: [2005] SQL Join question
I would say like this:
Select * From USviews Inner Join USviewsDesctionion On UV_SessionID Where UV_SessionID = " & myInt.ToString()
The myInt should be outside the string qoutes to allow the variables value to be used.
I would really like to see the database structure to eally help out though.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
May 29th, 2007, 09:55 AM
#4
Thread Starter
Frenzied Member
Re: [2005] SQL Join question
talkro, I got the following error message (although i moved the myInt outside the string as Gary suggested). I got the following error:
The multi-part identifier "USviews.UV_SessionID" could not be bound.
Gary, when I tried yours I got this message:
An expression of non-boolean type specified in a context where a condition is expected
I think I'm doing something badly wrong here although I've double checked the column names, values and datatypes, they are correct. I'll keep trying, thanks.
-
May 29th, 2007, 09:57 AM
#5
Re: [2005] SQL Join question
What are the database fields types? What is the actuall SQL being generalted? My main point is that myInt needs to outside the double qoutes.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
May 29th, 2007, 10:41 AM
#6
Hyperactive Member
Re: [2005] SQL Join question
You need to specify how the tables are joined in the ON clause. As far as I know that means you need to reference a column in both tables-not just one.
Instead of 'On UV_SessionID' I'd say 'ON USviews.UV_SessionID = USviewsDesctionion.UV_SessionID' assuming that both tables have the same column.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|