SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 PARENT ID Updation in Same Table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Kalaiselvan
Posting Yak Master

India
109 Posts

Posted - 09/11/2013 :  23:22:33  Show Profile  Reply with Quote
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)

Singapore
17642 Posts

Posted - 09/11/2013 :  23:33:28  Show Profile  Reply with Quote
can you please describe what is the logic behind ?


KH
Time is always against us

Go to Top of Page

Kalaiselvan
Posting Yak Master

India
109 Posts

Posted - 09/13/2013 :  01:32:17  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000