Click here to Skip to main content
15,896,063 members
Home / Discussions / Database
   

Database

 
GeneralRe: SQL To XML Pin
Vimalsoft(Pty) Ltd1-Nov-09 20:06
professionalVimalsoft(Pty) Ltd1-Nov-09 20:06 
AnswerRe: SQL To XML Pin
Andy_L_J30-Oct-09 21:43
Andy_L_J30-Oct-09 21:43 
GeneralRe: SQL To XML Pin
Vimalsoft(Pty) Ltd1-Nov-09 20:03
professionalVimalsoft(Pty) Ltd1-Nov-09 20:03 
GeneralRe: SQL To XML Pin
J4amieC1-Nov-09 21:43
J4amieC1-Nov-09 21:43 
GeneralRe: SQL To XML Pin
Vimalsoft(Pty) Ltd1-Nov-09 22:15
professionalVimalsoft(Pty) Ltd1-Nov-09 22:15 
GeneralRe: SQL To XML Pin
J4amieC2-Nov-09 1:15
J4amieC2-Nov-09 1:15 
Questionits urgent Pin
bcss03a00629-Oct-09 21:00
bcss03a00629-Oct-09 21:00 
AnswerRe: its urgent [modified] Pin
Niladri_Biswas29-Oct-09 21:46
Niladri_Biswas29-Oct-09 21:46 
This kind of problem can be easily solved with Recursive CTE's.

Try this.
declare @tbl table(id varchar(20),parentid varchar(20))
insert into @tbl
select 'S1','SG' union all
select 'G1','FG' union all
select 'GP01','FG' union all
select 'GP0101','GP01' union all
select 'G11','G1' union all
select 'G12','G1' union all
select 'G111','G11' union all
select 'G112','G11' union all
select 'G113','G11'

;with cte as
(
	select t1.parentid,t1.id,0 AS [Level] from  @tbl t1	
	where t1.parentid  = 'FG'	
	union all 	
	select t1.parentid,t1.id,[Level]+1 from  @tbl t1
	inner join cte c
	on c.id = t1.parentid
)
select left(Decendants,len(Decendants)-1) Decandants
from
    (
		select id  + ','
		from cte
		for xml path ('')
    ) Result(Decendants)


Pass the parent id as a parameter from ur stored proc.

O/P:
Decandants
G1,GP01,GP0101,G11,G12,G111,G112,G113


Smile | :)

Niladri Biswas

modified on Friday, October 30, 2009 6:11 AM

GeneralRe: its urgent Pin
Mycroft Holmes29-Oct-09 22:13
professionalMycroft Holmes29-Oct-09 22:13 
QuestionConvert Oracle Query to MS-Access Pin
M Riaz Bashir29-Oct-09 20:22
M Riaz Bashir29-Oct-09 20:22 
AnswerRe: Convert Oracle Query to MS-Access Pin
Mycroft Holmes29-Oct-09 22:10
professionalMycroft Holmes29-Oct-09 22:10 
GeneralRe: Convert Oracle Query to MS-Access Pin
Jörgen Andersson29-Oct-09 23:45
professionalJörgen Andersson29-Oct-09 23:45 
AnswerRe: Convert Oracle Query to MS-Access Pin
Jörgen Andersson29-Oct-09 23:05
professionalJörgen Andersson29-Oct-09 23:05 
GeneralRe: Convert Oracle Query to MS-Access Pin
David Skelly30-Oct-09 3:08
David Skelly30-Oct-09 3:08 
GeneralRe: Convert Oracle Query to MS-Access Pin
Jörgen Andersson30-Oct-09 3:25
professionalJörgen Andersson30-Oct-09 3:25 
GeneralRe: Convert Oracle Query to MS-Access Pin
Chris Meech30-Oct-09 9:54
Chris Meech30-Oct-09 9:54 
QuestionProblem with Execute query by EXEC(@string) Pin
nainakarri29-Oct-09 1:31
nainakarri29-Oct-09 1:31 
AnswerRe: Problem with Execute query by EXEC(@string) Pin
Covean29-Oct-09 1:52
Covean29-Oct-09 1:52 
GeneralRe: Problem with Execute query by EXEC(@string) Pin
nainakarri29-Oct-09 2:02
nainakarri29-Oct-09 2:02 
GeneralRe: Problem with Execute query by EXEC(@string) Pin
Covean29-Oct-09 2:04
Covean29-Oct-09 2:04 
GeneralRe: Problem with Execute query by EXEC(@string) Pin
Mycroft Holmes29-Oct-09 2:06
professionalMycroft Holmes29-Oct-09 2:06 
GeneralRe: Problem with Execute query by EXEC(@string) Pin
nainakarri29-Oct-09 2:18
nainakarri29-Oct-09 2:18 
GeneralRe: Problem with Execute query by EXEC(@string) Pin
Mycroft Holmes29-Oct-09 2:24
professionalMycroft Holmes29-Oct-09 2:24 
GeneralRe: Problem with Execute query by EXEC(@string) Pin
nainakarri29-Oct-09 2:35
nainakarri29-Oct-09 2:35 
AnswerRe: Problem with Execute query by EXEC(@string) Pin
soni uma29-Oct-09 2:44
soni uma29-Oct-09 2:44 

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.