Solved

Error Executing Database Query

Posted on 2007-03-26
9
295 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 142

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
 
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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 142

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 142

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

16 Experts available now in Live!

Get 1:1 Help Now