Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - What's wrong with my SQL query ?

Reply
 
Old 08-26-2008   #1 (permalink)
NS


 
 

What's wrong with my SQL query ?

Hello,

I have a SQL query that perfectly works using *SQL Entreprise Manager*.
But when i try to use the very same in a VBS script i got an error 80040E14
telling me something like :
Tables or functions 'dbo.T_Missions' and 'dbo.T_Missions' have the same
name. (error message here in french :
http://img515.imageshack.us/my.php?i...ryerrorpu1.jpg)

Please help me to solve my pb.
Code is here :
-------------------------------------------------------------------------
Dim Mission
Mission = InputBox("Enter your mission number : " , ".: Mission Browser
:." )
If IsEmpty(Mission) Then
MsgBox "You pressed Cancel!", 48, "Canceling"
Wscript.Quit
End If

Set adoRecordset = CreateObject("ADODB.Recordset")
adoRecordset.ActiveConnection = "DRIVER=SQL Server;" _
& "Trusted_Connection=Yes;" _
& "DATABASE=Xpertease;SERVER=EXPERTEASE"

adoRecordset.Source = "SELECT DISTINCT " _
& "T_Missions.Libellé AS Libellé_Mission, " _
& "T_Missions.Numéro AS Numéro_Mission, " _
& "T_Ingénieurs.Initiales AS Initiales_Expert, " _
& "T_TypesMissions.Libellé AS AouJ " _
& "FROM dbo.T_Ingénieurs INNER JOIN " _
& "dbo.T_Missions ON " _
& "dbo.T_Ingénieurs.ID = dbo.T_Missions.ID_Responsable INNER JOIN " _
& "dbo.T_Missions ON " _
& "dbo.T_Missions.ID_NatureOrigine = dbo.T_TypesMissions.ID " _
& "WHERE (dbo.T_Missions.Numéro = " & Mission & ")"
adoRecordset.Open
Do Until adoRecordset.EOF
str1st = adoRecordset.Fields("Libellé").Value
str2nd = adoRecordset.Fields("No_Mission").Value
str3rd = adoRecordset.Fields("Titulaire").Value
str4th = adoRecordset.Fields("AouJ").Value
Wscript.Echo str1st & " " & str2nd & " " & str3rd & " " & str4th
adoRecordset.MoveNext
Loop
adoRecordset.Close
-------------------------------------------------------------------------

Thanks a lot to the community if you can help me.

Nicolas




My System SpecsSystem Spec
Old 08-26-2008   #2 (permalink)
Old Pedant


 
 

Re: What's wrong with my SQL query ?

I think Anthony mis-diagnosed the problem.

I don't think there was any intent to JOIN to the same table twice. I think
it was simply a case of naming the wrong table in the join!

After all, the SELECT includes
T_TypesMissions.Libellé AS AouJ
and the second ON condition says
ON dbo.T_Missions.ID_NatureOrigine = dbo.T_TypesMissions.ID

Joining on T_Missions twice wouldn't fix the errors that would be caused by
those two usages of T_TypesMissions.

So I think the only error is that the SECOND
& "dbo.T_Missions ON " _
should, instead, be
& "dbo.T_TypesMissions ON " _

Thus:

adoRecordset.Source = "SELECT DISTINCT " _
& "T_Missions.Libellé AS Libellé_Mission, " _
& "T_Missions.Numéro AS Numéro_Mission, " _
& "T_Ingénieurs.Initiales AS Initiales_Expert, " _
& "T_TypesMissions.Libellé AS AouJ " _
& "FROM dbo.T_Ingénieurs INNER JOIN " _
& "dbo.T_Missions ON " _
& "dbo.T_Ingénieurs.ID = dbo.T_Missions.ID_Responsable INNER JOIN " _
& "dbo.T_TypesMissions ON " _
& "dbo.T_Missions.ID_NatureOrigine = dbo.T_TypesMissions.ID " _
& "WHERE (dbo.T_Missions.Numéro = " & Mission & ")"


My System SpecsSystem Spec
Old 08-26-2008   #3 (permalink)
Anthony Jones


 
 

Re: What's wrong with my SQL query ?

"Old Pedant" <OldPedant@xxxxxx> wrote in message
news:2E552069-84A5-4BE0-BF28-2102303B0D21@xxxxxx
Quote:

> I think Anthony mis-diagnosed the problem.
>
> I don't think there was any intent to JOIN to the same table twice. I
think
Quote:

> it was simply a case of naming the wrong table in the join!
>
> After all, the SELECT includes
> T_TypesMissions.Libellé AS AouJ
> and the second ON condition says
> ON dbo.T_Missions.ID_NatureOrigine = dbo.T_TypesMissions.ID
>
> Joining on T_Missions twice wouldn't fix the errors that would be caused
by
Quote:

> those two usages of T_TypesMissions.
>
> So I think the only error is that the SECOND
> & "dbo.T_Missions ON " _
> should, instead, be
> & "dbo.T_TypesMissions ON " _
>
> Thus:
>
> adoRecordset.Source = "SELECT DISTINCT " _
> & "T_Missions.Libellé AS Libellé_Mission, " _
> & "T_Missions.Numéro AS Numéro_Mission, " _
> & "T_Ingénieurs.Initiales AS Initiales_Expert, " _
> & "T_TypesMissions.Libellé AS AouJ " _
> & "FROM dbo.T_Ingénieurs INNER JOIN " _
> & "dbo.T_Missions ON " _
> & "dbo.T_Ingénieurs.ID = dbo.T_Missions.ID_Responsable INNER JOIN " _
> & "dbo.T_TypesMissions ON " _
> & "dbo.T_Missions.ID_NatureOrigine = dbo.T_TypesMissions.ID " _
> & "WHERE (dbo.T_Missions.Numéro = " & Mission & ")"
>
Well spotted


--
Anthony Jones - MVP ASP/ASP.NET


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
SP2 query... Vista General
Tab key query Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46