Update based on a select statement SQL Server 2005 -



Update based on a select statement SQL Server 2005 -

i have select statement gives me results need update have no thought how incorporate update. below select statement , results.

select top 20 percent fpartno ,(fytdiss * fmatlcost) 'total' inmast fpartno not 'crv%' , fcstscode = 'a' grouping fpartno, fytdiss,fmatlcost,fabccode order total desc fpartno total --------------------------------------------------- 1062-20-0244 172821.4800000000 b50602 91600.7205800000 bm6031pq 82978.3200000000 ly2f-dc12 74740.9500000000 bm6033sq 51640.4200000000 dtm06-6s-e007 49810.4700000000

my update looks this

update inmast set fabccode = 'a'

i'm guessing select how go clause i'm not sure how.

updating top 20 percent tricky... because can't set order by in update.

i this:

select * -- update t set fabccode='a' inmast t fpartno in ( select top 20 percent fpartno inmast t fpartno not 'crv%' , fcstscode = 'a' grouping fpartno, fytdiss,fmatlcost,fabccode order (fytdiss * fmatlcost) desc)

run select , create sure works expected. if yes, can remove select line, , uncomment update line.

alternate solution:

select * -- update t set fabccode='a' inmast t bring together (select top 20 percent fpartno inmast t fpartno not 'crv%' , fcstscode = 'a' grouping fpartno, fytdiss,fmatlcost,fabccode order (fytdiss * fmatlcost) desc) x on t.fpartno = x.fpartno

sql sql-server sql-server-2005

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -