【发布时间】:2014-07-22 12:20:12
【问题描述】:
您好,我的存储过程添加了“NULL”而不是数字
那么为什么下面的过程会添加 'NULL' 而不是 0 到无穷大之间的值呢?
这是我的程序
ALTER PROCEDURE [dbo].[Plan_Abschluss]
-- My parameters for the stored procedure
@date AS datetime2(7),
@Einrichtung AS Int,
@Mitarbeiter AS Int
AS
BEGIN
-- declare my parameters
DECLARE @PlanStunden AS decimal(18, 2)= null,
@PlanUrlaub AS Int= null,
@oldDate AS datetime2(7)= null,
@oldUrlaubskonto AS Int= null,
@oldStundenKonto AS decimal(18, 2)= null;
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- set the previous month
SET @oldDate= DATEADD(month, -1, @date);
-- get some values from the previous row and set it to my parameters
SELECT @oldUrlaubskonto = ISNULL(CurrentUrlaubskonto,0) ,
@oldStundenKonto = ISNULL(CurrentStundenKonto,0)
FROM [Plan]
WHERE [Jahr] = YEAR(@oldDate)
AND [Monat] = MONTH(@oldDate)
AND [RefMitarbeiterId] = @Mitarbeiter
AND [RefEinrichtungId] = @Einrichtung;
-- get some values from the row i want to update and set it to my parameters
SELECT @PlanStunden = ISNULL(PlanStunden,0) ,
@PlanUrlaub = ISNULL(PlanUrlaub,0)
FROM [Plan]
WHERE [Jahr] = YEAR(@date)
AND [Monat] = MONTH(@date)
AND [RefMitarbeiterId] = @Mitarbeiter
AND [RefEinrichtungId] = @Einrichtung;
-- update the row and do a calculation with my parameters
UPDATE [Plan]
SET Abgeschlossen = 1,
CurrentUrlaubskonto = @oldUrlaubskonto+ @PlanUrlaub,
CurrentStundenKonto = @oldStundenKonto+ @PlanStunden
WHERE [Jahr] = YEAR(@date)
AND [Monat] = MONTH(@date)
AND [RefMitarbeiterId] = @Mitarbeiter
AND [RefEinrichtungId] = @Einrichtung
END
【问题讨论】:
-
NULL设置了哪些值? -
@GordonLinoff CurrentUrlaubskonto 和 CurrentStundenKonto
标签: sql stored-procedures sql-update declare