sql server - SQL Conditional UPDATE Based on SELECT -



sql server - SQL Conditional UPDATE Based on SELECT -

in sql server 2008, have set of info containing costs east , west. i'm adding new field client canada needs 1.5 times east or west cost (which ever greater). i'm trying come sql can execute. i've tried next have not had success:

update shippingcost set if eastcost>westcost canada= eastcost*1.8 else canada= westcost*1.8 endif

i'm sure there's easy way this? ideas?

you need utilize case

update shippingcost set canada = case when eastcost>westcost eastcost*1.8 else westcost*1.8 end

sql sql-server sql-server-2008 select sql-update

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -