Solved

Error Executing Database Query

Posted on 2007-03-26
9
301 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
  • 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
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…

791 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