MSSQL Update Trick

So today I found a neat trick (that was intuitive but not obvious, at least to me and my google search for “SQL update set column = column”) was that you can set one column to be relative to anther column in the same table.
So in this example my table has 2 columns: buy and sell, initially I have set both to the same value but now I want to add 15% margin onto this. The solution is very simple:

UPDATE table SET sell = buy * 1.15

And like magic all the sell values in the table are 15% higher than the buy price.

About Simeon Cheeseman

I enjoy a wide variety of computer and board games, have a BSc in Computer Science and have played percussion for 18 years.

Posted on November 9, 2011, in Database and tagged , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: