【发布时间】:2021-11-11 14:02:45
【问题描述】:
当传递的参数为空时,我正在尝试为存储过程分配值。
如果 startDate 或 endDate 为空,我想给它们赋值
喜欢
@StartDate = '1990-01-01'
@EndDate = DATEADD(YEARS, 30, GETDATE()) -- 30 years from now.
我该怎么做?
CREATE OR ALTER PROCEDURE dbo.GetByProductID
(
@ProductID INT,
@StartDate DATETIME = NULL
@EndDate DATETIME = NULL
)
AS
SELECT ProductId, Name, InsertedDate, UpdatedDate
FROM Products
WHERE ProductId = @ProductID
AND InsertedDate > @startDate
AND UpdatedDate < @EndDate
【问题讨论】:
标签: sql sql-server stored-procedures