Is it Possible to get the multiple set result into single set of result in SQL Server? -
my sql table looks this
create table [contents].[id] ( [id] nvarchar (20) not null, [name] nvarchar (max) not null, [content] nvarchar (max) null, [parent_id] nvarchar (20) not null, [type] int not null, [shared] int not null, [created] datetime null, [icon] varbinary (max) null, [updated] datetime null );
every item has parent item except major items. need required item parent, parent of parent, until item having no parent..
i used following query
declare @id nvarchar(max)='12843686753443770653'; way: set @id = (select parent_id contents.id (id = @id)) select * contents.id (id = @id) if @id!='jkparthiban' goto way
i got result:
i need results in single set instead of multiple sets.
you can use recursive cte results
declare @id nvarchar(max)='12843686753443770653'; ;with cte ( select id, name contentsid id = @id union select ci.id, ci.name cte c inner join contentsid ci on c.id = ci.parent_id ) select * cte
Comments
Post a Comment