?? 119.sql
字號:
create function jiner(@玩具號 char(20),@數量 int)
returns money
as
begin
declare @jiner money
select @jiner=價格 from 玩具 where @玩具號=玩具號
return @玩具號 * @數量
end
select dbo.jiner('00001',2)
create function orderstable (@orderid char(10))
returns table
as
return (select 定單號,dbo.玩具.玩具號,購買數量 from dbo.定單詳情 ,dbo.玩具
where dbo.定單詳情.玩具號 = dbo.玩具.玩具號 and 定單號 = @orderid)
select * from orderstable('000001')
Create Function GetToyQty(@toytype char(3))
returns @return Table
(類型 char(4),玩具名 varchar(20),銷售數量 smallint)
as
begin
insert into @return select '進貨',玩具名,sum(銷售數量) from 玩具 a inner join
月銷售情況 b on a.玩具號 = b.玩具號 where a.類別號=@toytype group by 玩具名
insert into @return select '銷售',玩具名,sum(數量+銷售數量) as 進貨數量 from 玩具 a inner join
月銷售情況 b on a.玩具號 = b.玩具號 where a.類別號=@toytype group by 玩具名
return
end
go
---調用函數
select * from GetToyQty('001') order by 玩具名
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -