Amending a query to show date before but not date after

Will Faulkner 201 Reputation points
2021-06-17T06:33:32.29+00:00

Hello

I have a simple report, written for a specific group of people, that shows the volume of telephone calls completed by people within certain dates.

The specific group of people are gathered within the script using IN, so for example:

SELECT name, callcompleted, date
from table
WHERE name IN ('william faulkner', 'richard ford')
And date between @datea and @dateb

This gives an output:

william faulkner y 16/6/21
richard ford y 15/6/21 etc

My issue is that one of the people - say richard ford - left the group on 1/6/21 for another group and so still works for the same company, uses the same database and so his calls still appear in the above report. I want his calls excluded from the report from 1/6/21

Is it possible to amend the query above to continue to show the output of william faulkner but to exclude the output of richard ford after 1/6/21 - but still include the input of richard ford before 1/6/21?

any suggestions advice would be very helpful - thanks

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,620 questions
0 comments No comments
{count} votes

Accepted answer
  1. EchoLiu-MSFT 14,581 Reputation points
    2021-06-17T06:39:36.927+00:00

    Please try:

    SELECT name, callcompleted, date
    from table
    WHERE name IN ('william faulkner', 'richard ford')
    And date between @datea and 1/6/21
    union all
    SELECT name, callcompleted, date
    from table
    WHERE name IN ('william faulkner','other')--Exclude richard ford
    And date between 1/6/21 and @dateb
    

    If you have any question, please feel free to let me know.

    Regards
    Echo


    If the answer is helpful, please click "Accept Answer" and upvote it.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.