調用UDF像這樣:TVF UDF不返回相同的數據作爲SELECT
SELECT
product_name,
SUM(quantity) AS SumQty,
SUM(face_value) AS SumFaceValue,
SUM(net_cost)AS SumNetCost,
SUM(face_value - net_cost) AS SumScripRebate,
organization_name
FROM getSalesSummary(@GLSCOrgId, @BeginDate, @EndDate) getSalesSummary
GROUP BY product_name, organization_name
ORDER BY product_name
收率:
"Chili's 1 25.00 22.75 2.25 Sample Organization 1
CVS/pharmacy 1 25.00 23.50 1.50 Sample Organization 1
Macy's 1 100.00 90.00 10.00 Sample Organization 1"
使用UDF邏輯和測試結果與SELECT:
SELECT
product_name,
SUM(quantity) AS SumQty,
SUM(face_value) AS SumFaceValue,
SUM(net_cost) AS SumNetCost,
SUM(face_value - net_cost) AS SumScripRebate,
organization_name
FROM @ReturnTable
GROUP BY product_name, organization_name
ORDER BY product_name
收益率:
"Chili's 4 100.00 91.00 9.00 Sample Organization 1
CVS/pharmacy 1 25.00 23.50 1.50 Sample Organization 1
Macy's 1 100.00 90.00 10.00 Sample Organization 1"
@ReturnTable是由UDF返回的表,並創建像這樣:
INSERT INTO @ReturnTable(product_name,
unit_price,
quantity,
face_value,
net_cost,
organization_name)
(select * from @TablePartial UNION select * from @TableClosed)
與SELECT和變量是返回正確的數據,但在調用UDF沒有得到與其他3個池莉測試記錄。我正在使用相同的參數數據。我對UDF很陌生,我不確定它爲什麼會返回與SELECT不同的數據。任何建議和/或答案?
U可以生成表格,數據和功能的腳本和在這裏發佈它可以給更多的想法 – Thakur 2010-09-29 14:24:13