SQL Server

SQL case workweek

Is there another way of doing this like a loop or something?
Case
When Date >= ‘4/11/2021’ and Date < ‘4/18/2021’ then ‘WK5’
When Date >= ‘4/4/2021’ and Date < ‘4/11/2021’ then ‘WK4’
When Date >= ‘3/28/2021’ and Date < ‘4…

Row Number Based on Conditions

declare @delimiter nvarchar(2) = char(10);
declare @objectName sysname = ‘dbo.table_1;
———————————————————————————————–
with CTE as (

select
0 as line_number
, @obje…

Mapping All Terminal IDs to Previous IDs

I have a table in SQL Server that contains a list of all ID migrations overtime. An individual’s ID can change overtime, and this table helps us understand when the change occurs, and what the ID changes from/to. What I’d ultimately like i…