日期:2014-05-17  浏览次数:20959 次

ASP中select top查询的记录为变量时,该如何写?望指教~~
ASP中select   top查询的记录为变量时,该如何写?望指教~~


如:

buycount=request.form( "buycount ")


select   top   [如何获取buycount里的数值?]   form   pro   order   by   id   desc

望高手指教~~~



------解决方案--------------------
buycount=request.form( "buycount ")


select top "&buycount& " form pro order by id desc

try.
------解决方案--------------------
输出下buycount=request.form( "buycount ")的值,是不是数字?

select top "&cint(buycount)& " form pro order by id desc

------解决方案--------------------
buycount=request.form( "buycount ")


SQL = "select top " & buycount & " * form pro order by id desc "

set rs = .....
------解决方案--------------------
if buycount > 0 then strSql = " top " & buycount else strSql = " "

sql = "select " & strSql & " * from .... "
------解决方案--------------------
不需要end if

response.write sql
response.end

打印sql语句,贴出来.
------解决方案--------------------
因为 你的 buycount = 0
------解决方案--------------------
if buycount > 0 then strSql = " top " & buycount else strSql = " "

或者:

if buycount > 0 then
strSql = " top " & buycount
else
strSql = " "
End if

if 写在一行上时,不需要end if
------解决方案--------------------
response.write buycount '输出这个数字

if .....
sql = .....

response.write sql '输出sql

rs.open sql.....

查看一下.sql, 然后把 同样数字的代入sql中,再试.结果应是一样的.不一样也是你程序的问题.^__________^
------解决方案--------------------
那是因为,符合条件的只有二条,你让它怎么替你搞出三条出来?
------解决方案--------------------
sql server 查询分析器里运行一下.
------解决方案--------------------
~~:|