Solved

Error Executing Database Query

Posted on 2007-03-26
9
307 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

636 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