Solved

Server: Msg 170

Posted on 2008-06-26
6
688 Views
Last Modified: 2012-05-05
Hi,
I have a sql view, which i need to retrieve information. Question: I need three different names and surnames from the users table. The one who accepted the quote, who opened the quote and last who the quote has been assigned to.

The Error that i get is this;
Server: Msg 170, Level 15, State 1, Line 25
Line 25: Incorrect syntax near 'QuoteID'.

I appreciate the help.

SELECT dbo.Quotes.QuoteName, dbo.QuoteStatus.Description AS Status, dbo.QuoteAccepted.AcceptDate, dbo.a.FirstName+' '+dbo.a.LastName as [Accepted By], dbo.o.FirstName+' '+dbo.o.LastName as [Opened By], 

dbo.QuoteNotes.Note, dbo.QuoteNotes.NoteDate, dbo.ato.FirstName+' '+dbo.ato.LastName as [Assigned To], dbo.QuoteFollowUPs.LastFollowup, 

dbo.QuoteFollowUPs.NextFollowUp, dbo.QuoteFollowUPs.Comment, dbo.QuoteFollowUPs.HoursSpent, dbo.QuoteFollowUPs.DaysSpent, 

dbo.QuoteBookingReferences.BookRef, dbo.QuoteTourTypes.Description AS [Tour Type], dbo.QuoteTypes.Description AS [Quote Type], dbo.Quotes.QuoteID, dbo.QuotesSent.DateSent, dbo.QuotesSent.Cost, dbo.QuotesSent.PaxFrom, 

dbo.QuotesSent.PaxTo, dbo.QuotesSent.Currency, dbo.QuotesSent.Selling, dbo.QuotesSent.MasterPaxAmount

FROM dbo.QuoteBookingReferences INNER JOIN

dbo.Quotes INNER JOIN

dbo.QuoteStatus_Quotes ON dbo.Quotes.QuoteID = dbo.QuoteStatus_Quotes.QuoteID INNER JOIN

dbo.QuoteStatus ON dbo.QuoteStatus_Quotes.StatusID = dbo.QuoteStatus.StatusID ON 

dbo.QuoteBookingReferences.QuoteID = dbo.Quotes.QuoteID INNER JOIN

dbo.QuoteFollowUPs ON dbo.Quotes.QuoteID = dbo.QuoteFollowUPs.QuoteID INNER JOIN

dbo.QuoteNotes ON dbo.Quotes.QuoteID = dbo.QuoteNotes.QuoteID INNER JOIN

dbo.QuoteOpenedBy ON dbo.Quotes.QuoteID = dbo.QuoteOpenedBy.QuoteID INNER JOIN

dbo.Quotes_QuoteTourTypes ON dbo.Quotes.QuoteID = dbo.Quotes_QuoteTourTypes.QuoteID INNER JOIN

dbo.QuoteTourTypes ON dbo.Quotes_QuoteTourTypes.TypeofToursID = dbo.QuoteTourTypes.TypeofToursID INNER JOIN

dbo.Quotes_QuoteTypes ON dbo.Quotes.QuoteID = dbo.Quotes_QuoteTypes.QuoteID Inner JOIN

dbo.QuoteTypes ON dbo.Quotes_QuoteTypes.TypeofQuoteID = dbo.QuoteTypes.TypeofQuoteID INNER JOIN

dbo.QuotesSent ON dbo.Quotes.QuoteID = dbo.QuotesSent.QuoteID LEFT OUTER JOIN

/*Trying to use the same table to get back different names and surnames*/

dbo.Users INNER JOIN

dbo.Users a INNER JOIN

dbo.Users o INNER JOIN

dbo.Users ato INNER JOIN

dbo.QuoteAccepted ON dbo.a.UserID = dbo.QuoteAccepted.UserID INNER JOIN

dbo.QuoteAssignTo ON dbo.ato.UserID = dbo.QuoteAssignTo.UserID ON dbo.QuoteOpenedBy.UserID = dbo.o.UserID AND 

dbo.Quotes.QuoteID = dbo.QuoteAssignTo.QuoteID AND dbo.Quotes.QuoteID = dbo.QuoteAccepted.QuoteID

Open in new window

0
Comment
Question by:TIO-Solutions
  • 3
  • 3
6 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 21873212
line 20 to 26 are wrong.

when you have aliases, you cannot prefix them with dbo. you also are better to put the ON clause next to the INNER JOIN

INNER JOIN dbo.Users a ON a.UserID = dbo.QuoteAccepted.UserID
INNER JOIN dbo.Users o ON dbo.QuoteOpenedBy.UserID = o.UserID
INNER JOIN dbo.Users ato ON ato.UserID = dbo.QuoteAssignTo.UserID
INNER JOIN dbo.QuoteAccepted ON dbo.Quotes.QuoteID = dbo.QuoteAccepted.QuoteID
0
 

Author Comment

by:TIO-Solutions
ID: 21873499
Server: Msg 170, Level 15, State 1, Line 25
Line 25: Incorrect syntax near 'QuoteID'.


SELECT dbo.Quotes.QuoteName, dbo.QuoteStatus.Description AS Status, dbo.QuoteAccepted.AcceptDate, 

(SELECT a.FirstName+' '+a.LastName FROM Users a WHERE a.UserID = dbo.QuoteAccepted.UserID AND dbo.Quotes.QuoteID = dbo.QuoteAccepted.QuoteID)as [Accepted By], 

(SELECT o.FirstName+' '+o.LastName FROM Users o WHERE o.UserID = dbo.QuoteOpenedBy.UserID AND dbo.Quotes.QuoteID = dbo.QuoteOpenedBy.QuoteID) as [Opened By], 

dbo.QuoteNotes.Note, dbo.QuoteNotes.NoteDate, 

(SELECT a.FirstName+' '+a.LastName FROM Users a WHERE a.UserID = dbo.QuoteAssignTo.UserID AND Quotes.QuoteID = dbo.QuoteAssignTo.QuoteID) as [Assigned To], 

dbo.QuoteFollowUPs.LastFollowup, dbo.QuoteFollowUPs.NextFollowUp, dbo.QuoteFollowUPs.Comment, dbo.QuoteFollowUPs.HoursSpent, 

dbo.QuoteFollowUPs.DaysSpent, dbo.QuoteBookingReferences.BookRef, dbo.QuoteTourTypes.Description AS [Tour Type], 

dbo.QuoteTypes.Description AS [Quote Type], dbo.Quotes.QuoteID, dbo.QuotesSent.DateSent, dbo.QuotesSent.Cost, dbo.QuotesSent.PaxFrom, 

dbo.QuotesSent.PaxTo, dbo.QuotesSent.Currency, dbo.QuotesSent.Selling, dbo.QuotesSent.MasterPaxAmount

FROM dbo.QuoteBookingReferences INNER JOIN

dbo.Quotes 

INNER JOIN dbo.QuoteStatus_Quotes ON dbo.Quotes.QuoteID = dbo.QuoteStatus_Quotes.QuoteID

INNER JOIN dbo.QuoteStatus ON dbo.QuoteStatus_Quotes.StatusID = dbo.QuoteStatus.StatusID 

ON dbo.QuoteBookingReferences.QuoteID = dbo.Quotes.QuoteID 

INNER JOIN dbo.QuoteFollowUPs ON dbo.Quotes.QuoteID = dbo.QuoteFollowUPs.QuoteID 

INNER JOIN dbo.QuoteNotes ON dbo.Quotes.QuoteID = dbo.QuoteNotes.QuoteID 

INNER JOIN dbo.Quotes_QuoteTourTypes ON dbo.Quotes.QuoteID = dbo.Quotes_QuoteTourTypes.QuoteID 

INNER JOIN dbo.QuoteTourTypes ON dbo.Quotes_QuoteTourTypes.TypeofToursID = dbo.QuoteTourTypes.TypeofToursID 

INNER JOIN dbo.Quotes_QuoteTypes ON dbo.Quotes.QuoteID = dbo.Quotes_QuoteTypes.QuoteID 

INNER JOIN dbo.QuoteTypes ON dbo.Quotes_QuoteTypes.TypeofQuoteID = dbo.QuoteTypes.TypeofQuoteID 

INNER JOIN dbo.QuotesSent ON dbo.Quotes.QuoteID = dbo.QuotesSent.QuoteID Left Outer Join

Users 

Inner JOIN dbo.QuoteAccepted ON dbo.QuoteAccepted.UserID = dbo.Users.UserID AND dbo.Quotes.QuoteID = dbo.QuoteAccepted.QuoteID 

INNER JOIN dbo.QuoteOpenedBy ON dbo.QuoteOpenedBy.UserID = dbo.Users.UserID AND dbo.Quotes.QuoteID = dbo.QuoteOpenedBy.QuoteID

INNER JOIN dbo.QuoteAssignTo ON dbo.QuoteAssignTo.UserID = dbo.Users.UserID AND Quotes.QuoteID = dbo.QuoteAssignTo.QuoteID

Open in new window

0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 21873659
>>Left Outer Join Users

where is the ON clause for this line?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:TIO-Solutions
ID: 21873851
Even if i take it away it still gives me the error in the original question.
FROM dbo.Users INNER JOIN

dbo.QuoteBookingReferences INNER JOIN

dbo.Quotes 

INNER JOIN dbo.QuoteStatus_Quotes ON dbo.Quotes.QuoteID = dbo.QuoteStatus_Quotes.QuoteID

INNER JOIN dbo.QuoteStatus ON dbo.QuoteStatus_Quotes.StatusID = dbo.QuoteStatus.StatusID 

ON dbo.QuoteBookingReferences.QuoteID = dbo.Quotes.QuoteID 

INNER JOIN dbo.QuoteFollowUPs ON dbo.Quotes.QuoteID = dbo.QuoteFollowUPs.QuoteID 

INNER JOIN dbo.QuoteNotes ON dbo.Quotes.QuoteID = dbo.QuoteNotes.QuoteID 

INNER JOIN dbo.Quotes_QuoteTourTypes ON dbo.Quotes.QuoteID = dbo.Quotes_QuoteTourTypes.QuoteID 

INNER JOIN dbo.QuoteTourTypes ON dbo.Quotes_QuoteTourTypes.TypeofToursID = dbo.QuoteTourTypes.TypeofToursID 

INNER JOIN dbo.Quotes_QuoteTypes ON dbo.Quotes.QuoteID = dbo.Quotes_QuoteTypes.QuoteID 

INNER JOIN dbo.QuoteTypes ON dbo.Quotes_QuoteTypes.TypeofQuoteID = dbo.QuoteTypes.TypeofQuoteID 

INNER JOIN dbo.QuotesSent ON dbo.Quotes.QuoteID = dbo.QuotesSent.QuoteID

INNER JOIN dbo.QuoteAccepted ON dbo.QuoteAccepted.UserID = dbo.Users.UserID AND dbo.Quotes.QuoteID = dbo.QuoteAccepted.QuoteID 

INNER JOIN dbo.QuoteOpenedBy ON dbo.QuoteOpenedBy.UserID = dbo.Users.UserID AND dbo.Quotes.QuoteID = dbo.QuoteOpenedBy.QuoteID

INNER JOIN dbo.QuoteAssignTo ON dbo.QuoteAssignTo.UserID = dbo.Users.UserID AND Quotes.QuoteID = dbo.QuoteAssignTo.QuoteID

Open in new window

0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 21873880
comment out all your JOIN and add them one by one.

I see right at the beginning that you don't have the ON clause again:

FROM dbo.Users INNER JOIN
dbo.QuoteBookingReferences INNER ...

so comment out every JOINs and add them one by one (ensuring it is working before adding another one)
0
 

Author Comment

by:TIO-Solutions
ID: 21874348
CHeers mate. I was looking at the JOINs, infact the nested select statements were missing the declaration of another table....

You helped me alot though.

Cheers again!!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Query Syntax Error 9 34
sql query to reportserver  table error 3 24
SQL Date Retrival 7 31
Caste datetime 2 24
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now