All Questions
Tagged with recursive-query t-sql
174 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 ...
-1
votes
1
answer
78
views
Extraction of Parents by hierarchy for employees using Azure Synapse Analytics
I am looking for a solution for the below situation:
I have to extract all the managers (by hierarchy) for some employees that i receive in the flow (we have a file that contains all the information ...
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,
...
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 ...
-1
votes
1
answer
239
views
Calculate the price of a product from a multilevel BOM
I'm not very advanced on sql, i read a lot about cte and recursive query to expand a bom but i still can't figure out how to solve my problem.
My table look like this:
DB_PARENT
DB_COMPONENT
DB_COEFF
...
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 ...
0
votes
1
answer
189
views
T-SQL JSON with Recursive hierarchal data but with joins
I found this link and it works as long as I don't join to other tables Generate nested nth level JSON SQL Server using recursive CTE
The problem is some of the data I need is via a join. The below is ...
-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 (...
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 ...
-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 ...
-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 ...
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 ...
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 ...
0
votes
2
answers
604
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 ...
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(...