Relative Content

Tag Archive for sqlsql-servercommon-table-expression

Understanding performance lag on a simple cte

I am trying to calc carryover of PTO hours from one year to the next. In order to do this, I need to know the previous year’s “remaining balance”, which requires knowing the previous year’s Hours Used AND the previous year’s Carryover. This puts me in a “turtles all the way down” scenario, where I need to reference (prior) carryover in order to calc (current) carryover, going back forever.

Create a Task Sheet By CTE

In SQL Server I have a table named task with columns: task_id, task_name, task_weight, task_parent. the task_parent column is a foreign key which may be null or be related to another task_id in this table. I want to write a CTE to show tasks in a sheet like MS Project where task_weight of atask row with some recursive children, is summarized from its children and level of each child is calculated based on its recursive parents. Each child may have another child and so on. So consider this to calculate top level weight.