关于变量的求助
有表ZK
数量 折扣
2 10
4 15
6 20
当用户输入1时,就不带出折扣,当用户输入2时就带出折扣10.也就是说满足数量条件就带出相应的折扣
但是这个数量条件和折扣都是是不定的,经常会去变,所以我想把数量和折扣也做成变量,求高手指点
[解决办法]
if object_id('[ZK]') is not null drop table [ZK]gocreate table [ZK] (数量 int,折扣 int)insert into [ZK]select 2,10 union allselect 4,15 union allselect 6,20select * from [ZK]declare @i int set @i = 2select 数量,折扣 from ZK where 数量 = @i/*数量 折扣2 10*/
[解决办法]
declare @i int set @i=3if @i<2 select 1[数量],0[折扣]else if @i<4 select @i [数量],折扣 from zk where 数量=2else if @i<6 select @i [数量],折扣 from zk where 数量=4else select @i [数量],折扣 from zk where 数量=6
[解决办法]
declare @qty int,@discount intselect @qty=1;select @discount=isnull((select top 1 折扣 from 你的表 where t.数量<=@qty order by 数量 desc),0);select @qty 数量, @discount 折扣;