SQL Help

  • sergv
  • Born
  • Born
  • sergv
  • Posts: 1

Post 3+ Months Ago

I have 2 tables, one with real data, other is to help me updating the first one. The real data has structure similar to this:
PK|Value
1|2
2|8
3|22

the translation table has the following information:
min|max|value
1|5|5
6|10|10
11|15|20

basically what I want to do is create a query that goes through every record in the first table and based on the value looks up a correct value in the trnslation table (between min & max) then adds that value to the value in the first table. So, once its ran, the results would look like so:
PK|Value
1|7
2|18
3|42

There are lots more records in the first table and translation table has 15 ranges that have different values so this query needs to be automated, that is why I need a query. I tried to do something like this:
Update main_table set value = value + (select value from translation_table....) but it does not seem to like value + (select... statement. Hope this makes sense, let me know!

Thanks!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 94 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.