Solved

SQL Query

Posted on 2012-03-25
2
328 Views
Last Modified: 2012-03-25
I have a table as below

Material   SeqNum   Controlkey
22             1                  x
22             2                  x
22             3                  x
22             4                  x
24             1                  x
24             2                  x

I have to update controlkey='y' for the max(seqno) for each material. I came up with the query

update Table_3
set ckey='ybp3'
from Table_3
where seqno=(select MAX(seqno)
from Table_3
group by Material)

But this is giving me two values in subquery . Here in the above query I need to update table as

Material   SeqNum   Controlkey
22             1                  x
22             2                  x
22             3                  x
22             4                  y
24             1                  x
24             2                  y


Thanks !
0
Comment
Question by:himabindu_nvn
2 Comments
 
LVL 8

Accepted Solution

by:
fundacionrts earned 500 total points
ID: 37762958
update
      Table_3_update
set
      ckey='ybp3'
from
      Table_3 Table_3_update
where
      seqno=(select MAX(seqno)
                  from Table_3 t3
                  where t3.Material = Table_3_update.Material
                  group by Material)
0
 

Author Closing Comment

by:himabindu_nvn
ID: 37762973
Thank you!
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

759 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

19 Experts available now in Live!

Get 1:1 Help Now