有一个表TABLE,有区域、类型、价格、面积等字段。
求一条搜索语句,是根据这四个字段来搜索的。
比如说这样的条件: 某某类型、某某区域、20<价格<50、100<面积<200求高手指点一下怎么写这样一条SQL语句,谢谢。

解决方案 »

  1.   

    select * from table1 where (价格>20 and 价格<50) and (面积>100 and 面积<200)
      

  2.   

    自己去分解这个字符串..然后用exec去执行.
      

  3.   

    SELECT * FROM [TABLE] WHERE [类型] = 'XXX'  AND [区域] ='YYY' AND [价格] BETWEEN 20 AND 50 AND [面积] BETWEEN 100 AND 200
      

  4.   

    select * from table1 
    where 类型='某某类型' and 区域='某某区域' and (价格>20 and 价格<50) and (面积>100 and 面积<200)
      

  5.   

    create proc pr_test
    @q varchar(10) = '',
    @l varchar(10) = '',
    @p1 int = 0,
    @p2 int = 0,
    @s1 int = 0 ,
    @s2 int = 0
    as
    begin
      判断为空拼成SQL的where 条件
      exec ('select * from ta where 1 =1 and '+ @sqlwhere
    end 
    go
      

  6.   

    方法多种,区域和类型和也可以用like模糊查询 价格和面积也可以用between and
    select * from table where 区域='条件' and 类型='条件' and 价格<50 and 价格>20 and 面积>100 and 面积<200
      

  7.   

    create proc pr_test 
    @q varchar(10) = '', 
    @l varchar(10) = '', 
    @p1 int = 0, 
    @p2 int = 0, 
    @s1 int = 0 , 
    @s2 int = 0 
    as 
    begin 
      判断为空拼成SQL的where 条件 
      set @sqlwhere = ....
      exec ('select * from ta where 1 =1 and '+ @sqlwhere )
    end 
    go 
      

  8.   

    select * from table1 
    where 类型='某某类型' and 区域='某某区域' and (价格 between 20 and 50) and (面积 between 100 and 200)