如何在案例中嵌入和 if 语句。这就是我到目前为止所拥有的。
DECLARE @LDCCode as int
DECLARE @InvoiceDate as datetime
DECLARE @PaymentSemiMonthlyDays AS int
SET @LDCCode = 20
SET @InvoiceDate = '5/16/2012'
DECLARE @InvDateDayMonth AS INT
DECLARE @ReturnDate AS DATETIME
SET @ReturnDate = @InvoiceDate
DECLARE @PaymentDOM AS INT
DECLARE @PaymentDays AS INT
DECLARE @PaymentSemiMonthlyOffset AS INT
SET @ReturnDate = CASE WHEN NOT @PaymentDOM IS NULL THEN
@ReturnDate + (@PaymentDOM - DATEPART(day, DateAdd(mm,1,@ReturnDate)))
WHEN NOT @PaymentDays IS NULL THEN
DATEADD(Day,@PaymentDays,@ReturnDate)
WHEN NOT @PaymentSemiMonthlyOffset IS NULL THEN
IF @LDCCode = 40 AND @InvDateDayMonth > 11 AND @InvDateDayMonth < 26
SELECT @ReturnDate + (@PaymentSemiMonthlyOffset - DATEPART(day, DateAdd(mm,1,@ReturnDate)))
ELSE
SELECT @ReturnDate + (@PaymentSemiMonthlyDays - DATEPART(day, DateAdd(mm,1,@ReturnDate)))
END