Re: What's wrong with my SQL query ?
- From: "Anthony Jones" <Ant@xxxxxxxxxxxxxxxx>
- Date: Tue, 26 Aug 2008 16:29:44 +0100
"NS" <n@s> wrote in message news:48b41cf1$1$851$426a74cc@xxxxxxxxxxxxxxx
Hello,80040E14
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
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?image=vbssqlqueryerrorpu1.jpg)
You've include a joing to T_Missions twice. You need therefore to alias the
table name so that each join has a different name. See change in line.
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, " _
Change to M1.Libellé AS Libellé_Mission,
& "T_Missions.Numéro AS Numéro_Mission, " _
Change to M2.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 " _
change to dbo.T_Missions M1 ON
& "dbo.T_Ingénieurs.ID = dbo.T_Missions.ID_Responsable INNER JOIN " _
& "dbo.T_Missions ON " _
change to dbo.T_Missions M2 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
I don't read french so I've only guessed at which of the field comes from
which instance of T_Missions but you get the general idea.
--
Anthony Jones - MVP ASP/ASP.NET
.
- Prev by Date: Re: How to get the Local Machine Name
- Next by Date: Re: How to open Access in VBS and leave it open
- Previous by thread: Re: How to get the Local Machine Name
- Next by thread: Re: What's wrong with my SQL query ?
- Index(es):
Relevant Pages
|