0
我需要插入@t
總的行數,如果@total
等於1SQL表中的計算,從臨時表中的總行值函數
我怎麼能這樣做?
ALTER FUNCTION [dbo].[myfunction]
(
@ID int = NULL,
@years int = NULL,
,@total BIT = 0
)
RETURNS @t TABLE (
RowNum int,
ID int,
years int,
)
AS
BEGIN
INSERT INTO @t
SELECT
ROW_NUMBER() OVER(ORDER BY years) AS RowNum,
ID,
years,
FROM dbo.mytable
WHERE ..
RETURN
END
結果的外觀應該是:
Total RowNum ID year
-------------------------------------
3 1 101 2014
3 2 102 2015
3 3 103 2016
謝謝!
非常感謝! –