Skip to content

Tag: sql-server

Calculating time with datetime values

I have two tables where one has tasks, other has actions. In the task table I have tasks that ha ID, start date (when the task was created) and end date (when the task was closed). In the action table I have actions that were done in the task table so it has ID, task_ID, action_ID and time of the

Problems finding out Active users due to Hire/Resign Date

In my Employee table in SQL Server I have two datetime columns: HiringDate and ResignDate. I want to create a new column Status (Active, Inactive) in a view. If HiringDate is NULL or greater than today = Inactive If HiringDate is Active but ResignDate is earlier than today then Status also have to be Inactive…

SQL Server Query filter with order is slow

I have been struggling with this for a while. I have a database with three tables (each of which has millions of records) as follows (removed some columns for simplicity): There exists indexes As follows To eliminate the possibility that the slowness is because of the selected columns, I only select a fixed v…