Solved

update fields from one field to another

Posted on 2010-11-30
3
265 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
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 …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

706 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now