Last active
August 29, 2015 14:27
-
-
Save warriorg/ecf95603747014391ab4 to your computer and use it in GitHub Desktop.
[sql]with tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH x AS ( | |
SELECT [TYPE_SID] | |
,[CATEGORY_SID] | |
,[APARTMENT_SID] | |
,[TYPE_NAME] | |
,[REMARK] | |
,[PARENT_SID] | |
,[CREATEDBY] | |
,[CREATED_ON] | |
,[MODIFIEDBY] | |
,[MODIFIED_ON] | |
,[SORT_INDEX] | |
,[TAG] | |
,[LEVEL] = 0 | |
FROM [dbo].[HOME_SERVICE_TYPE] | |
WHERE PARENT_SID = '0' and APARTMENT_SID = '64884172-dc3c-4277-87a9-bfdeec040b13' and CATEGORY_SID = '9098ED29-072D-4653-A37D-3C2F6DF80861' | |
union all | |
SELECT t.[TYPE_SID] | |
,t.[CATEGORY_SID] | |
,t.[APARTMENT_SID] | |
,t.[TYPE_NAME] | |
,t.[REMARK] | |
,t.[PARENT_SID] | |
,t.[CREATEDBY] | |
,t.[CREATED_ON] | |
,t.[MODIFIEDBY] | |
,t.[MODIFIED_ON] | |
,t.[SORT_INDEX] | |
,t.[TAG] | |
,[LEVEL] = x.[LEVEL] + 1 | |
FROM x inner join [dbo].[HOME_SERVICE_TYPE] t on t.PARENT_SID = x.TYPE_SID) | |
SELECT * FROM x order by LEVEL, [SORT_INDEX] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment