?
Solved

Sql error, Incorrect syntax

Posted on 2007-11-30
4
Medium Priority
?
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

650 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