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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 PARENT ID Updation in Same Table

Author  Topic 

Kalaiselvan
Posting Yak Master

112 Posts

Posted - 2013-09-11 : 23:22:33
Hi,
Got a Table with some Columns, Need to Update PArentID column depends on Column values.

TableA:
[PID] [COL1] [COL2] [COL3] [COL4] [VOL] [PARENTID]
101 AA AA AA AA 10 0
102 AA AB AB AB 10 0
103 AA AB AAA AAA 10 0
104 AA AB AAA X1 10 0
105 AA AB AAA X2 10 0
106 AA AC AC AC 10 0
107 AA AC AAB AAB 10 0
108 AA AC AAB X3 10 0
109 AA AC AAB X4 10 0

From above table COL1 to COL4 is considered for ParentID Updation. Will Update the PArent ID, Which is the Required Output.1st Row will be 0 because there is no Parent for 1st Row.

[PID] [COL1] [COL2] [COL3] [COL4] [VOL] [PARENTID]
101 AA AA AA AA 40 0
102 AA AB AB AB 20 101
103 AA AB AAA AAA 20 102
104 AA AB AAA X1 10 103
105 AA AB AAA X2 10 103
106 AA AC AC AC 20 101
107 AA AC AAB AAB 20 106
108 AA AC AAB X3 10 107
109 AA AC AAB X4 10 107

Please help me to Fix this Parent ID updation using SQL Query...


Regards,
Kalai

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-09-11 : 23:33:28
can you please describe what is the logic behind ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Kalaiselvan
Posting Yak Master

112 Posts

Posted - 2013-09-13 : 01:32:17
1st Row All Column Values were Same So Its the Parent Node and Its Parent Id will be 0.
2nd Row PID 102 1st Column is AA and Other were AB, Its the Child for 1st row and the same for PID 106 1st Col is AA and Others were AC. Here the PArentID will be 101.

The same have to Check for All Rows, If all Row Values were same Then its PArent.
After 1st Column If other Column values were same Then its the Child for 1st Parent.
And the Same Check for Other Columns.


Regards,
Kalai
Go to Top of Page
   

- Advertisement -