Click here to Skip to main content
15,887,821 members
Home / Discussions / Database
   

Database

 
GeneralRe: 1 recursive field in a Query Pin
Herman<T>.Instance14-Oct-10 2:20
Herman<T>.Instance14-Oct-10 2:20 
AnswerRe: 1 recursive field in a Query [modified] Pin
Herman<T>.Instance14-Oct-10 2:19
Herman<T>.Instance14-Oct-10 2:19 
GeneralRe: 1 recursive field in a Query Pin
Chris Meech14-Oct-10 3:11
Chris Meech14-Oct-10 3:11 
GeneralRe: 1 recursive field in a Query Pin
Herman<T>.Instance14-Oct-10 3:18
Herman<T>.Instance14-Oct-10 3:18 
GeneralRe: 1 recursive field in a Query Pin
Simon_Whale14-Oct-10 3:43
Simon_Whale14-Oct-10 3:43 
GeneralRe: 1 recursive field in a Query Pin
Herman<T>.Instance14-Oct-10 4:16
Herman<T>.Instance14-Oct-10 4:16 
GeneralRe: 1 recursive field in a Query Pin
Mycroft Holmes14-Oct-10 11:12
professionalMycroft Holmes14-Oct-10 11:12 
GeneralRe: 1 recursive field in a Query [modified] Pin
Herman<T>.Instance17-Oct-10 22:21
Herman<T>.Instance17-Oct-10 22:21 
It was a bit of a headache but my colleague came up with materialized path design pattern:
WITH 
	ParentChildRels
	(ParentID, ChildID, KeyField, [Path], HierarchyLevel, Doc) 
AS 
(
	SELECT     
		ParentID, ChildID, KeyField, CAST('root/' + Folder AS nvarchar(255)) AS Path, 1 AS HierarchyLevel, Doc 
	FROM         
	(
		SELECT     
			dbo.Folder.ParentID, dbo.Folder.ID AS ChildID, dbo.Folder.Folder, dbo.[Document].DocumentID AS KeyField, dbo.[Document].[Document] AS Doc
		FROM          
			dbo.[Document] 
		RIGHT OUTER JOIN
			dbo.Folder 
		ON 
			dbo.[Document].FolderID = dbo.Folder.ID
	) AS x
	WHERE     
		(ParentID = 0)
	
	UNION ALL


	SELECT     
		r.ParentID, r.ChildID, r.KeyField, CAST(RTRIM(pr.Path) + '/' + r.Folder AS nvarchar(255)) AS Path, pr.HierarchyLevel + 1 AS HierarchyLevel, r.Doc
	FROM         
	(
		SELECT     
			Folder_1.ParentID, Folder_1.ID AS ChildID, Folder_1.Folder, Document_1.DocumentID AS KeyField, Document_1.[Document] AS Doc
		FROM          
			dbo.[Document] AS Document_1 
		INNER JOIN
			dbo.[Folder] AS Folder_1 
		ON
			Document_1.FolderID = Folder_1.ID
	) AS r 
	INNER JOIN
		ParentChildRels AS pr 
	ON r.ParentID = pr.ChildID
)
SELECT DISTINCT TOP (100) PERCENT 
	ParentID, ChildID, KeyField, RTRIM(RTRIM([Path]) + '/' + Doc)
FROM         
	ParentChildRels AS ParentChildRels_1
WHERE Keyfield is not null
ORDER BY 
	RTRIM(RTRIM([Path]) + '/' + Doc), ParentID, ChildID, KeyField


I thought to share it with you all if you ever come into the same situation
In Word you can only store 2 bytes. That is why I use Writer.
modified on Monday, October 18, 2010 4:59 AM

QuestionSubquery select case Pin
C#Coudou13-Oct-10 15:11
C#Coudou13-Oct-10 15:11 
AnswerRe: Subquery select case Pin
Karthik. A13-Oct-10 15:44
Karthik. A13-Oct-10 15:44 
GeneralRe: Subquery select case [modified] Pin
Alegria_Lee13-Oct-10 16:25
Alegria_Lee13-Oct-10 16:25 
GeneralRe: Subquery select case Pin
Karthik. A13-Oct-10 16:29
Karthik. A13-Oct-10 16:29 
GeneralRe: Subquery select case Pin
Alegria_Lee13-Oct-10 16:31
Alegria_Lee13-Oct-10 16:31 
GeneralRe: Subquery select case Pin
C#Coudou13-Oct-10 16:50
C#Coudou13-Oct-10 16:50 
GeneralRe: Subquery select case Pin
Blue_Boy13-Oct-10 21:01
Blue_Boy13-Oct-10 21:01 
GeneralRe: Subquery select case Pin
C#Coudou13-Oct-10 21:37
C#Coudou13-Oct-10 21:37 
GeneralRe: Subquery select case Pin
Blue_Boy13-Oct-10 21:43
Blue_Boy13-Oct-10 21:43 
QuestionPlease help me with my research problem [modified] Pin
bleedingfingers13-Oct-10 9:37
bleedingfingers13-Oct-10 9:37 
AnswerRe: Please help me with my research problem Pin
David Mujica13-Oct-10 10:44
David Mujica13-Oct-10 10:44 
GeneralRe: Please help me with my research problem Pin
bleedingfingers13-Oct-10 10:55
bleedingfingers13-Oct-10 10:55 
QuestionCouple general questions on sql server 2005+ transactional replication (in continuous mode specifically) Pin
Jon_Boy13-Oct-10 8:58
Jon_Boy13-Oct-10 8:58 
AnswerRe: Couple general questions on sql server 2005+ transactional replication (in continuous mode specifically) Pin
SimulationofSai14-Oct-10 17:05
SimulationofSai14-Oct-10 17:05 
QuestionHow pass dataset query as paramter in SSRS? Pin
andy_p 213-Oct-10 4:39
andy_p 213-Oct-10 4:39 
QuestionOracle development Pin
sinsoush113-Oct-10 2:26
sinsoush113-Oct-10 2:26 
AnswerRe: Oracle development Pin
David Mujica13-Oct-10 3:08
David Mujica13-Oct-10 3:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.