sql server 2005 - SQL - looping through columns, once empty is found, update it -


i started similar thread problem more difficult, start scratch.
imagine there 10 inventory slots (in db columns in user's row). when users picks item up, should placed first empty column (it gets updated). how looping through columns (except if exists) in query if want have still flexible design? cannot solved having items in rows order of items matters (each item belongs particular slot). if users has 1nd , 3rd slot full, next picked item should go 2nd. hope more clear now, thanks!

why not have table inventory items? you'd have inventory table , inventory_item table, this:

---------- inventory ---------- id int description varchar(100)  --------------- inventory_item --------------- id  int inventory_id int (foreign key inventory table) sequence_num int (indicates "slot" data represents) 

so now, have row in inventory, , insert rows inventory_item values. if have 3 values, insert 3 rows inventory_item. "slot" go in, sequence_num field tell that.

edit
query existing inventory_items find out next available slot number, like:

select coalesce(max(sequence_num),0) + 1 next_sequence_num   inventory_item  inventory_id = xxx 

if no inventory_items exist, return 1. if existing items present, give next "slot number" use (i call sequence_number, same thing).


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -