[英]How to JOIN table-valued functions?
在下面,我想通过udf_SlipSerials加入股票交易,该股票交易返回股票序列和股票ID; 我该如何实现?
ALTER VIEW [dbo].[vStockSerials]
AS
SELECT distinct sa.Oid as Id,it.Oid as StockOid, wh.Oid as WarehouseOid, udf.serial,
it.Code as StockCode,sa.ActionPrice,it.Code+' '+it.Title as StockName, it.Title as StockTitle,wh.Title as Warehouse,
sa.SlipDate,sa.IsSlipDeleted,sst.ActionType,
sa.SlipType
FROM dbo.StockAction as sa
INNER JOIN dbo.Item as it ON sa.Stock=it.Oid
INNER JOIN dbo.EnterpriseCore as wh ON sa.Warehouse=wh.Oid
INNER JOIN dbo.Stock as s ON sa.Stock=s.Oid
LEFT OUTER JOIN
(
SELECT CONVERT(uniqueidentifier, st.Oid) as SlipType,
(case st.StockEffect
when '1' then
'Income'
when '2' then
'Expense'
end) as ActionType
FROM dbo.StockSlipType as st
UNION
OUTER APPLY udf_SlipSerials(sa.SerialNos,sa.Stock) as udf
GO
SELECT distinct
sa.Oid as Id
,it.Oid as StockOid
, wh.Oid as WarehouseOid
, udf.serial
,it.Code as StockCode
,sa.ActionPrice
,it.Code+' '+it.Title as StockName
, it.Title as StockTitle
,wh.Title as Warehouse
,sa.SlipDate
,sa.IsSlipDeleted
,sst.ActionType
,sa.SlipType
FROM dbo.StockAction as sa INNER JOIN dbo.Item as it
ON sa.Stock=it.Oid
INNER JOIN dbo.EnterpriseCore as wh
ON sa.Warehouse=wh.Oid
INNER JOIN dbo.Stock as s
ON sa.Stock=s.Oid
LEFT OUTER JOIN
(
SELECT CONVERT(uniqueidentifier, st.Oid) as SlipType,
case st.StockEffect
when '1' then 'Income'
when '2' then 'Expense'
end as ActionType
FROM dbo.StockSlipType as st
)Sub
ON s.Oid = Sub.SlipType --<-- Your are missing this join condition here I have only gussed
OUTER APPLY
dbo.udf_SlipSerials(sa.SerialNos,sa.Stock) as udf
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.