100分求解存储过程,查询问题!!在线等待!
在页面中搜索查询,共有六个查询条件进行组合查询,甚至更多,
我在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