sql - Issue with limiting number of times a value can be inserted -
i have following query below inserting correctly way written. however, running issues when trying modify query insert value of column 'coord' maximum of 5 times.
for example if column 'coord' = 'north'. need limit number of times 'north' can inserted. if 10 records 'coord' = 'north' in database 5 times, next value of 'coord' should selected based on clause criteria.
select id, route #temp_distance tran_tbl handle = 21; select coord, travels #temp_planned converse_tbl travelplansinfo ( select id, route, count(1) rowcnt #tran_tbl group id, route ) , rownum_matches ( select t.id, r.coord, t.rowcnt, row_number() on (partition t.id order newid()) rownum travelplansinfo t join #temp_planned f on f.travels != t.route ) insert #temp_angle select id, coord rownum_matches rm rownum <= rowcnt i tried solve issue using cursor mess. rather use different alternative cursors if possible. input appreciated.
this approach simpler.
insert table (f1, f2, etc) select value1, value2, etc (select count(*) wherever) < 5 this assumes sql server don't need clause in select query.
Comments
Post a Comment