select * from table1 where (价格>20 and 价格<50) and (面积>100 and 面积<200)
自己去分解这个字符串..然后用exec去执行.
SELECT * FROM [TABLE] WHERE [类型] = 'XXX' AND [区域] ='YYY' AND [价格] BETWEEN 20 AND 50 AND [面积] BETWEEN 100 AND 200
select * from table1 where 类型='某某类型' and 区域='某某区域' and (价格>20 and 价格<50) and (面积>100 and 面积<200)
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
方法多种,区域和类型和也可以用like模糊查询 价格和面积也可以用between and select * from table where 区域='条件' and 类型='条件' and 价格<50 and 价格>20 and 面积>100 and 面积<200
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
select * from table1 where 类型='某某类型' and 区域='某某区域' and (价格 between 20 and 50) and (面积 between 100 and 200)
where 类型='某某类型' and 区域='某某区域' and (价格>20 and 价格<50) and (面积>100 and 面积<200)
@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
select * from table where 区域='条件' and 类型='条件' and 价格<50 and 价格>20 and 面积>100 and 面积<200
@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
where 类型='某某类型' and 区域='某某区域' and (价格 between 20 and 50) and (面积 between 100 and 200)