是不是要加个else?
Case @hotel_money when '01' then 'hotelminor.hotel_member_price > 250'
when '02' then 'hotelminor.hotel_member_price > 250 and hotelminor.hotel_member_price < 400'
when '03' then 'hotelminor.hotel_member_price > 400 and hotelminor.hotel_member_price < 600'
when '04' then 'hotelminor.hotel_member_price > 600 and hotelminor.hotel_member_price < 800'
when '05' then 'hotelminor.hotel_member_price > 800'
else ' 1=1 '
End
Case @hotel_money when '01' then 'hotelminor.hotel_member_price > 250'
when '02' then 'hotelminor.hotel_member_price > 250 and hotelminor.hotel_member_price < 400'
when '03' then 'hotelminor.hotel_member_price > 400 and hotelminor.hotel_member_price < 600'
when '04' then 'hotelminor.hotel_member_price > 600 and hotelminor.hotel_member_price < 800'
when '05' then 'hotelminor.hotel_member_price > 800'
else ' 1=1 '
End
解决方案 »
- 想问一下SQL 2005客户端安装问题
- 急请指点:表中内容改变,怎么用TRIGGER把变动的内容 插入另一张表
- sql2000里备份的数据库文件无法在2005里还原啊?
- 数据库里的用户函数代码太多有影响吗?
- 数据库恢复的问题 ?
- 请问大力,愉快的登山者等,这个问题!
- 多个数据库数据合并问题
- 请问大虾:如何在pb8.0中使用ole db接口连接SQL Server中的除master之外的数据库?不用Data Link file,只用代码!!
- SQL Server数据库的异地数据处理问题!
- 'NOW' is not a recognized built-in function name.
- 怎样得到应用程序的起始路径(vfp)
- ODBC的难问题,快来救火呀!help!
@hotel_city2 varchar(50),
@hotelmain_name varchar(255),
@hotel_star int,
@hotel_money varchar(10)As
declare @v_sql varchar(2000)
declare @v_condition varchar(200)if @hotel_money = '01'
set @v_condition = ' and hotelminor.hotel_member_price > 250'
else if @hotel_money = '02'
set @v_condition = ' and hotelminor.hotel_member_price > 250 and hotelminor.hotel_member_price < 400'
else if @hotel_money = '03'
set @v_condition = ' and hotelminor.hotel_member_price > 400 and hotelminor.hotel_member_price < 600'
else if @hotel_money = '04'
set @v_condition = ' and hotelminor.hotel_member_price > 600 and hotelminor.hotel_member_price < 800'
else if @hotel_money = '05'
set @v_condition = ' and hotelminor.hotel_member_price > 800'
else
set @v_condition = ''set @v_sql = 'Select distinct hotelmain.id , hotelmain.hotelmain_name, hotelmain.hotel_city , hotelmain.hotel_city2 , hotelmain.hotel_info
From hotelmain , hotelminor
Where hotelmain.hotelmain_name = hotelminor .hotelmain_name and hotelmain.hotel_city = '+@hotel_city+' and hotelmain.hotel_city2 like ''%'''+@hotel_city2+'''%''
and hotelmain.hotelmain_name like ''%''' + @hotelmain_name +'''%'' and hotelmain.hotel_star like ''%'''+@hotel_star+'''%'''+@v_conditionexec (@v_sql)
GO
(@hotel_money = '02' and hotelminor.hotel_member_price > 250 and hotelminor.hotel_member_price < 400) or
(@hotel_money = '03' and hotelminor.hotel_member_price > 400 and hotelminor.hotel_member_price < 600) Or
(@hotel_money = '04' and hotelminor.hotel_member_price > 600 and hotelminor.hotel_member_price < 800) Or
(@hotel_money = '05' and hotelminor.hotel_member_price > 800)
select ......
from .....
where 'hotelminor.hotel_member_price > 250'之类的,肯定不能执行的。
hotelmain.hotel_city2 like ''%'''+@hotel_city2+'''%'' ??hotelmain.hotel_city2 like '%'+@hotel_city2+'%'不是很简单吗?另外我还是想知道,为什么使用case会出错先给你加上60分