Created
September 27, 2013 06:55
-
-
Save pavelpower/6725009 to your computer and use it in GitHub Desktop.
рекурсивный запрос в T-SQL
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 PCommentList ([ProductId] | |
,[ProductCommentId] | |
,[ProductCommentPId] | |
,[ProductCommentText] | |
,[ProductCommentAddDate] | |
,[ProductCommentAddUserId] | |
,[ProductCommentAddUserName] | |
,[IsApproved] | |
,[IsLocked]) | |
AS( | |
SELECT * | |
FROM [basename].[dbo].[ProductComments] | |
WHERE [ProductCommentId] = 113 --- id того сообщения которого возвращаем ветку | |
UNION ALL | |
SELECT comm.* | |
FROM [basename].[dbo].[ProductComments] as comm | |
Inner JOIN PCommentList as pl | |
ON comm.ProductCommentPId = pl.ProductCommentId | |
) | |
SELECT * FROM PCommentList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment