我有一个存储过程尝试将函数中的记录插入表中。当我运行存储过程时,它成功完成,但不会在表中插入任何记录。如果我突出显示插入代码,它可以工作。我对这一切都很陌生,并希望得到任何帮助。
The Stored Procedure is:
ALTER PROCEDURE [dbo].[DataQualityDashboard_UpdatePart1]
AS
DECLARE @StartDate date
DECLARE @EndDate date
SET @StartDate = '2017-01-01'
SET @EndDate = '2017-01-31'
Insert into [iCS.Warehouse3].[dbo].[DashboardData]
Select
MetricID
, FirstDateofMonth
, Numerator
, Denominator
From [iCS.Warehouse3].[KPI].[DataQualityEthnicityOutpatientsWCFT]
(@StartDate, @EndDate)
Commit;
它所调用的函数是[iCS.Warehouse3]。[KPI]。[DataQualityEthnicityOutpatientsWCFT],如下所示。
ALTER FUNCTION [KPI].[DataQualityEthnicityOutpatientsWCFT]
(
@StartDate date
, @EndDate date
)
RETURNS TABLE
AS
RETURN
(
WITH EthnicityOutpatients (XCN, EthnicGroup, FirstDateOfMonth, MetricID)
AS
(
SELECT
o.XCN
,p.EthnicGroup
,DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0) as FirstDateOfMonth
,1 as MetricID
FROM [iCS.Warehouse3].[OP].[Appointments] o
Inner Join [iCS.Warehouse3].[lk].[Patient] p
on o.[XCN] = p.[XCN]
Inner Join [iCS.Warehouse3].[lk].[Calendar] cal
on o.AppointmentDate = cal.TheDate
Inner Join [iCS.Warehouse3].[dbo].[LocationLK] l
on o.ClinicLocation = l.Location
WHERE o.AppointmentDate >= @StartDate and o.AppointmentDate <= @EndDate
and o.AppointmentStatus = 'A'
and o.Specialty not in ('NR', 'NPH')
and l.WCFTorSatellite = 'WCFT'
)
SELECT
FirstDateOfMonth
, MetricID
, COUNT(CASE WHEN EthnicGroup is null THEN 1 END) as Numerator
, COUNT (XCN) as Denominator
FROM EthnicityOutpatients
GROUP BY
FirstDateOfMonth
, MetricID
)
它应该将记录插入的表是[iCS.Warehouse3]。[dbo]。[DashboardData]。
它有四个字段:MetricID,Date,Numerator和Denominator。
任何帮助都将非常感谢。 提前谢谢,安德鲁。