日期:2014-05-16  浏览次数:21051 次

ASP中一条输出产品的SQL语句问题希望大家帮忙看看
 先输出产品ID为20的产品 然后在输出其他产品 显示方式产品ID为20的在前面显示其他产品按照排序显示 

 例如:点击类别电脑 先输出所有电脑产品然后输出电脑周边的一些产品如鼠标键盘等。。按照ID大小排序出来
 
 但是电脑显示在最前面、
 我现在写了一条可是没有输出
 


 <%
 classid = request("classid")
set rsx=server.createobject("adodb.recordset")
sqlx="select * from product where classid="&classid&"  order by case when classid="&classid&" then 1 else 2 end,classid"
rsx.open sqlx,conn,1,1
if not rsx.eof then
  %>

------解决方案--------------------
 写两条语句嘛,搞得这么复杂
sqlx="select * from product where classid="&classid&" 

sqly="select * from product where not exists (select * from product where classid="&classid&"  ) 
------解决方案--------------------
1.分写成两个SELECT语句先后执行.
2.两个SELECT语句可以用UNION联结在一起一次执行,执行的就是楼主要求的记录结果.
3.可以作成一个存储过程,对于编号有一定规则的情况比较适合.