I need help to develop the proposed task: I need to count the current month active employees and then generate a “forecast” for the next six months, the forecast is just the last total active from the current month over the next six months, just changing the date value on the result. Expected Result: Date_Active Location Total_Active Forecast 2021.04 127
Tag: sql-server-2016
Get rows of Last hour, Last ‘x’ minutes in SQL Server
Order ID Picker ID Time_Picked 1 111 2020-01-13 11:28:00 2 222 2020-01-13 11:40:00 3 333 2020-01-13 10:00:00 4 444 2020-01-13 9:00:00 5 555 2020-01-13 9:45:00 SELECT * FROM mytable WHERE …
Splitting up events that occur over the day boundary
I have a table of events with a start time and an end time, with some events that have a start time before midnight and an end time after midnight. I’d like to produce output that splits up these events at the midnight barrier so they can be counted toward their respective date. The above table could be produced by
Dynamic SQL mistakenly looks for table variable
my code accepts table name parameters and my dynamic code is supposed to query a table. I consistently get the error: @sourcetbl variable must be declared. After a lot of troubleshooting, I realized …
Creating a SQL Loop to Change the Table Name
I am needing to change the ending number of the table name in a loop to go from 1 through 12. This is a more straight forward example of my actual problem, but if this can be solved, then I can duplicate the results later on (Actual problem is using the past 12 months on a rolling basis for a
Append data from one table to another table
I have a Destination table with 3 columns, ID, Name, Source. I have 10+ Source tables, each with multiple columns, but I only require the ID, Name, and the table name itself to be appended into Destination table. Do note the naming of the column names are different in each table, but the required ID and Name are of the
Concatenate or merge many columns values with a separator between and ignoring nulls – SQL Server 2016 or older
I want to simulate the CONCAT_WS SQL Server 2017+ function with SQL Server 2016 version or older in order to concatenate many columns which values are strings like that: Input: Output: Notice that the output result is a new column that concatenate all values separated by ‘|’. The default value should be NULL if there are no values in the
Sql Server Global Blocked List and Item specific Allow List
This seems easy at first but after thinking about it for the day I’m stuck. Imagine you have a global block list for veggies. create table blocked_veggie(veggieid int primary key, veggiename varchar(…
SQL Server: NULL or empty string?
I have a a database column whose value is determined programmatically and is not affected by user input. The value is never an empty string; it’s either NULL or a non-0 length string. The column is …
Finding whether duplicates exists in 2 select statements
Could you please help me with SQL statement to find duplicate names present in first Select statement and the second. For example : I need to find whether student with same name in Class 1 is present or not in Class 2 or 3. and Second select statement is : If there is matching occurrences for any name then I