Skip to main content

All Questions

-1 votes
1 answer
125 views

Recursive CTE and performance issue when anchor member is a large table

I have made some edits so that the post is clearer. I have a large table with data like below. The goal is to be able to retrieve the original ID and location associated with the original ID given ...
T340B's user avatar
  • 55
0 votes
2 answers
213 views

Update chain of rows in which each row will affect next one through a computed column

In a banking DB we want to hold the transactions and remainder amount of accounts after each transaction in a table named 'Operation' like this: CREATE TABLE Operation ( Id int PRIMARY KEY, ...
HamedH's user avatar
  • 3,293
1 vote
1 answer
139 views

Is recursive variable self-assignment valid?

I found some T-SQL code, and i'm trying to figure out if it is: an elegant solution that i never knew about a horrible abomination that happens to work, and should absolutely be removed or somewhere ...
Ian Boyd's user avatar
  • 258k
0 votes
1 answer
114 views

Types don't match between the anchor and the recursive part in column "manager_name" of recursive query "manager"

I always get the error Types don't match between the anchor and the recursive part in column "manager_name" of recursive query "manager". on the following query, even when ...
Pedro Paixao's user avatar
-1 votes
2 answers
189 views

T-SQL - Update rows with calculated values from previous rows

I need to create a dataset that calculates values using results from the previous row, but only the first row contains an actual value. This is my dataset: DROP TABLE IF EXISTS #tmp CREATE TABLE #tmp (...
Rob Ong's user avatar
  • 11
0 votes
1 answer
65 views

Recursive Where Clauses SQL CTE Query

I'm having trouble making the use of a iterative SQL script. What I need is to calculate inventory of documents of every month, but I'm not able to iterate over the where clauses, what I need is to ...
Richard Steefanhöffen's user avatar
-5 votes
1 answer
1k views

How to put a CTE as a subquery

In SQL Server, I have a CTE and a select statement. The CTE looks like WITH Recursion AS ( SELECT Value, GroupID, Type FROM @GroupMembership WHERE GroupID = @requestingGroupID UNION ...
omega's user avatar
  • 44.1k
-1 votes
1 answer
225 views

SQL Data Hierarchy Mapping

The first data table shows the hierarchy structure and Im trying to show how each level relates to all the children underneath. The output I'm looking for is the second table. Any pointers of how to ...
Twiss's user avatar
  • 13
1 vote
1 answer
595 views

Recursive Sum of each level in SQL Server 2017

I need to find out the recursive sum of each node of a tree. Please find the image below. Here the number(assuming no of sales made) in blue is the sum of Parent Quantity + Sum of its children and ...
Amit Ranjan's user avatar
1 vote
2 answers
112 views

Latest Available Holdings by Quarter

I'm hoping for a fix to this that doesn't use a cursor (unless necessary). We receive holdings submissions from our Investments quarterly. They are loaded by Reference Date, Investment, Holding and ...
Jay's user avatar
  • 33
0 votes
2 answers
606 views

Bottom Up Recursive SUM (lowest level only has values)

I have a tree-based structure of SKUs within a Product Hierarchy in SQL Server. The lowest level SKUs will only ever have values (these are consumption values). I then want to generate aggregates up ...
anderly's user avatar
  • 695
1 vote
1 answer
645 views

Recursive SQL query (parent-child) to include total downline records per record

I have a table that has a parent - child structure. I managed to bring this structure sorted by creating a field called "Path" with the first name of the agent, so this query: WITH cte(...
Danielle's user avatar
  • 1,506
0 votes
2 answers
526 views

Query with row by row calculation for running total

I have a problem where jobs become 'due' at the start of a week and each week there are a certain number of 'slots' available to complete any outstanding jobs. If there are not enough slots then the ...
JHW's user avatar
  • 136
4 votes
3 answers
10k views

Recursive query with parent-child relation

I am trying to make a recursive query in SQL Server, that display data hierarchically. Here is the structure of the table [id] [int] IDENTITY(1,1) NOT NULL, [name] [varchar(100)] NOT NULL, ...
the smart life's user avatar
0 votes
0 answers
81 views

SQL Recursive get next algorithm not working properly

Trying to make a get next recursive algorithm in stored procedure. I am having a bit of difficulty however. The condition part sometime may select multiple result - if that is the case I want it to ...
rhin's user avatar
  • 1

15 30 50 per page
1
2 3 4 5
9