sql server - fully update a temporary table sql -


i have problem: trying update temporary table (in stored procedure) in sql server 2012, updates first entry matches description. here code:

create table #t (store_name varchar(30),                  product_name varchar(30),                   price int,                   valab_since date,                   valab_until date,                   best_offer varchar(3))  --some code populates table  update #t set best_offer = 'yes' price = (select min(price) cataloage c                  inner join produse p                 on c.codp = p.codp                 p.denumire = #t.store_name) update #t set best_offer = 'no' price > (select min(price) cataloage c                  inner join produse p                 on c.codp = p.codp                 p.denumire = #t.product_name)  select * #t 

cataloage , produse tables use

to cover records, first set them "no", run separate query update ones min price store.

update #t set best_offer = 'no';  ;with t (     select *, rnk = dense_rank() on (partition t.store_name order price asc)     cataloage c     join produse p on c.codp = p.codp     join #t t on p.denumire = t.store_name ) update t set best_offer = 'yes' rnk = 1; 

i've used dense_rank , common table expression alternative row-by-row subquery.


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -