question

red68 avatar image
red68 asked

Populate Update Query using data from another table

I have 2 tables: Master and Lookup. The Lookup table has Segment, Cell and Quantity. Need to update Master table using data from Lookup table. Ex: Select needed quantity in Lookup table of 100,000 records for Segment = B and pass to Master table update statement to set Cell = 1 for top 100,000 records where priority_flag = 1, then 2, then 3 until 100,000 quantity is met. Once this is complete, I would then go to next line in Lookup table perform same process until I reach the end of each row in Lookup table. This way I don't have to run 19 update statements manually. Thanks!

sql-server-2012
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

red68 avatar image red68 commented ·

Example lookup table. Basically, I want to join to my master table on Segment and update the value for Cell = 1 but ONLY Top 100,000 records order by prioritygroup_flag (1,2,3,4,5). When done, jump to next row in lookup table do the same procedure but for Segment = 'C' and set Cell = '2' but ONLY Top 50,000. Thx.

SegmentCellQtyB1100000C250000
0 Likes 0 ·

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.