Skip to content
Advertisement

How to exclude a specific row from an SQL Count

I need to exclude a certain row from a COUNT in SQL Server. This is what I have:

If I remove the last AND GuestStayDetails.GuestId != @GuestId; it gives me the expected COUNT however I must exclude one of the GuestIDs. Any suggestions?

Advertisement

Answer

It looks like you are looking for overlapping time intervals — as well as your parentheses problem. If that is the case, you can significantly simplify the query:

This eliminates the need for any parentheses at all.

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