-1
<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 *”中发生第二个查询错误。为此写什么

4

1 回答 1

4

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

于 2013-10-23T12:58:38.170 回答