Skip to content

Instantly share code, notes, and snippets.

@bonskijr
Last active September 8, 2017 13:53
Show Gist options
  • Select an option

  • Save bonskijr/746c639c3c987595f23e67b3b88fcfc2 to your computer and use it in GitHub Desktop.

Select an option

Save bonskijr/746c639c3c987595f23e67b3b88fcfc2 to your computer and use it in GitHub Desktop.
sample temp table
SELECT row_number() over (order by (select null)) as RowId,
FileName,
ItemId
INTO #result
FROM cm_steps
DECLARE
@i int, @max int,
@parentId int,
@itemId int;
SELECT @i = MIN(RowId) , @max=MAX(RowId) FROM #result;
WHILE (@i <= @max )
BEGIN
SET @ItemId = ( SELECT ItemId FROM #result WHERE RowId = @i );
-- get parentId
SET @parentId = ( SELECT parentId FROM cm_Cases WHERE ItemId = @itemId )
.. so on and so forth
SET @i = @i+1;
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment