Skip to main content

All Questions

-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 ...
Zoro4246's user avatar
-1 votes
2 answers
281 views

Get the Whole List from a many to many relation [duplicate]

i have the following schema CREATE TABLE BookRelationship (Id int IDENTITY(1,1) PRIMARY KEY, Book1 nvarchar(50), Book2 nvarchar(50)) INSERT INTO BookRelationship (Book1,Book2) VALUES ('Book 42','...
Mariam Nagy's user avatar
0 votes
2 answers
491 views

T-SQL: Self-Referencing calculated field

I'm trying to calculate the daily total number of Day Trades based on an existing table that provides the cumulative number of Day Trades over a rolling five-day window (business days only). The data ...
tshobe's user avatar
  • 19
2 votes
1 answer
403 views

Use CTE Instead of Table Variable for Recursive Function

I am trying to create a loop that when given a part id, it will search a table of assembly parts and put all the parts into the return table. I.e. I want to explode the parts from a single part id. It ...
Dizzy49's user avatar
  • 1,530
0 votes
2 answers
336 views

Recursive CTE to populate latest available data across many quarters?

here is a sample dataset: CREATE TABLE UholdingsPE( Reference_Date DATE NOT NULL PRIMARY KEY ,Investment VARCHAR(14) NOT NULL ,Holding VARCHAR(9) NOT NULL ,Price INTEGER ...
Jay's user avatar
  • 33
0 votes
3 answers
302 views

Lazy upward recursive query in sql

I'm trying to generate a path from the name of an item's parents. For example if test has for parent dad the path would be dad/test; and if dad had for parent gran the path of test would be gran/dad/...
Hugo's user avatar
  • 479
-1 votes
1 answer
65 views

How can I select the top level of a hierarchical relationship in SQL?

I have a list of routines that need to be ran, and a table which defines whether a routine is dependent on the successful completion of other routines or not. So for example: | RoutineID | ...
Dan Scally's user avatar
  • 2,052
2 votes
2 answers
268 views

Recursive CTE (T-SQL) Returns Un-expected Result

I've been staring at this code for WAY too long, trying to figure out why my final query returns unexpected results. Any help would be much appreciated. Thanks in advance. Given the following code (...
katzbatz's user avatar
  • 365
0 votes
1 answer
655 views

TSQL recursive query help parent-child

I'm trying to build a t-sql query that will return parent and its child accounts in the same table based on a roll-up input. Can someone please assist? ***TABLE:USERS*** UserId ParentId 66 ...
ememgi79's user avatar
3 votes
1 answer
4k views

How to speed up a recursive CTE

Given the following recursive CTE (simplified a bit for my example): WITH myCTE (sort, parentid, myid, level, somedata) AS ( -- Anchor member definition SELECT CAST(ROW_NUMBER() OVER(...
Davio's user avatar
  • 4,747
3 votes
2 answers
3k views

Genealogy Tree in SQL Server

In my table each record has a pointer to his direct parent and I need to know how to query for all the descendants, direct or not (the son of a son), of a given record. Facts: I don't know how ...
Leonardo's user avatar
  • 11.4k
0 votes
3 answers
240 views

Aggregate survey results recursively by manager

I have a StaffLookup table which looks like this. UserSrn | UserName | ManagerSrn =============================== ABC1 | Jerome | NULL ABC2 | Joe | ABC1 ABC3 | Paul | ABC2 ABC4 ...
Ian Roke's user avatar
  • 1,784