四级数据库 答案 2010
(3)create proc p3
@lb varchar(20),@sum money output as
if exists(select * from able_GoodsClass where GoodsClassName = @lb) select @sum = sum(PayAmount) from Table_SaleBill a join Table_SaleBillDetail b on a.SaleBillID = b.SaleBillID join Table_Goods c on c.GoodsID = b.GoodsID
join Table_GoodsClass d on d.GoodsClassID = c.GoodsClassID where GoodsClassName = @lb else
print '不存在指定类别的商品' (4)create proc p4
as
update Table_SaleBillDetail set Discount = case when c.Score > 10000 then 0.8
when c.Score between 5000 and 10000 then 0.9 when c.Score between 1000 and 4999 then 0.95 else 1 end
from Table_SaleBillDetail a join Table_SaleBill b on a.SaleBillID = b.SaleBillID join Table_Card c on c.CardID = b.CardID 13.3 答案
(1)create function dbo.f1(@lb varchar(20), @nf int)
returns int as
begin
declare @sum int
select @sum = sum(Quantity) from Table_SaleBillDetail a join Table_SaleBill b on a.SaleBillID = b.SaleBillID join Table_Goods c on c.GoodsID = a.GoodsID
join Table_GoodsClass d on d.GoodsClassID = c.GoodsClassID where GoodsClassName = @lb and year(SaleDate) = @nf return @sum end
(2)create function dbo.f2(@addr varchar(20))
returns int as
begin
declare @count int
select @count = count(*) from Table_Card a join Table_Customer b on a.CardID = b.CardID where address = @addr and State = '2' return @count end