View Full Version : Adding new row in table


Zlatkodo
04-05-2010, 12:12 AM
I have a database in Access 2007 (accdb) , that consists of only one table with several thousand rows.
I must add a new column X and enter into it values that depend on the value of the same row in column A, something like this:
-" if 1500< valueA<=3000 then valueX=2
- if 1000< valueA<=1500 then valueX=4
- if 750< valueA<=1000 then: valueX=6
- if 600< valueA<=750 then: valueX=8
- if 500< valueA<=600 then: valueX=10"

This should be done only once. If I am going to do it manually, I'll have a lot of work.
Can someone help me in this case?
Zlatkodo

ajetrumpet
04-05-2010, 12:54 AM
you need a simple update query. add the column manually to the table, then write the update. i'm tired right now, but maybe something like so:UPDATE table SET

table.x =

switch([a] > 1500 and [a] >= 3000, 2,
switch([a] > 1000 and [a] >= 1500, 4,
switch([a] > 750 and [a] >= 1000, 6,
switch([a] > 600 and [a] >= 750, 8,
switch([a] > 500 and [a] >= 600, 10)


I think you might want to check your comparison operators. I don't think you meant to post it the way you did. You might want to switch some of them around to make more sense for Mr. 'A' field! ;) The way you wrote it, either side could be eliminated and it would still come out the same...

Zlatkodo
04-05-2010, 01:07 AM
Hi, Adam,
You're right. I have already fixed the error.
I'll try to do as you suggested. Thanks. Zlatkodo