HSID (int, PK)
TapID (int, PK) HSID
So, for each HSID, there are multiple TapIDs in table B (and multiple TapStart dates). I want to run an update query that will determine the earliest TapStart for each HSID in Table B and update EarliestTapStart in Table A (to the corresponding HSID, of course).
Above statement updates every record with the minimum date for all HSID.
How do I get the update to work so that each HSID is updated correctly?
Thanks very much for any assistance you can provide.
asked Jul 25, 2012 at 05:09 PM in Default
Thanks sunil2711 for getting me on the right path. Here's the actual SQL that I used to make it work.
answered Jul 25, 2012 at 08:26 PM
Try like this update [Table A] x set EarliestTapStart = ( select Tapstart from ( select tapid,min(tapstart) from [Table B] )y where x.HSID=y.HSID
If you are familer with CTE,YOu can do also with CTE's
answered Jul 25, 2012 at 07:06 PM