是不是要加个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

解决方案 »

  1.   

    楼上的兄弟,加了else还是出现同样的错误我怀疑是不是和上面的Where语句有关,但就找不出错误来少一个空格?少一个逗号?今天见鬼了!
      

  2.   

    這種寫法是誰告訴你的??CREATE Procedure hotel_query  @hotel_city varchar(50),
      @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
      

  3.   

    你的本意是这样吧:(@hotel_money ='01' and hotelminor.hotel_member_price > 250) Or
                  (@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)
      

  4.   

     我知道怎么回事了,不能这样写的,要先组成一个字符串后再执行才对。你上面的结果会是:
    select ......
    from .....
    where 'hotelminor.hotel_member_price > 250'之类的,肯定不能执行的。
      

  5.   

    zhuzhichao(竹之草)已经写出来了,厉害厉害!PFPF!
      

  6.   

    to:zhuzhichao(竹之草)我的写法是查看sql server联机文档上的,觉得使用多重的if ... else ...会使程序变得繁琐,所以选择case的,谁知道调试了半天………另外,不明白你为什么要用
    hotelmain.hotel_city2 like ''%'''+@hotel_city2+'''%'' ??hotelmain.hotel_city2 like '%'+@hotel_city2+'%'不是很简单吗?另外我还是想知道,为什么使用case会出错先给你加上60分
      

  7.   

    to:karma(无为) 你的分已经在ASP版加上