Link to home
Start Free TrialLog in
Avatar of RIAS
RIASFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Sql query with where clause

Hello,
I have a sql query need to add a where clause.

DECLARE @Last_Friday AS DATE = '2017-02-07'
DECLARE @This_Friday as date = '2017-02-17'

SELECT GuestName, ArrivalDate, 
       CASE
              WHEN Extendedto IS NULL THEN DepartureDate
              ELSE Extendedto
       END AS DepartureDate
FROM CORRESPONDENCE
WHERE (ArrivalDate >= '2016-01-01'
       AND (
              (Extendedto IS NULL AND DepartureDate >= @Last_Friday)
              OR Extendedto >= @Last_Friday
              )
       AND (ArrivalDate >= @Last_Friday AND ArrivalDate <  @This_Friday)
    OR (ArrivalDate < @Last_Friday 
              AND (
                     (Extendedto IS NULL AND DepartureDate >= @This_Friday)
                     OR Extendedto >= @This_Friday
                     )
              )
       )

Open in new window

Where clause to be added is :

WHERE ( DeleteRecord is null or DeleteRecord = 0)'
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RIAS

ASKER

Cheers!