• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

update fields from one field to another

Hi
I have one table (Items) with the following details
Itemcode, ItemDescription, lastmaintdate

another table Maintenance
MaintReqID, MaintitemCode, MaintDate

I have to for one item multiple maintenance request in table maintenance I need to write a query to update lastmaintdate in table items with the recent date of the maintenance table of the same item.

can you help me with this
0
nadermik
Asked:
nadermik
1 Solution
 
cyberkiwiCommented:
update items
set lastmaintdate = (select max(maintdate) from maintenancem m
where m.maintitemcode=items.itemcode)
0
 
s_chilkuryCommented:
update [items]
set lastmaintdate =
(
      select top 1 maintdate from [maintenance]
      where items.itemcode = maintenance.maintitemcode
      and [whatever clause you need more]
      order by maintdate desc
)
0
 
Rajkumar GsSoftware EngineerCommented:
update i
set lastmaintdate = (select max(MaintDate) from  Maintenance where MaintitemCode = i.Itemcode)
from items i
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now