Home » SQL & PL/SQL » SQL & PL/SQL » Update Query
Update Query [message #7031] Fri, 16 May 2003 08:47 Go to next message
Ray
Messages: 58
Registered: January 2000
Member
Here is a table that I am working with:
Table A
KEY Unique, Not Null
COLA Not Null, Number
COLB Not Null, Number
COLC Null, VARCHAR

I did not design these tables or columns so can't change the formatting. The problem that I am up against is, I don't know an easy way to fill COLC from the difference between COLA and COLB based on the KEY field.ex. (COLC = COLA / COLB for Unique KEY).
I am new at cursors and the like so any help is greatly appreciated. I was trying to use an Update Query command but it has 4500+ rows and it never worked. Thanks in advance.
Re: Update Query [message #7032 is a reply to message #7031] Fri, 16 May 2003 11:09 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Of course, it is not a good idea at all to store a calculated field, but...

update a
   set colc = (cola / colb);


That's all there is to it.
Re: Update Query - Still have a problem [message #7033 is a reply to message #7032] Fri, 16 May 2003 12:04 Go to previous messageGo to next message
Ray
Messages: 58
Registered: January 2000
Member
Hi,
Thanks for the help and I understand that you shouldn't but since I didn't build them just maintain them.....

Anyway, Can I do that for just certain key field identifiers by using a where clause? ex. update a set colc = (cola / colb) where keyfield = *****;
Re: Update Query - Still have a problem [message #7035 is a reply to message #7033] Fri, 16 May 2003 12:31 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Sure. You could also do a list of values:

where keyfield in (1, 2, ..., n)
Re: Update Query - Still have a problem [message #7038 is a reply to message #7035] Fri, 16 May 2003 14:44 Go to previous message
Ray
Messages: 58
Registered: January 2000
Member
Thanks for all of the help it apears to be working
Previous Topic: Index?
Next Topic: Using NOT IN in a subquery
Goto Forum:
  


Current Time: Thu Apr 25 11:29:20 CDT 2024