Click here to Skip to main content
15,894,955 members
Home / Discussions / Database
   

Database

 
GeneralRe: Debug Sp Pin
sreejith ss nair20-Sep-05 1:06
sreejith ss nair20-Sep-05 1:06 
QuestionStroing Word Document in the Database Pin
Ahsan Askare19-Sep-05 18:57
Ahsan Askare19-Sep-05 18:57 
AnswerRe: Stroing Word Document in the Database Pin
turbochimp19-Sep-05 19:42
turbochimp19-Sep-05 19:42 
AnswerRe: Stroing Word Document in the Database Pin
enjoycrack19-Sep-05 19:43
enjoycrack19-Sep-05 19:43 
GeneralRe: Stroing Word Document in the Database Pin
Ahsan Askare19-Sep-05 21:06
Ahsan Askare19-Sep-05 21:06 
AnswerRe: Stroing Word Document in the Database Pin
Michael P Butler20-Sep-05 2:34
Michael P Butler20-Sep-05 2:34 
QuestionNewbish Problem Pin
tatchung19-Sep-05 18:30
tatchung19-Sep-05 18:30 
AnswerRe: Newbish Problem Pin
Edbert P19-Sep-05 19:34
Edbert P19-Sep-05 19:34 
A very interesting problem.
Most likely you can solve this by creating a User-Defined function (or Stored Procedure) that keeps calling itself to union all the result from the ChildIDs.
How about something like below (example of usage: "SELECT ID, ModuleID FROM dbo.GetModule('91')").

Note: I haven't tested the UNION yet. You might need to modify it a bit to make the union work.

CREATE FUNCTION dbo.GetModule
{
       @ListID nvarchar(2000)
}

<code>--Concatenate all ChildIDs of all IDs in @ListID. Basically COALESCE is used to replace NULL with '' (empty string)</code>
DECLARE @ChildIDs varchar(100);
SELECT @ChildIDs = COALESCE (@ChildIDs + ', ', '') + ChildIDs          
FROM tblModule WHERE ID IN (SELECT value FROM dbo.Split(@ListID)))

<code>-- Selects the Parent's ID and ModuleID, then UNION with ChildIDs' result if there are ChildIDs</code>
IF @ChildIDs = null

  SELECT ID, ModuleID                                     --This is to return only parent result if there are no ChildIDs
  FROM tblModule 
  WHERE ID IN (SELECT value FROM dbo.Split(@ListID)

ELSE

  SELECT ID, ModuleID
  FROM tblModule 
  WHERE ID IN (SELECT value FROM dbo.Split(@ListID)

  UNION                                                    --This is the recursive code to union with result of ChildIDs

  SELECT ID, ModuleID
  FROM dbo.GetModule(@ChildIDs)

RETURN


Of course, you also need the Split UDF to split your ChildIDs into array of IDs that is acceptable in SQL:
CREATE FUNCTION dbo.Split
(
	@List nvarchar(2000),
	@SplitOn nvarchar(5)
)  
RETURNS @RtnValue table 
(
		
	Id int identity(1,1),
	Value nvarchar(100)
) 
AS  
BEGIN
	WHILE (CHARINDEX(@SplitOn,@List)>0)
	BEGIN 
	
	INSERT INTO @RtnValue (value)
	SELECT 
	    Value = LTRIM(RTRIM(SUBSTRING(@List,1,CHARINDEX(@SplitOn,@List)-1))) 
	
	   Set @List = SUBSTRING(@List,CHARINDEX(@SplitOn,@List)+LEN(@SplitOn),LEN(@List))
	END
	
	INSERT INTO @RtnValue (Value)
	SELECT Value = LTRIM(RTRIM(@List))
	
	RETURN
END



Signature
The only valid use of the BLINK tag:

Schrodinger's cat is <blink>not dead

.


-- modified at 1:38 Tuesday 20th September, 2005
GeneralRe: Newbish Problem Pin
tatchung19-Sep-05 20:08
tatchung19-Sep-05 20:08 
GeneralRe: Newbish Problem Pin
Edbert P19-Sep-05 20:39
Edbert P19-Sep-05 20:39 
GeneralRe: Newbish Problem Pin
tatchung19-Sep-05 21:09
tatchung19-Sep-05 21:09 
GeneralRe: Newbish Problem Pin
Edbert P20-Sep-05 13:44
Edbert P20-Sep-05 13:44 
QuestionUpdate Command Failing Pin
japel19-Sep-05 0:42
japel19-Sep-05 0:42 
AnswerRe: Update Command Failing Pin
enjoycrack19-Sep-05 0:54
enjoycrack19-Sep-05 0:54 
AnswerRe: Update Command Failing Pin
Luis Alonso Ramos19-Sep-05 8:19
Luis Alonso Ramos19-Sep-05 8:19 
GeneralRe: Update Command Failing Pin
japel19-Sep-05 10:36
japel19-Sep-05 10:36 
AnswerRe: Update Command Failing Pin
Luis Alonso Ramos20-Sep-05 19:49
Luis Alonso Ramos20-Sep-05 19:49 
Questionusing @@IDENTITY (or nething like this)for char datatype(sql server) Pin
utsav_verma18-Sep-05 23:53
utsav_verma18-Sep-05 23:53 
AnswerADDON:using @@IDENTITY (or nething like this)for char datatype(sql server) Pin
utsav_verma19-Sep-05 0:04
utsav_verma19-Sep-05 0:04 
AnswerRe: using @@IDENTITY (or nething like this)for char datatype(sql server) Pin
utsav_verma19-Sep-05 0:22
utsav_verma19-Sep-05 0:22 
GeneralRe: using @@IDENTITY (or nething like this)for char datatype(sql server) Pin
enjoycrack19-Sep-05 0:51
enjoycrack19-Sep-05 0:51 
QuestionMultiple Choice Pin
Leslie Sanford18-Sep-05 19:25
Leslie Sanford18-Sep-05 19:25 
AnswerRe: Multiple Choice Pin
Colin Angus Mackay18-Sep-05 20:26
Colin Angus Mackay18-Sep-05 20:26 
GeneralRe: Multiple Choice Pin
Leslie Sanford19-Sep-05 6:21
Leslie Sanford19-Sep-05 6:21 
AnswerRe: Multiple Choice Pin
Edbert P18-Sep-05 20:31
Edbert P18-Sep-05 20:31 

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.