Solved

Sql error, Incorrect syntax

Posted on 2007-11-30
4
284 Views
Last Modified: 2010-03-20
Sql error, Incorrect syntax

HI,

I am working on SQL 2000

What is the problem in my below query.

error says

Server: Msg 170, Level 15, State 1, Line 12
Line 12: Incorrect syntax near 'id'.



SELECT DISTINCT
                      *
FROM        
      dbo.ProductSubType
            INNER JOIN
                      dbo.ProductSubTypeLink
                  ON dbo.ProductSubType.id = dbo.ProductSubTypeLink.ProductSubTypeId
            INNER JOIN
                      dbo.ProductSubCategoryLink
            INNER JOIN
                      dbo.Product
                  ON dbo.ProductSubCategoryLink.ProductID = dbo.Product.id
                  


Thanks
0
Comment
Question by:tia_kamakshi
  • 2
4 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 20380887
you are missing the join condition for the  dbo.ProductSubCategoryLink  table...


apart from that, note that you should consider using table alias names...
SELECT DISTINCT  *
FROM  dbo.ProductSubType pst
INNER JOIN dbo.ProductSubTypeLink  pstl
   ON pst.id = pstl.ProductSubTypeId 
INNER JOIN dbo.ProductSubCategoryLink pscl
   ON pscl..... = .....
INNER JOIN dbo.Product p
   ON pscl.ProductID = p.id

Open in new window

0
 
LVL 7

Expert Comment

by:Chandan_Gowda
ID: 20380898
You have joined  dbo.ProductSubCategoryLink table but u have not mentioned the column names
0
 
LVL 16

Expert Comment

by:Rick_Rickards
ID: 20383160
You're SELECT statement asks for everything * but that will error when everything could be from any one of several tables.  Your * needs to be preceeded by a table name from which you want values.  Also you can not use the * more than one time.

Also there is a missing JOIN in reference to the dbo.ProductSubCategoryLink table.... To make the two examples easier to see here is the before and after picture....

Before - Syntax Error

SELECT DISTINCT
                *
FROM        
      dbo.ProductSubType
            INNER JOIN dbo.ProductSubTypeLink ON dbo.ProductSubType.id = dbo.ProductSubTypeLink.ProductSubTypeId
            INNER JOIN dbo.ProductSubCategoryLink
            INNER JOIN dbo.Product ON dbo.ProductSubCategoryLink.ProductID = dbo.Product.id


AFTER -- Adjust the table with the * to match the one you want and verify that the link added "ON dbo.ProductCategoryLink.ProductCategoryLinkID = dbo.ProductSubTypeLink.ProductCategoryLinkID " fits your situation, (adjusting table names and field names to produce the desired JOIN.

SELECT DISTINCT
                dbo.ProductSubType.*
FROM        
      dbo.ProductSubType
            INNER JOIN dbo.ProductSubTypeLink ON dbo.ProductSubType.id = dbo.ProductSubTypeLink.ProductSubTypeId
            INNER JOIN dbo.ProductSubCategoryLink ON dbo.ProductCategoryLink.ProductCategoryLinkID = dbo.ProductSubTypeLink.ProductCategoryLinkID
            INNER JOIN dbo.Product ON dbo.ProductSubCategoryLink.ProductID = dbo.Product.id




SELECT DISTINCT
                dbo.ProductSubType.*
FROM        
      dbo.ProductSubType
            INNER JOIN dbo.ProductSubTypeLink ON dbo.ProductSubType.id = dbo.ProductSubTypeLink.ProductSubTypeId
            INNER JOIN dbo.ProductSubCategoryLink ON dbo.ProductCategoryLink.ProductCategoryLinkID = dbo.ProductSubTypeLink.ProductCategoryLinkID
            INNER JOIN dbo.Product ON dbo.ProductSubCategoryLink.ProductID = dbo.Product.id
0
 
LVL 16

Expert Comment

by:Rick_Rickards
ID: 20383169
**** Reposting my last post to eliminate the unintended duplication it had at the bottom of the post...

You're SELECT statement asks for everything * but that will error when everything could be from any one of several tables.  Your * needs to be preceeded by a table name from which you want values.  Also you can not use the * more than one time.

Also there is a missing JOIN in reference to the dbo.ProductSubCategoryLink table.... To make the two examples easier to see here is the before and after picture....

Before - Syntax Error

SELECT DISTINCT
                *
FROM        
      dbo.ProductSubType
            INNER JOIN dbo.ProductSubTypeLink ON dbo.ProductSubType.id = dbo.ProductSubTypeLink.ProductSubTypeId
            INNER JOIN dbo.ProductSubCategoryLink
            INNER JOIN dbo.Product ON dbo.ProductSubCategoryLink.ProductID = dbo.Product.id


AFTER -- Adjust the table with the * to match the one you want and verify that the link added "ON dbo.ProductCategoryLink.ProductCategoryLinkID = dbo.ProductSubTypeLink.ProductCategoryLinkID " fits your situation, (adjusting table names and field names to produce the desired JOIN.

SELECT DISTINCT
                dbo.ProductSubType.*
FROM        
      dbo.ProductSubType
            INNER JOIN dbo.ProductSubTypeLink ON dbo.ProductSubType.id = dbo.ProductSubTypeLink.ProductSubTypeId
            INNER JOIN dbo.ProductSubCategoryLink ON dbo.ProductCategoryLink.ProductCategoryLinkID = dbo.ProductSubTypeLink.ProductCategoryLinkID
            INNER JOIN dbo.Product ON dbo.ProductSubCategoryLink.ProductID = dbo.Product.id
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

815 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

8 Experts available now in Live!

Get 1:1 Help Now