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
 General SQL Server Forums
 New to SQL Server Programming
 Update field

Author  Topic 

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2011-11-23 : 12:15:02
Last item of the day and i'm OUT of here for the extended weekend! So ye who helps me with this will have the full gratitude of my family:
I have a table (EVP_COC) which has multiple EVPNO rows with the same value that correspond to other columns. The column i need to update is the 'EVENT' column, HOWEVER i only need to place the value from the TEMPEVENT column in the last occurence for each EVPNO row. So i have a value of "CHECK OUT" in the TempEvent column which corresponds to EVPNO 'RCSO00EVP000001'. I have four rows which correspond to that EVPNO value, and i need to place the value in the TEMPEVENT column (corresponding to the EVPNO value) into the LAST row for that EVPNO value.

how the heck is this going to happen?

thanks

james

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2011-11-23 : 12:26:17
Sorry, i meant to say i need to place the value FROM the tempevent column into the last corresponding entry in the EVENT column which relates to that EVPNO.
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-11-23 : 12:46:08
What do you mean by last? do you have a datetime or identity or something?

something like
update EVP_COC
set TempEvent = event
from EVP_COC e
join (select EVPNO, IDENTITY = max(id) from EVP_COC group by EVPNO) e2
on e.EVPNO = e2.EVPNO
and e.ID = e2.ID


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2011-11-23 : 12:55:27
Good question. The customer has not done well in providing us coherent links between these fields. i think this is one i have to kick back to the customer to get them to clarify some of these vague relationship values.
Go to Top of Page
   

- Advertisement -