uj5u.com熱心網友回復:
確定要用函式(function)實作嗎?uj5u.com熱心網友回復:
CREATE FUNCTION [dbo].fn_Shortage()
RETURNS @tblShortage TABLE ( so varchar(20),
name nvarchar(20),
fqty int,
欠料 int)
BEGIN
;with cte_Inventory as (
Select 'TS-1' as so,N'繼電器' as name,100 as fqty union
SELECT 'TX-0' as so,N'硬碟' as name,2 as fqty),
cte_IssueMaterial as (
Select 'TS-1' as so,N'繼電器' as name,200 as fqty union
SELECT 'TF-2' as so,N'繼電器' as name,300 as fqty )
INSERT INTO @tblShortage
Select a.so,a.name,a.fqty,(isnull(b.fqty,0)-a.fqty) as '欠料'
From cte_IssueMaterial a
Left Join cte_Inventory b on a.so=b.so
RETURN
END
GO
Select * From [dbo].fn_Shortage()
uj5u.com熱心網友回復:
這只是個列子,實際資料庫資料量很大轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/79053.html
標籤:疑難問題
上一篇:男朋友
下一篇:有沒有會在線回去鄉鎮地圖的?
