Solved

Error Executing Database Query

Posted on 2007-03-26
9
303 Views
Last Modified: 2010-03-20
Error Executing Database Query.
[Macromedia][SQLServer JDBC Driver][SQLServer]Incorrect syntax near the keyword 'AND'    


-------------------------------------------------------------

 SELECT departments.pos, departments.depId, departments.name as depName, departments.metaDescription as depMeta, categories.name as catName, categories.metaDescription as catMeta, catId
        FROM departments
        LEFT JOIN categories on departments.depId = categories.depId ORDER BY pos ASC
0
Comment
Question by:pigmentarts
[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
  • 5
  • 3
9 Comments
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 250 total points
ID: 18791655
PLEASE post the full query...

there must be an and in it somewhere...

(ps... please alias your table names it makes the sql much more readable...)
 
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18791685
I agree with lowfatspread: the query you posted does not contain an AND anywhere, so you must have another SQL that raises the error.
0
 
LVL 12

Author Comment

by:pigmentarts
ID: 18791708
this is the whole query, i posted the wrong error sorry

 [Macromedia][SQLServer JDBC Driver][SQLServer]Ambiguous column name 'pos'.


-----------------------------


<cffunction name="getMenuDepartments" returntype="query" hint="get departments and categories">
     <cfset var locals = StructNew()>
     <cfquery name="locals.departments" datasource="#dbSource#" username="#dbUsername#" password="#dbPassword#">
        SELECT departments.pos, departments.depId, departments.name as depName, departments.metaDescription as depMeta, categories.name as catName, categories.metaDescription as catMeta, catId
        FROM departments
        LEFT JOIN categories on departments.depId = categories.depId ORDER BY pos ASC      
       </cfquery>
     
<cfreturn locals.departments>
</cffunction>      
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 12

Author Comment

by:pigmentarts
ID: 18791714
ps, sorry if its a little hard to read was cut and paste happy. i think the error is becuase it was in mysql now i have a ms msql database does it have to be in tsql? ect

0
 
LVL 12

Author Comment

by:pigmentarts
ID: 18791718
the order by is the problem (ORDER BY pos ASC) but in tsql i dont know how to correct this without putting every column name.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18791727
       SELECT departments.pos, departments.depId, departments.name as depName, departments.metaDescription as depMeta, categories.name as catName, categories.metaDescription as catMeta, catId
        FROM departments
        LEFT JOIN categories on departments.depId = categories.depId ORDER BY departments.pos ASC      
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
ID: 18791731
explanation: as you have a "pos" column in both tables, it would not be able to know which to use.
YOU might know that both values are the same, but SQL cannot know.

as lowfatspread indicated already, use table alias names, makes the query easier to read:

       SELECT d.pos, d.depId, d.name as depName, d.metaDescription as depMeta, c.name as catName, c.metaDescription as catMeta, c.catId
        FROM departments d
        LEFT JOIN categories c on d.depId = c.depId ORDER BY d.pos ASC  
0
 
LVL 12

Author Comment

by:pigmentarts
ID: 18791736
i see so i dont have to list them all just do departments.pos. many thanks
0
 
LVL 12

Author Comment

by:pigmentarts
ID: 18791741
i will use use table alias names now, i see what you mean
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

730 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