错误:查询查询语法错误

时间:2013-10-23 12:18:24

标签: sql coldfusion coldfusion-10

<cfquery name="result" datasource="Training">
        select  TE.firstname,TE.lastname,TD.deparmentname,TE.salary,TE.DateOfBirth
        from TEmployee as TE 
        inner join Tdepartment as TD
        on TE.departmentID=TD.departmentID
        where 1 = 1
        <cfif isdefined('form.fname') AND len(form.fname) gt 0 >
        AND TE.FirstName Like  '#Form.fname#%'
        </cfif>
        <cfif isdefined('form.lname') AND len(form.lname) gt 0>
        and TE.LastName Like '#Form.lname#%'
        </cfif>
        <cfif isdefined('form.dept') AND form.dept neq 0>
        and TD.DeparmentName='#form.dept#'
        </cfif>

        <cfif isdefined('form.salary') AND ListLen(Form.salary,'-') EQ 2>
        and TE.salary between #ListGetAt(Form.salary,1,'-')# AND #ListGetAt(Form.salary,2,'-')#
        </cfif>

        <cfif isdefined('form.hidetxt') AND Len(form.hidetxt) GT 0>
            order by #form.hidetxt# 
        </cfif>
    </cfquery>
     <cfdump var="#result#">
            <cfoutput>
            <cfquery dbtype="query" name="detail"> 
                select top 2 * 
                  FROM result
                  WHERE 1=1
                        <cfif isdefined('form.hidetxt') AND Len(form.hidetxt) GT 0>
                                  order by #form.hidetxt# 

                        </cfif>
            </cfquery>
      </cfoutput>
      <cfdump var="#detail#">

前2名出错。但是这个查询在数据库中工作。我在这做了什么错。在“select top 2 *”中出现第二个查询错误。该怎么写

1 个答案:

答案 0 :(得分:4)

TOP不是QoQ的SQL实现的一部分。使用maxrows标记上的<cfquery>属性。