Skip to content

Tag: sql-server

Determining what index to create given a query?

Given a SQL query: How do you determine what index to write to improve the performance of the query? (Assuming every value to the right of the equal is calculated at runtime) Is there a built in command SQL command to suggest the proper index? To me, it gets confusing when there’s multiple JOINS that us…

Migrate columns to JSON in SQL

I have a table (Table A) that looks like this: I want to convert it to a table (Table B) like this How do you insert/transform into a json column? Or do I just have to construct the json string myself? Additionally, does the nullableness of the int columns affect creation? Are clicks for example not included …

Select from dynamic table

I need to run a query in sql that depending on the month and year I need to call a different table. For example: If current_date is 31/08/2020, execute: select * from table_ago If current_date is 01/09/2020, execute: select * from table_sep Is it posible using a query in SQL Server? Answer You can use a store…

Get users attendance entry and exit in one row SQL Server

I have a table with all entries for employees. I need to get all the working hours and the entry and exit time of the user in one record. The table is like this: How can I do that and also in case there is some missing entries or exit. Like one employee will have entry with no exit in