ご迷惑をおかけして申し訳ありません。クライアントの場所でコードレビューを担当しましたが、発行されたラップトップにSQLがインストールされていません。インストールが行われるのを待っている間、コードを見るのに忙しくなりたくて、この宝石に出くわしました
CREATE FUNCTION [dbo].[Uf_GetTotalDaysInMonth]
(
-- Add the parameters for the function here
@anydateofMonth datetime
)
RETURNS int
AS
BEGIN
-- Declare the return variable here
DECLARE @totalDaysInMonth int
-- Add the T-SQL statements to compute the return value here
DECLARE @givendate datetime
SET @givendate = STR(Year(@givendate)) + '-' + STR(Month(@givendate) + 1) + '-01'
select @totalDaysInMonth = datepart(dd, dateadd(day, -1, @givendate))
-- Return the result of the function
RETURN @totalDaysInMonth
END
不必要な余分な変数の使用を無視すると、この関数は12月にクラッシュすると思います
STR(Month(@givendate) + 1)
13と評価され、範囲外の日付エラーが発生します。誰かが私のためにこれを検証してくれませんか?