Microsoft Knowledge Base Email Alertz

(297035) - When executing a parameterized UNION query with the SQLOLEDB OLEDB Provider, the following error may be reported: Run-time error '-2147467259 (80004005)': The correlation name 'O' is specified multiple times in a FROM clause.

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 297035 - Last Review: September 26, 2005 - Revision: 2.3

FIX: Correlation Error Using Parameters.Refresh with SQLOLEDB

This article was previously published under Q297035

SYMPTOMS

When executing a parameterized UNION query with the SQLOLEDB OLEDB Provider, the following error may be reported:
Run-time error '-2147467259 (80004005)':

The correlation name 'O' is specified multiple times in a FROM clause.

RESOLUTION

To resolve this problem, obtain the latest service pack for SQL Server 2000, the latest service pack for MDAC 2.6, or the hotfix referenced below: For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
290211  (http://kbalertz.com/Feedback.aspx?kbNumber=290211/EN-US/ ) INF: How to Obtain the Latest SQL Server 2000 Service Pack
For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
300635  (http://kbalertz.com/Feedback.aspx?kbNumber=300635/EN-US/ ) INFO: How to Obtain the Latest MDAC 2.6 Service Pack

Hotfix

The English version of this fix should have the following file attributes or later:
 Date        Version         Size      File name     Platform
 -------------------------------------------------------------
 05/17/2001  2000.080.0294   491,584   Sqloledb.dll     x86
 05/17/2001  2000.080.0294    61,440   Sqloledb.rll     x86
				

WORKAROUND

To work around this issue, make sure that the order of the table names in each of the SELECT statements is the same in each UNION query.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. This problem was first corrected in SQL Server 2000 Service Pack 2 and MDAC 2.6 Service Pack 2.

MORE INFORMATION

To reproduce this problem, run the following Microsoft Visual Basic code:
Sub CorrelationReproCode()
Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Dim sql As String
Dim fUseOutOfOrderUNION As Boolean

    Set conn = New ADODB.Connection
    conn.Open "Provider=sqloledb;Server=.;Database=northwind;" & _
              "Integrated Security=SSPI;"
    
    ' Change this to False to avoid the problem.
    fUseOutOfOrderUNION = True
    
    If (fUseOutOfOrderUNION) Then
        sql = "SELECT O.OrderDate FROM Customers R, Orders O " & _
              "WHERE R.CustomerId = O.CustomerId AND R.CustomerId = ? " & _
              "Union " & _
              "SELECT O.OrderDate FROM Orders O, Customers R " & _
              "WHERE R.CustomerID = O.CustomerID AND R.Region = ?"
    Else
        sql = "SELECT O.OrderDate FROM Customers R, Orders O " & _
              "WHERE R.CustomerId = O.CustomerId AND R.CustomerId = ? " & _
              "Union " & _
              "SELECT O.OrderDate FROM Customers R, Orders O " & _
              "WHERE R.CustomerID = O.CustomerID AND R.Region = ?"
    End If
    Set cmd = New ADODB.Command
    cmd.CommandText = sql
    Set cmd.ActiveConnection = conn

    ' Error will occur here if fUseOutOfOrderUNION is set to True.
    cmd.Parameters.Refresh
    Set cmd.ActiveConnection = Nothing
    Set cmd = Nothing
    conn.Close
    Set conn = Nothing
    
End Sub
				

APPLIES TO
  • Microsoft OLE DB Provider for SQL Server 7.0
  • Microsoft OLE DB Provider for SQL Server 7.01
  • Microsoft Data Access Components 2.6
Keywords: 
kbhotfixserver kbqfe kbbug kbfix kbmdac260sp2fix kbsqlserv2000presp2fix KB297035
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Aji - ajichennakkadan NOSPAM-AT-NOSPAM rediffmail.com Report As Irrelevant  
Written: 7/27/2004 8:36 AM
When executing a stored procedure the following error may be reported: ODBC Error Code = 37000 (Syntax error or access violation) [Microsoft][ODBC SQL Server Driver][SQL Server]The correlation name 'a' is specified multiple times in a FROM clause. the query is CREATE PROCEDURE [MergeAccounts] @accID1 varchar(1000), @MovieDB varchar(100), @MathewsDB varchar(100), @ResearchDB varchar(100), @RMPDB varchar(100) AS DECLARE @sql varchar(8000) select @sql= "select a.accountid,a.account,a.BillAddr1,a.BillAddr2,BillCity, b.State,a.deleted /*Landoncore*/ ,isnull(proposal,0) as Proposal ,isnull(Research,0) as Research ,isnull(BillingInvoices,0) as BillingInvoices ,isnull(TravelCalendar,0) as TravelCalendar ,isnull(AcSalesReps,0) as AcSalesReps ,isnull(MDPAcceptance,0) as MDPAcceptance ,isnull(ExportInvoice,0) as ExportInvoice ,isnull(ExportInvoiceRevise,0) as ExportInvoiceRevise ,isnull(AgencyAccounts,0) as AgencyAccounts ,isnull(BillingPurchases,0) as BillingPurchases ,isnull(Tickler,0) as Tickler ,isnull(doclibry,0) as doclibry ,isnull(AccountsDivisions,0) as AccountsDivisions ,isnull(AcTagetAssign,0) as AcTagetAssign ,isnull(RunList,0) as RunList ,isnull(Correspondence,0) as Correspondence ,isnull(AcAgncyContact,0) as AcAgncyContact ,isnull(Activities,0) as Activities ,isnull(Movies,0) as Movies ,isnull(Registrants,0) as Registrants ,isnull(StudioTourAgenda,0) as StudioTourAgenda ,isnull(Uids,0) as Uids ,isnull(Adprojects,0) as Adprojects ,isnull(Contacts,0) as Contacts /*Movie*/ ,isnull(Mstudioprofiles,0) as Mstudioprofiles ,isnull(MstudioMktShares,0) as MstudioMktShares ,isnull(MAdSpending,0) as MAdSpending ,isnull(MStdoTorAgenda,0) as MStdoTorAgenda /*Mathews*/ ,isnull(MwProjects,0) as MwProjects /*Research*/ ,isnull(RProjects,0) as RProjects /*CompanyAdLog*/ ,isnull(ComAdLog,0) as ComAdLog from tblaccounts as a left join lkpStates as b on a.Billstate=b.stateid /*Landoncore*/ left join ( select accountid,count(*)as proposal from tblProposal where deleted=0 and accountid in ("+@accID1+") group by accountid )c on a.accountid=c.accountid left join ( select accountid,count(*)as Research from tblResearch where deleted=0 and accountid in ("+@accID1+") group by accountid )d on a.accountid=d.accountid left join ( select accountid,count(*)as BillingInvoices from tblBilling_Invoices where accountid in ("+@accID1+") group by accountid )e on a.accountid=e.accountid left join ( select accountid,count(*)as TravelCalendar from tblTravelCalendar where accountid in ("+@accID1+") group by accountid )f on a.accountid=f.accountid left join ( select accountid,count(*)as AcSalesReps from tblAccounts_SalesReps where deleted=0 and accountid in ("+@accID1+") group by accountid )g on a.accountid=g.accountid left join ( select accountid,count(*)as MDPAcceptance from tblMDPAcceptance where accountid in ("+@accID1+") group by accountid )h on a.accountid=h.accountid left join ( select accountid,count(*)as ExportInvoice from tblExportInvoice where accountid in ("+@accID1+") group by accountid )i on a.accountid=i.accountid left join ( select accountid,count(*)as ExportInvoiceRevise from tblExportInvoiceRevise where accountid in ("+@accID1+") group by accountid )j on a.accountid=j.accountid left join ( select accountid,count(*)as AgencyAccounts from tblAgencyAccounts where deleted=0 and accountid in ("+@accID1+") group by accountid )k on a.accountid=k.accountid left join ( select accountid,count(*)as BillingPurchases from tblBilling_Purchases where accountid in ("+@accID1+") group by accountid )l on a.accountid=l.accountid left join ( select account,count(*)as Tickler from tblTickler where account in ("+@accID1+") group by account )m on a.accountid=m.account left join ( select account,count(*)as doclibry from doclibrary where deleted=0 and account in ("+@accID1+") group by account )o on a.accountid=o.account left join ( select account,count(*)as AccountsDivisions from tblAccounts_Divisions where account in ("+@accID1+") group by account )p on a.accountid=p.account left join ( select account,count(*)as AcTagetAssign from tblAccounts_TargetsAssignments where deleted=0 and account in ("+@accID1+") group by account )q on a.accountid=q.account left join ( select account,count(*)as RunList from tblRunList where deleted=0 and account in ("+@accID1+") group by account )r on a.accountid=r.account left join ( select account,count(*)as Correspondence from tblCorrespondence where deleted=0 and account in ("+@accID1+") group by account )s on a.accountid=s.account left join ( select account,count(*)as AcAgncyContact from tblAccounts_AgencyContact where deleted=0 and account in ("+@accID1+") group by account )t on a.accountid=t.account left join ( select account,count(*)as Activities from tblActivities where deleted=0 and account in ("+@accID1+") group by account )u on a.accountid=u.account left join ( select studioid,count(*)as Movies from tblMovies where deleted=0 and studioid in ("+@accID1+") group by studioid )v on a.accountid=v.studioid left join ( select Company,count(*)as Registrants from tblRegistrants where deleted=0 and Contacttype='3' and Company in ("+@accID1+") group by company )w on a.accountid=w.Company left join ( select studioid,count(*)as StudioTourAgenda from tblStudioTourAgenda where studioid in ("+@accID1+") group by studioid )x on a.accountid=x.studioid left join ( select Companyid,count(*)as Uids from userids where deleted=0 and membertype='6' and Companyid in ("+@accID1+") group by Companyid )y on a.accountid=y.Companyid left join ( select client,count(*)as Adprojects from tbladProjects where deleted=0 and client in ("+@accID1+") group by client )z on a.accountid=z.client left join ( select objid,count(*)as Contacts from tblContacts where deleted=0 and Contacttype='5' and objid in ("+@accID1+") group by objid )aa on a.accountid=aa.objid /*Movie*/ left join ( select accountid,count(*) as Mstudioprofiles from "+@MovieDB+".MovieStudioProfiles where deleted=0 and accountid in ("+@accID1+") group by accountid )ab on a.accountid=ab.accountid left join ( select studioid,count(*) as MstudioMktShares from "+@MovieDB+".tblStudioMarketShare where studioid in ("+@accID1+") group by studioid )ac on a.accountid=ac.studioid left join ( select studioid,count(*) as MAdSpending from "+@MovieDB+".tblAdSpending where deleted=0 and studioid in ("+@accID1+") group by studioid )ad on a.accountid=ad.studioid left join ( select studioid,count(*) as MStdoTorAgenda from "+@MovieDB+".tblStudioTourAgenda where studioid in ("+@accID1+") group by studioid )ae on a.accountid=ae.studioid /*Mathews*/ left join ( select client,count(*) as MwProjects from "+@MathewsDB+".MathewsProjects where deleted=0 and Client in ("+@accID1+") group by Client )af on a.accountid=af.client /*Research*/ left join ( select client,count(*) as RProjects from "+@ResearchDB+".ResearchProjects where deleted=0 and Client in ("+@accID1+") group by Client )ag on a.accountid=ag.client /*Rmp/CompanyAdLog*/ left join ( select cid,count(*) as ComAdLog from "+@RMPDB+".CompanyAdLog where cid in ("+@accID1+") group by cid )ah on a.accountid=ah.cid where a.accountid in ("+@accID1+") and a.deleted=0 order by a.accountid" exec (@sql) return