100分求解存储过程,查询问题!!在线等待!

xlfj521 2005-10-04 03:11:18
在页面中搜索查询,共有六个查询条件进行组合查询,甚至更多,
我在SQL里面设置的存储过程,但是判断每个条件的成立,太麻烦了
需要写很长时间,代码如下:
谁有更好的办法,高分求教啊!!!!

set @str2='RestId,Res_name,Res_Regionid,Res_Consumeid,Res_address,Res_Discountid'
set @str3='order by Addtime desc'
if @Regionid ='' and @Priceid='' and @Cuisineid='' and @Neighborhoodid=''and @Discountid='' and @RestaurantName='' and @Parking='1'
begin
set @str='select ' + @str2 + ' from eat_RestInfo '+ @str3 +' '
select @str sql
return
end
else
if @Priceid='' and @Regionid !='' and @Cuisineid !='' and @Neighborhoodid !=''and @Discountid !='' and @RestaurantName !='' and @Parking='1'
begin
set @str='select ' + @str2 + ' from eat_RestInfo where Res_Regionid ='+ @Regionid +' and Res_Cuisineid ='+ @Cuisineid +' _
and Res_Neighborhoodid ='+ @Neighborhoodid +' and Res_Discountid ='+ @Discountid +' and Res_Parking='+ @Parking+' and Res_name ='+ @RestaurantName +' '+ @str3 +' '
select @str sql
return
end
else
if @Priceid!='' and @Regionid ='' and @Cuisineid !='' and @Neighborhoodid !=''and @Discountid !='' and @RestaurantName !='' and @Parking='1'
begin
set @str='select ' + @str2 + ' from eat_RestInfo where Res_Priceid='+ @Priceid +' and Res_Cuisineid ='+ @Cuisineid +' _
and Res_Neighborhoodid ='+ @Neighborhoodid +' and Res_Discountid ='+ @Discountid +' and Res_Parking='+ @Parking+' and Res_name ='+ @RestaurantName +' '+ @str3 +' '
select @str sql
return
end
if @Priceid!='' and @Regionid !='' and @Cuisineid ='' and @Neighborhoodid !=''and @Discountid !='' and @RestaurantName !='' and @Parking='1'
begin
set @str='select ' + @str2 + ' from eat_RestInfo where Res_Regionid ='+ @Regionid +' and Res_Priceid='+ @Priceid +' _
and Res_Neighborhoodid ='+ @Neighborhoodid +' and Res_Discountid ='+ @Discountid +' and Res_Parking='+ @Parking+' and Res_name ='+ @RestaurantName +' '+ @str3 +' '
select @str sql
return
end
else
if @Priceid!='' and @Regionid !='' and @Cuisineid !='' and @Neighborhoodid =''and @Discountid !='' and @RestaurantName !='' and @Parking='1'
begin
set @str='select ' + @str2 + ' from eat_RestInfo where Res_Regionid ='+ @Regionid +' and Res_Priceid='+ @Priceid +' _
and Res_Cuisineid ='+ @Cuisineid +' and Res_Discountid ='+ @Discountid +' and Res_Parking='+ @Parking+' and Res_name ='+ @RestaurantName +' '+ @str3 +' '
select @str sql
return
end
else
if @Priceid!='' and @Regionid !='' and @Cuisineid !='' and @Neighborhoodid !=''and @Discountid ='' and @RestaurantName !='' and @Parking='1'
begin
set @str='select ' + @str2 + ' from eat_RestInfo where Res_Regionid ='+ @Regionid +' and Res_Priceid='+ @Priceid +' _
and Res_Cuisineid ='+ @Cuisineid +' and Res_Neighborhoodid ='+ @Neighborhoodid +' and Res_Parking='+ @Parking+' and Res_name ='+ @RestaurantName +' '+ @str3 +' '
select @str sql
return
end
...全文
78 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧