我了解到某些版本的 Microsoft OLE DB Provider for SQL Server(主要在 Windows XP 上)不支持WITH
语句。因此,我决定将我的 SQL 语句移动到一个表值函数中,并从我的应用程序中调用它。现在,我被困住了。我应该如何使用该INSERT INTO
语句WITH
?这是到目前为止我提供的代码,但 SQL Server 不喜欢它...... :-(
CREATE FUNCTION GetDistributionTable
(
@IntID int,
@TestID int,
@DateFrom datetime,
@DateTo datetime
)
RETURNS
@Table_Var TABLE
(
[Count] int,
Result float
)
AS
BEGIN
INSERT INTO @Table_Var ([Count], Result) WITH T(Result)
AS (SELECT ROUND(Result - AVG(Result) OVER(), 1)
FROM RawResults WHERE IntID = @IntID AND DBTestID = @TestID AND Time >= @DateFrom AND Time <= @DateTo)
SELECT COUNT(*) AS [Count],
Result
FROM T
GROUP BY Result
RETURN
END
GO