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

asked on

Sql Query

Hello,
I have a sql query

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

SELECT GuestName, ArrivalDate, DepartureDate 
FROM CORRESPONDENCE
WHERE (ArrivalDate >= '2016-01-01'
       AND (DepartureDate >= @Last_Friday)
       AND (ArrivalDate >= @Last_Friday AND ArrivalDate <  @This_Friday)
    OR (ArrivalDate < @Last_Friday AND DepartureDate >= @This_Friday))

Open in new window


Please refer :

https://www.experts-exchange.com/questions/28994771/Sql-query.html

https://www.experts-exchange.com/questions/28995976/Sql-Query.html

Needed change is
There is one more field Extented  .
Now if the extended has a date in it then the departure date is replaced by 'Extended'.

Any suggestions are welcome
SOLUTION
Avatar of Nakul Vachhrajani
Nakul Vachhrajani
Flag of India 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
ASKER CERTIFIED SOLUTION
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
Avatar of RIAS

ASKER

Vitor,
Do you say Nakul's solution will not work?
Do you say Nakul's solution will not work?
No. I'm sure it will work.

I just gave an alternative in case you do not want to use the ISNULL function since it may have performance impact if the Extended date is indexed.
Avatar of RIAS

ASKER

Cheers!