Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hierarchy update children when parent

Status
Not open for further replies.

Sammy145

Programmer
Oct 4, 2002
173
GB
Hi

what i want is query that will update all children to 'N' if the parent [ACTIVE] field is 'N', i want all
children to be ACTIVE ='N'
--The hierarchy can be 10 levels down
--parent is 0 for top level

CREATE TABLE [dbo].[Hierarchy](
[ID] [int] IDENTITY(1,1) NOT NULL,
[ParentID] [int] NULL,
[descr] [varchar](50) NULL,
[maingroup] [varchar](12) NULL,
[subgroup] [varchar](12) NULL,
active [varchar](2) NULL
)


Can someone show me how to do this please

Thanks for any help!
 
What version of SQL Server you use?
If you use SQL Server 2005 or later you could try recursive SELECT (seek for CTE in BOL) Then store the result from that select in Temp Variable and then join that table to your main table and do the update.

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top