Click here to Skip to main content
15,911,711 members
Home / Discussions / Database
   

Database

 
GeneralRe: Multiple Rows to Single Rows Pin
Blue_Boy16-Oct-10 5:51
Blue_Boy16-Oct-10 5:51 
GeneralRe: Multiple Rows to Single Rows Pin
Chris Meech18-Oct-10 4:17
Chris Meech18-Oct-10 4:17 
GeneralRe: Multiple Rows to Single Rows Pin
Alegria_Lee18-Oct-10 4:48
Alegria_Lee18-Oct-10 4:48 
Questionsplitting one column into many Pin
rakeshs31215-Oct-10 0:42
rakeshs31215-Oct-10 0:42 
AnswerRe: splitting one column into many Pin
J4amieC15-Oct-10 1:17
J4amieC15-Oct-10 1:17 
GeneralRe: splitting one column into many Pin
rakeshs31215-Oct-10 2:23
rakeshs31215-Oct-10 2:23 
GeneralRe: splitting one column into many Pin
J4amieC15-Oct-10 2:53
J4amieC15-Oct-10 2:53 
AnswerRe: splitting one column into many Pin
PIEBALDconsult15-Oct-10 3:07
mvePIEBALDconsult15-Oct-10 3:07 
AnswerRe: splitting one column into many Pin
Rajesh Anuhya19-Oct-10 23:57
professionalRajesh Anuhya19-Oct-10 23:57 
Questionexesute ssis package Pin
samerh14-Oct-10 3:24
samerh14-Oct-10 3:24 
AnswerRe: exesute ssis package Pin
Vimalsoft(Pty) Ltd14-Oct-10 4:53
professionalVimalsoft(Pty) Ltd14-Oct-10 4:53 
Question1 recursive field in a Query Pin
Herman<T>.Instance14-Oct-10 0:25
Herman<T>.Instance14-Oct-10 0:25 
AnswerRe: 1 recursive field in a Query Pin
Simon_Whale14-Oct-10 0:41
Simon_Whale14-Oct-10 0:41 
AnswerRe: 1 recursive field in a Query Pin
Alegria_Lee14-Oct-10 2:11
Alegria_Lee14-Oct-10 2:11 
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 

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.