日期:2014-5-18 浏览次数:20051次 点赞次数:20

SQL传递参数 between 100 and 500
问题如下:

select par from tb_table1 where id=1;
得到par的值 between 100 and 500

怎么样把 between 100 and 500带到下面的SQL?

select * from tb_table2 where price (select par from tb_table1 where id=1)

实现类似于:select * from tb_table2 where price between 100 and 500

------解决方案--------------------
SQL code
select * from tb_table2 where price IN (select par from tb_table1 where id=1)

------解决方案--------------------
EXEC('select * from tb_table2 where price '+(select par from tb_table1 where id=1))
------解决方案--------------------
EXEC('select * from tb_table2 where price '+(select par from tb_table1 where id=1))
------解决方案--------------------
BETWEEN不对的,万一返回的值不连续,就不能BETWEEN,IN可以

------解决方案--------------------
SQL code

--在where条件里用in
select * from tb_table2 where price in (select par from tb_table1 where id=1)

------解决方案--------------------
BETWEEN不对的,万一返回的值不连续,就不能BETWEEN,IN可以

------解决方案--------------------
可以用in 也可以用法exists
------解决方案--------------------
select t2.* from tb_table2 t2 left join tb_table1 t1 on t2.price=t1.par where t1.id=1 and t1.parice between 100 and 500
------解决方案--------------------
来晚了,呵呵
------解决方案--------------------
来晚了,呵呵