【SQL开源代码栏目提醒】:网学会员为需要SQL开源代码的朋友们搜集整理了013.sql相关资料,希望对各位网友有所帮助!
use db_Sql
GO
if exists(select * from INFORMATION_SCHEMA.TABLES
where table_name = 'tb_Sell01')
drop table tb_Sell01
GO
create table tb_Sell01--创建tb_Sell01数据表
(
药品编号 int identity(1001,1),
药品名称 varchar(20),
药品数量 float not null,
价格 float not null,
状态 varchar(20),
金额 AS(药品数量*价格)
)
GO
--向表中插入信息
insert into tb_Sell01 values('药品1','100','50','1')
insert into tb_Sell01 values('药品2','89','21','0')
insert into tb_Sell01 values('药品3','70','5','1')
GO
/*使用case关键字进行条件选择判断,case语句对销售信息(tb_Sell01)表,中的状态进行判断,药品当前的状态等于“1”,则显示“库存中有货!”,如果当前的状态等于“0”,则显示“库存中没有货!”*/
select 药品编号,药品名称,药品数量,价格,金额,状态=
case
when 状态='1' then '库存中有货!'
when 状态='0' then '库存中没有货!'
end
from tb_Sell01
GO