Skip to content

Loop to create new columns

Say that I have a SQL Server table which has 4 columns MonthEnd, Gender, Weight and Age. Now, the MonthEnd go from 201901 through 201912. I have a process where a run a query which generates a variety of metrics, for instance sum(Weight) and average(Age) for each month. Right now, I set a where MonthEnd = 201…

how to select rows with no null values (in any column) in SQL?

I have a table called table1 It has 100 columns: {col1, col2, …,col100} I understand how to SELECT rows not containing null values in a specific column for instance col1: How do I SELECT all rows that do not contain null values in any column Attempt but this returns an error in MySQL (which I am using) …

Count for each day return wrong value

The below code gives a count of 1 for each day, and accumulates from today (13/04/2021) til the end of the month and sums them for Saturdays, Sundays and Week days. ;WITH mycte AS ( SELECT …

Sum and segment overlapping date ranges

Our HR system specifies employee assignments, which can be concurrent. Our rostering system only allows one summary assignment for a person. Therefore I need to pre-process the HR records, so …

How to convert date format in Excel

When I pull out data using SQL query and copy and paste the date to excel it automatically bring AM or PM right next to original data. For example: 2021-04-11 11:45:00.000 (SQL data) –> 2021-…