0
所以我有這個公式需要一個公式來找到年份和季度在SQL
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- This function takes a qtr (yyyyq), and adds the number of qtrs, and returns the future qtr
--e.g. FutureQtr (20154,7) returns 20173
CREATE FUNCTION [dbo].[FutureQtr_fn] (@StartQtr int,@AddlQtrs int)
Returns int
AS BEGIN
RETURN
(@StartQtr/10*10)+ -- Current Year (yyyy)
((@StartQtr%(@StartQtr/10*10) [email protected] - 1)/4)*10 -- add'l years (n0)
+(@StartQtr%(@StartQtr/10*10) [email protected])%4 + 1 -- new qtr (n)
END
GO
我想創建一個名爲dbo.GetPastQtr_fn
新的公式,我希望它產生相同的結果。
但是不寫select dbo.FutureQtr_fn (20154,7) -> 20173
我想寫dbo.GetPastQtr_fn (20154,7)
,這將給我20141
。
因此它下降!