sql语句用 case end 判断正负后给变量赋值问题
declare @AVAILABLE_STOCK int
select
@AVAILABLE_STOCK=
(case
when AVAILABLE_STOCK<0
then 0
else AVAILABLE_STOCK
end)
as [库存] from Table
请问我想用case end 判断数据库字段AVAILABLE_STOCK的正负结果赋值给变量@AVAILABLE_STOCK这句话这么改?请教!!!
[解决办法]
declare @a intdeclare @b intset @a=-3select @b=case when @a<0 then 0 else @a endselect @b as value/*value0*/--你这样不行吗??
[解决办法]
if object_id('[lsxf1988_Table]') is not null drop table [lsxf1988_Table]create table [lsxf1988_Table]([AVAILABLE_STOCK] int)insert [lsxf1988_Table]select -1 union allselect 9 union allselect 8declare @AVAILABLE_STOCK intset @AVAILABLE_STOCK=( select top 1 case when AVAILABLE_STOCK<0 then 0else AVAILABLE_STOCK end from [lsxf1988_Table])select @AVAILABLE_STOCK as [库存]/*库存-----------0*/