Connect with Expertise | Find Experts, Get Answers, Share Insights

Update a thousand rows with specific value

 
Join Date: Jan 2010
Posts: 18
#1: Feb 9 '10
I would like to update thousand of Rows with its specific value

Suppose i have a table XYZ and ABC
XYZ contains Code,Name,RegDate And ABC also Contains the same
but the Value of RegDate of XYZ is Different than that of ABC..
i want to update XYZ's RegDate Value From the value of RegDate of table ABC
at once...

update XYZ set RegDate=

ck9663's Avatar
E
C
 
Join Date: Jun 2007
Posts: 2,255
#2: Feb 9 '10

re: Update a thousand rows with specific value


How are the two tables related? What's the key that link them together?

Happy Coding!!!

~~ CK
Delerna's Avatar
E
C
 
Join Date: Jan 2008
Location: Sydney
Posts: 1,062
#3: Feb 10 '10

re: Update a thousand rows with specific value


One of the simplest ways is
Expand|Select|Wrap|Line Numbers
  1. UPDATE xyx 
  2. set datereg=
  3. (
  4.    select datereg from abc 
  5.    where abc.Code=xyz.code 
  6.       and abc.name=xyz.Name
  7. )
  8.  
but as ck says, you don't indicate which fields are the key
OraMaster's Avatar
C
 
Join Date: Aug 2009
Location: Pune, India
Posts: 137
#4: Feb 25 '10

re: Update a thousand rows with specific value


Small modification in the posted SQL

UPDATE xyx
set datereg=
(
select datereg from abc
where abc.Code=xyz.code
and abc.name=xyz.Name
and abc.datereg <> xyz.datereg
)
ck9663's Avatar
E
C
 
Join Date: Jun 2007
Posts: 2,255
#5: Feb 25 '10

re: Update a thousand rows with specific value


Yet another version :)

Expand|Select|Wrap|Line Numbers
  1.  
  2. UPDATE x
  3. set datereg = a.datereg
  4. from XYZ x
  5. INNER JOIN ABC a on x.code = a.code and a.name = x.name and x.datereg <> a.datereg
  6.  
  7.  
Happy Coding!!!

~~ CK
 
Join Date: Mar 2010
Posts: 4
#6: Mar 11 '10

re: Update a thousand rows with specific value


Update a set a.regdate=b.regdate from xyz a,abc b
where a.code=b.code and a.name=b.name and a.regdate<>b.regdate
Reply