Posts

Showing posts from February, 2021

MS SQL server: CTE example

During one of my assignments I was asked to make a production report with the number of produced articles during a batch distributed evenly per hour between batch start and end. This is how I solved it with a cursor and cte (common table expression) --Variables DECLARE             @BatchID int ,             @startTime datetime ,             @stopTime datetime ,             @diffHours int ,             @Article int ,             @prodAmount int ,             @theRest int ,             @ProdLine int ,             @endDiff int ,             @amount int               - -Fetch the data             DECLARE prod_Cursor CURSO...