| title | SQUARE (Transact-SQL) | Microsoft Docs | ||
|---|---|---|---|
| ms.custom | |||
| ms.date | 03/03/2017 | ||
| ms.prod | sql-non-specified | ||
| ms.reviewer | |||
| ms.suite | |||
| ms.technology |
|
||
| ms.tgt_pltfrm | |||
| ms.topic | language-reference | ||
| f1_keywords |
|
||
| dev_langs |
|
||
| helpviewer_keywords |
|
||
| ms.assetid | 007b6b12-da86-4229-8f5c-fdd4fa839f5f | ||
| caps.latest.revision | 20 | ||
| author | BYHAM | ||
| ms.author | rickbyh | ||
| manager | jhubbard |
[!INCLUDEtsql-appliesto-ss2008-xxxx-asdw-pdw_md]
Returns the square of the specified float value.
Transact-SQL Syntax Conventions
-- Syntax for SQL Server, Azure SQL Data Warehouse, Parallel Data Warehouse
SQUARE ( float_expression )
float_expression
Is an expression of type float or of a type that can be implicitly converted to float.
float
The following example returns the volume of a cylinder having a radius of 1 inch and a height of 5 inches.
DECLARE @h float, @r float;
SET @h = 5;
SET @r = 1;
SELECT PI()* SQUARE(@r)* @h AS 'Cyl Vol';
[!INCLUDEssResult]
Cyl Vol
--------------------------
15.707963267948966
The following example returns the square of each value in the volume column in the containers table.
-- Uses AdventureWorks
CREATE TABLE Containers (
ID int NOT NULL,
Name varchar(20),
Volume float(24));
INSERT INTO Containers VALUES (1, 'Cylinder', '125.22');
INSERT INTO Containers VALUES (2, 'Cube', '23.98');
SELECT Name, SQUARE(Volume) AS VolSquared
FROM Containers;
[!INCLUDEssResult]
Name VolSquared
------------- ----------
Cylinder 15680.05
Cube 575.04