請幫幫忙,我怎麼能在Where
條款如何使用IF語句或案例時,WHERE子句中SQL
這是我的代碼的一部分,我收到錯誤,但是我插入If
或Case When
插入If
或Case
。
這是錯誤消息156,級別15,狀態1,過程P5,35號線
關鍵字附近有語法錯誤 '之間'
AS
WITH
t1 AS (SELECT 0 n UNION ALL SELECT 0 n UNION ALL SELECT 0 UNION ALL SELECT 0)
,Calendario AS (SELECT DATEADD(day, (ROW_NUMBER() OVER (ORDER BY a.n)), @CheckIn) AS Fetcha
FROM t1 a, t1 b, t1 c, t1 d, t1 e, t1 f)
SELECT @noches= convert(int,@Checkout - @CheckIn), @Sum = SUM(dbl*@canthabdbl),@SumSGL = SUM(SGL*@canthabsgl), @SumTPL = SUM(isnull(Triple,0)*@canthabtpl),@SumCUAD = SUM(isnull(Cuad,0)*@canthabcdpl),@SumChd = SUM(isnull(Chd,0)*@cantchd), @totalhab = (@[email protected][email protected][email protected][email protected]), @average = (@totalhab/@noches)
FROM hotelsnew
JOIN Calendario ON
Calendario.Fetcha BETWEEN Desde AND Hasta+1
WHERE
CASE WHEN @checkout>hasta THEN
Calendario.Fetcha BETWEEN @CheckIn+1 AND @CheckOut-1
AND Hoteles = @IDHotel AND tipohabitacion = @IDTipo AND Id_plan = @IDPlan
ELSE
Calendario.Fetcha BETWEEN @CheckIn AND @CheckOut
AND Hoteles = @IDHotel AND tipohabitacion = @IDTipo AND Id_plan = @IDPlan
END
RETURN
確實看起來像t-sql –