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 |
cidr
Posting Yak Master
207 Posts |
Posted - 2009-11-11 : 05:37:31
|
Hi there,This is probably quite easy for some so I'd like to ask for help.My db is developed for a repair centre. A call is made to the centre and a contracter is called out to the site and then makes the repair. There is a table with four relevant columns to record this info. The first is fldID which is the unique pk for the row. the second is CallID. This holds the ID about which call it is. The third is an EventTypeID Event 1 = Call logged. Event 2 = Contractor allocation Event 3 = third is Onsite Event 4 = repaired This means there will be four rows in total with the same callID.The fourth column is ParentID. Only the Onsite event will have a ParentID, the rest will have -1. The parentID is simply the fldID for the Call logged event (1). This ties it back for relevant reasons.The problem I have is that there was changes made to the db and subsequently, ParentIDs for about 6000 rows have not been updated and instead of having the fldID from the first row as the parentID in the Onsite Event it is also -1.I need to find a way to update all rows with their relevant ParentIDs. Does anyone know which is the best method to do this. Below is a diagram of the columns and the way it should be.Correct - the way it should befldID CallID EventTypeID ParentIDID1 1 1 -1 (call logged event)ID2 1 2 -1ID3 1 3 ID1ID4 1 4 -1 Incorrect - the way it is just now.fldID CallID EventTypeID ParentIDID1 1 1 -1 (call logged event)ID2 1 2 -1ID3 1 3 -1ID4 1 4 -1 Many thanks in advance |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-11-11 : 12:18:47
|
[code]UPDATE tSET t.ParentID=t1.fldIDFROM table tINNER JOIN table t1ON t.CallID=t1.CallIDAND t.EventTypeID=3AND t1.EventTypeID=1[/code] |
|
|
cidr
Posting Yak Master
207 Posts |
Posted - 2009-11-12 : 08:14:25
|
Thanks for getting back to me visakh16 (again)I worked this out, however, I went with your code as I was using subqueries and it was getting a little convoluted.Thanks |
|
|
|
|
|