0
我有以下SQL:我應該在哪裏放置IF塊SQL命令
DECLARE @ActualFromDT DATETIME,
@ActualToDT DATETIME
IF (ManPowerUsage.FromDT >= Shift.FromDT)
SET @ActualFromDT = ManPowerUsage.FromDT
ELSE
SET @ActualFromDT = Shift.FromDT
IF (ManPowerUsage.ToDT <= Shift.ToDT)
SET @ActualToDT = ManPowerUsage.ToDT
ELSE
SET @ActualToDT = Shift.ToDT
SELECT Shift.ShiftID,
Line.Line,
(SELECT SUM(DATEDIFF(MINUTE, @ActualFromDT, @ActualToDT))
/DATEDIFF(MINUTE, Shift.FromDT, Shift.ToDT)
FROM ManPowerUsage
WHERE ManPowerUsage.LineID = Line.LineID
AND ((Shift.FromDT < ManPowerUsage.FromDT AND Shift.ToDT > ManPowerUsage.FromDT)
OR (Shift.FromDT < ManPowerUsage.ToDT AND Shift.ToDT > ManPowerUsage.ToDT ))
AND ManPowerUsage.IsEdited = 0
) AS ActualManpower
FROM ......
的命令顯然是行不通的,但我想知道我怎麼去了解我之前設置的參數做DATEDIFF
s