Assign values from same table
- by Reddy S R
I have a database table with parent child relationships between different rows.
1 parent can have any number of children.
Children do not have children.
I want to copy 'Message' from 'Parent Category' to child categories.
CategoryID Name Value Message ParentID DeptId
1 Books 9 Specials 1
2 Music 7 1
3 Paperback 25 1 1
4 PDFs 26 1 2
5 CDs 35 2 1
If that was sample data, Paperback should have Specials as it's Message after the query is run.
I have gotten the child rows (the query runs very slow, don't know why), but how do I get the data and assign it to appropriate child rows?
--@DeptId = 1
select * from Categories
where ParentID in(
select CategoryID from Categories
where DeptID = @DeptId
)
I would like to see a solution that would not use cursors.
Thanks