Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
MAcKZloy
Starting Member
4 Posts |
Posted - 2010-06-15 : 05:56:47
|
| I have data next structure:[CODE]Status Field1 Field2 Field3 Status Field1 Field2 Field3 Status Field1 Field2 Field3[/CODE]The structure can be various.[CODE]Status Field1 ... Status .... Status Status .........[/CODE]How create tables correctly I can get all children in a select? |
|
|
NeilG
Aged Yak Warrior
530 Posts |
Posted - 2010-06-15 : 06:20:12
|
| Are you meaning to join all the tables together and produce one result setTry the Union operator happen? |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-06-15 : 06:30:23
|
Use ID and parentID No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
MAcKZloy
Starting Member
4 Posts |
Posted - 2010-06-15 : 06:46:12
|
quote: Originally posted by NeilG Are you meaning to join all the tables together and produce one result setTry the Union operator happen?
I am thinking to save in a(one) table.May be will add a new field and generate next:Name, ID, NewFieldStatus, 1, 1_ Status, 2, 1_2_ Status, 3, 1_3_ Status, 4, 1_3_4_ and can to get : Select * from MyTabke where NewField like 1_%What you think about it? PS: how I can get all records if implemented Parent\Child (id and ParentID)? |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-06-15 : 08:08:38
|
quote: PS: how I can get all records if implemented Parent\Child (id and ParentID)?
Search for SQL Server CTE and you will see examples for that. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
MAcKZloy
Starting Member
4 Posts |
Posted - 2010-06-15 : 10:37:13
|
quote: Originally posted by webfred
quote: PS: how I can get all records if implemented Parent\Child (id and ParentID)?
Search for SQL Server CTE and you will see examples for that. No, you're never too old to Yak'n'Roll if you're too young to die.
Thank you. is is a good idea. Can I implement one in the MSSQL2000? |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-06-15 : 10:47:24
|
No. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
MAcKZloy
Starting Member
4 Posts |
Posted - 2010-06-15 : 11:34:08
|
| What you think if make two tables:MyTable(MyTableId, RootId, AdditionalId, <Fileds>) if it is parent then Additional = null or 0, if it is children then a number from the Additional table. RootId - same for all records of one structure.Addtional (AdditionalId increment, MyTableId) where MyTableId is parent Id from MyTable.I think it is better than previous sample and need only 1 query.webfred you wrote about it above :). |
 |
|
|
|
|
|
|
|