Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to multiply column values in SQL Server?

Tags:

sql

sql-server

I would like to double the value of column C in a table. Is there a built-in function to achieve this?

Current table

       A  B  C
    X  1  2  3
    Y  4  5  6
    Z  7  8  9

After running the T-SQL or any query table values should be as below

   A  B  C
X  1  2  6
Y  4  5  12
Z  7  8  18
like image 701
akd Avatar asked May 03 '26 01:05

akd


1 Answers

  1. To select the data:

    SELECT A,B,C*2 as C
    FROM TableName
    

    Result:

    A   B   C
    1   2   6
    4   5   12
    7   8   18
    

    See result in SQL Fiddle.

  2. If you want to update the table:

    UPDATE TableName
    SET C=(C * 2)
    
like image 165
Raging Bull Avatar answered May 05 '26 14:05

Raging Bull