I have a WHERE clause that has a nested OR statement, as seen here: The @NeedsFollowUp, @NeedsInitialVacc, and @NeedsTraining variables are all set by the variables above. When one or more of these are set to “1”, the query should return employee entries that match the criteria inside their relate…
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…
Replace a recurring word and the character before it
I am using SQL Server trying to replace each recurring “[BACKSPACE]” in a string and the character that came before the word [BACKSPACE] to mimic what a backspace would do. Here is my current string: “This is a string that I would like to d[BACKSPACE]correct and see if I could make it %[BACK…
SQL some selections into one (or get two colums from one)
I use PostgreSql, I have two tables (for example) Let table1 will contain stores, there are 2 types ‘candy store’ and ‘dental store’. Each row contains information about a customer’s purchase in a …
how can i find unique conversation from table in sql
I Have this table: [Messages table] I need to find the number of uniqe conversation – conversation is define as senderid sent msg to reciverid, and reciverid has replied (no matter how many times or …
Inserting a generate_series select date statement into an array column
I have a Postgres table with a schema that looks like this – Table “public.nav_due_dates” Column | Type | Collation | Nullable | …
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-…