Skip to content
Advertisement

Can this be done as a SQL VIEW

I have a SQL Server table of Customer’s Events:

There can be many EventTypes for the same customer in one day.

EventTypes are like

1 – CheckIn
2 – CheckOut
3 – ExamStart
4 – ExamEnd

Now I want to select Customers that are currently (today) on premises. That’s Clients who had checked in, but hadn’t checked out, no matter if they taking Exam currently or not. Can this be done as a SQL view, or do I have to write a stored procedure for that?

Advertisement

Answer

You want today. So I would suggest not exists:

You can easily incorporate this into a view.

Note: date/time functions are notoriously database specific, so the exact syntax for “today” may vary.

EDIT:

In SQL Server, this can be written as:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement