question

jay avatar image
jay asked

The correlation name “” is specified multiple times in a FROM clause

Hi there. Basically, I have a JobOrder Table with the ff definition:

ID nvarchar(50) [the Job Order Number] pk, SiteID int fk, ClientID int fk, VehicleID int fk, OrderDate datetime, InsuranceID int fk, SalesAssistant int fk, Note text

with SiteID, ClientID, VehicleID, InsuranceID and SalesAssistantID as foreign keys. Getting to view the data from the JobOrder table in a GridView is fine, no problems or errors. But when I try to edit the record, using the ff code in a storedprocedure, I get the error: "The correlation name 'JobOrderSite' is specified multiple times in a FROM clause"

  SELECT
      dbo.JobOrder.ID ,
      dbo.JobOrder.ClientID ,
      dbo.Client_Site.ClientName ,
      dbo.JobOrder.SiteID ,
      dbo.Site.SiteName ,
      dbo.JobOrder.VehicleID ,
      dbo.Vehicle_Name.CarName ,
      dbo.JobOrder.OrderDate ,
      dbo.JobOrder.InsuranceID ,
      dbo.Insurance.InsuranceName ,
      dbo.JobOrder.SalesAssistant ,
      dbo.SalesAssistant.AssistantName ,
      dbo.JobOrder.Note ,
      dbo.Vehicle.ClientSitePlateNo
  FROM
      dbo.JobOrder
  INNER JOIN dbo.Client_Site ON dbo.JobOrder.ClientID = dbo.Client_Site.ID
  INNER JOIN dbo.Site ON dbo.JobOrder.SiteID = dbo.Site.ID
  INNER JOIN dbo.Vehicle ON dbo.JobOrder.VehicleID = dbo.Vehicle.ID
  INNER JOIN dbo.Vehicle_Name ON dbo.Vehicle.CarName = dbo.Vehicle_Name.ID
  INNER JOIN dbo.SalesAssistant ON dbo.JobOrder.SalesAssistant = dbo.SalesAssistant.ID
  INNER JOIN dbo.Insurance ON dbo.JobOrder.InsuranceID = dbo.Insurance.ID
  WHERE
      ( dbo.JobOrder.ID = @ID )

I know that this normally happens when an alias is used more than once for different tables, which is why I removed all the aliases I used and just used the field names. But I still get this error. I'm really at my wits end. I have no idea what's wrong. When I execute the storedprocedure in sql server 2005, it works fine.

Thank you so much in advance for the help.

sql-server-2005
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Matt Whitfield avatar image
Matt Whitfield answered

If that error is actually coming from the SQL you posted, then I suspect that one of the elements you are joining to is a view, and that JobOrderSite is specified in that view multiple times...

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image
Kev Riley answered

'JobOrderSite' isn't defined anywhere in this sql, is this something you have labelled in code?

This error normally appears when you have aliased 2 or more tables (or derived tables) with the same alias, but as that isn't present here, I'm guessing it's elsewhere in your code?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Fatherjack avatar image
Fatherjack answered

Have you tried wrapping all table and column names in [ ], just to avoid confusion over using the keyword site as an object name? OK, its not TSQL but it goes blue in SSMS and I like to avoid any possible confusion!

Which tables are needed in the query for the error you describe? Can you eliminate some from the query and still get the error?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.