Solved

update fields from one field to another

Posted on 2010-11-30
3
268 Views
Last Modified: 2012-05-10
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
Comment
Question by:nadermik
3 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
ID: 34237117
update items
set lastmaintdate = (select max(maintdate) from maintenancem m
where m.maintitemcode=items.itemcode)
0
 
LVL 9

Expert Comment

by:s_chilkury
ID: 34237167
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
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34237206
update i
set lastmaintdate = (select max(MaintDate) from  Maintenance where MaintitemCode = i.Itemcode)
from items i
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
2 comma seperated list - SQL Server 12 45
Why is the output of this function is like this? 4 43
Sql query 107 86
Change this SQL to get all nodes 3 36
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question