In focus

How To Perform Calculations Using SELECT Statement In T-SQL

In this article you will learn how to perform various calculations using SELECT Statement.

Gagan Sharma Apr 13, 2016

What is T-SQL

Transact-SQL (T-SQL) is the set of programming using SQL Server. The Structured Query Language is commonly called Transact-SQL. All applications that communicate with an instance of SQL Server do so by sending Transact-SQL statements to the server, regardless of the user interface of the application. SQL, often expanded to Structured Query Language, is a standardized computer language that was originally developed by IBM for querying, altering and defining relational databases, using declarative statements.Transact-SQL enhances the power of SQL and minimizes the occasions on which users must resort to a programming language to accomplish a desired task.

History of Transact-SQL product and the context of use in database clients, servers, and web components is reviewed and demonstrated. Transact-SQL's capabilities go beyond the ISO standards and the many commercial versions of SQL. T-SQL extend the SQL standard in terms of procedural programming, supporting various functions for string processing, mathematics, date processing etc. Transact-SQL is considered Turing complete by these features. 

The SELECT statement is used for retrieving data from a table. This SQL Statement begins with the keyword SELECT. The results from the SELECT query is called the 'Resultset'.  Look at the example given below using SELECT statement for calculation's.:

Addition (+)

Query: SELECT 1 + 2 + 3 + 4 + 5+ + 9+15+85+63+525+78745

Output: 79457

Subtraction (-)

Query: SELECT 125-100

Output: 25

Multiplication (*)

Query: SELECT 13.7858 * 3.58

Output: 49.353164

Division (/)

Query: SELECT 875.958/23.22

Output: 37.72428940

Combination 

Query: SELECT (785.0 - 150.0)/12.0

Output: 52.916666

query select statement statement t-sql

COMMENT USING