Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > SQL JOIN problem...


Reply
 
Thread Tools Display Modes
  #1  
Old 04-21-2005, 03:02 PM
Erik Erik is offline
Centurion
 
Join Date: Jan 2003
Posts: 118
Default SQL JOIN problem...


Hello...


Is it possible to join 1 table data into 2 collumns in one query like this:

Code:
"SELECT Prevozi.PriimekIme, Prevozi.UlicaSt, Prevozi.Kraj, " & _
       "Prevozi.UraStart, Prevozi.UraPrihod, Prevozi.UraCilj, Voznikisif.Voznik_sif, " & _
       "Tehnikisif.Tehnik_sif, Relacijesif.Kraj_sif, " & _
       "Statussif.Status_sif, Prevozi.Osebe, Prevozi.Km, Prevozi.VoziloSt, " & _
       "Prevozi.VoziloReg FROM ((((Prevozi INNER JOIN Voznikisif ON " & _
       "Prevozi.Voznik = Voznikisif.ID) INNER JOIN Tehnikisif ON " & _
       "Prevozi.Spremljevalec = Tehnikisif.ID) INNER JOIN  Relacijesif ON " & _
       "Prevozi.RelacijaOd = Relacijesif.ID) INNER JOIN Relacijesif  ON " & _
       "Prevozi.RelacijaDo = Relacijesif.ID)  INNER JOIN Statussif ON " & _
       "Prevozi.KoncnoStanje = Statussif.ID WHERE Datum =" & Date
It says invalid Join expression...

Thanks,
Erik
Reply With Quote
  #2  
Old 04-21-2005, 03:50 PM
VBJoe's Avatar
VBJoe VBJoe is offline
Village VB Idiot

* Expert *
 
Join Date: Jan 2003
Location: Idaho
Posts: 1,850
Default

Could you print the query out in the debugger and post that?

Also, if you're testing a Date value, then your WHERE clause will not be correct.
__________________
"What am I supposed to do with all my great ideas? Put 'em in a tub and clean myself with them? That's what soap is for, Lois."
Peter Griffin - The Family Guy
Reply With Quote
  #3  
Old 04-22-2005, 12:04 AM
Erik Erik is offline
Centurion
 
Join Date: Jan 2003
Posts: 118
Default

Quote:
Could you print the query out in the debugger and post that?
Can you explain what do you mean? ... I'm some kind of beginner
Reply With Quote
  #4  
Old 04-22-2005, 08:18 AM
VBJoe's Avatar
VBJoe VBJoe is offline
Village VB Idiot

* Expert *
 
Join Date: Jan 2003
Location: Idaho
Posts: 1,850
Default

Try Thinker's tutorial on debugging a VB app:

http://www.xtremevbtalk.com/showthre...?threadid=9415
__________________
"What am I supposed to do with all my great ideas? Put 'em in a tub and clean myself with them? That's what soap is for, Lois."
Peter Griffin - The Family Guy
Reply With Quote
  #5  
Old 04-22-2005, 04:12 PM
MKoslof's Avatar
MKoslof MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

If I understand your question, one table is joined on ONE condition within a query scope. Meaning, if you need to check against two fields in ONE table within a JOIN statement you should restructure your query to do something like:

Code:
SELECT.......
FROM T1 INNER JOIN T2 ON T1.F1 = T2.F1
WHERE T1.F2 IN (SELECT M.F2 FROM T1 M WHERE...etc.)
Basically, if you need to check or join one table on two conditions, you can create a sub query aliasing the same table and do your condition check there.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #6  
Old 04-24-2005, 04:51 AM
Erik Erik is offline
Centurion
 
Join Date: Jan 2003
Posts: 118
Default

I see, I'll try.... I will respond
Reply With Quote
  #7  
Old 04-24-2005, 03:00 PM
Erik Erik is offline
Centurion
 
Join Date: Jan 2003
Posts: 118
Default

Code:
"SELECT ....  FROM ((Table1 INNER JOIN Table2 ON " & _
       "Table1.Voznik = Table2.ID)  INNER JOIN Table3 ON " & _
       "Table1.RelacijaOd = Table3.ID) INNER JOIN Table3 ON " & _
       "Table1.RelacijaDo = Table3.ID  WHERE Name = " & txtName.txt
In the code above I have for Table3 two conditions, and I have WHERE condition for name .... how should I put this second Table3 condition in sub query.... it says invalid Join expression

I have problem with this query for about a month...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->