T-SQL Trigger – Audit Column Change

Given a simple table, with an ID what is the correct way to audit a column being changed. I am asking after looking after various answers which seem not to be working. Here is what I have: Create …

SQL Subquery within a subquery [closed]

I am writing a nested SQL where I need to have a subquery within a subquery Let’s say I am trying to retrieve a row from ORDERS that matches MAIN_ID from SOURCE that matches MODULE from MODULES. …

Calculate cumulative product value

I have the following database table: Date Return Index 01-01-2020 0.1 Null 01-02-2020 0.2 Null 01-03-2020 0.3 Null I would like to update the Index value using the following …

Calculate cumulative value in update query using SQL

I have the following database table: Date Return Index 01-01-2020 0.1 Null 01-02-2020 0.2 Null 01-03-2020 0.3 Null I would like to update the Index value using the following …

Create Continuous Enrollment islands for a certain sub-population

My end goal is to create islands of continuous enrollment days for each CLIENTID for a single sub-population: ‘Adult Expansion’ for calendar years 2019 and 2020. A CLIENTID can be associated with …

Split string without string_split (Sever 2012) [closed]

I would like to know if and if it’s possible how to split a string in to different columns. So first of all I have the table tabOld which contains: name 5522-rep__-4210-03-test-434907-emn-nt.pdf …

Group by Count of DateTime Per Hour by removing Duplicates?

I have a table named loginData: userName timestamp abc ‘2007-01-01 12:00:12 AM’ def ‘2021-01-01 12:09:12 AM’ abc ‘2021-01-01 12:40:12 AM’ abcde ‘2021-01-01 12:44:12 AM’ From this …

Create calculated field from MIN() and MAX() values of another column, grouped by unique ID

I have a table that looks like this, containing information about an object’s position and the length of time it existed for (age): Date ID Age x y 2021-03-25 20 1 531 295 2021-03-25 20 …

Subtotal of child records without COUNT?

ParentSub Table: ParentCode SubCode CompanyName MEGA1 MEGA1 Megacorp MEGA1 SUBC1 Subsidiary Company MEGA1 EASC1 East Coast Operations MEGA1 EURC1 Europe Company BIGLY ALPH1 Alphabet Company …

SQL – % Breakout by Hour

I’m trying to write a query that will break out what percentage of time is utilized within a hour given a time range. Sample data: declare @date table(id int, Start_time time, End_time time) …