Skip to content

Latest commit

 

History

History
49 lines (40 loc) · 2.18 KB

File metadata and controls

49 lines (40 loc) · 2.18 KB
title = (Assignment Operator) (Transact-SQL)
description = (Assignment Operator) (Transact-SQL)
author rwestMSFT
ms.author randolphwest
ms.date 03/14/2017
ms.service sql
ms.subservice t-sql
ms.topic reference
ms.custom
ignite-2025
helpviewer_keywords
operators [Transact-SQL], assignment
assignment operators [Transact-SQL]
headings [SQL Server columns]
relationships [SQL Server], assignment operators
column headings [SQL Server]
dev_langs
TSQL
monikerRange >=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric || =fabric-sqldb

= (Assignment Operator) (Transact-SQL)

[!INCLUDE SQL Server Azure SQL Database Azure SQL Managed Instance Azure Synapse Analytics Parallel Data Warehouse fabricse FabricDW FabricSQLDB]

The equal sign (=) is the only [!INCLUDEtsql] assignment operator. In the following example, the @MyCounter variable is created, and then the assignment operator sets @MyCounter to a value returned by an expression.

DECLARE @MyCounter INT;  
SET @MyCounter = 1;  

The assignment operator can also be used to establish the relationship between a column heading and the expression that defines the values for the column. The following example displays the column headings FirstColumnHeading and SecondColumnHeading. The string xyz is displayed in the FirstColumnHeading column heading for all rows. Then, each product ID from the Product table is listed in the SecondColumnHeading column heading.

-- Uses AdventureWorks  
  
SELECT FirstColumnHeading = 'xyz',  
       SecondColumnHeading = ProductID  
FROM Production.Product;  
GO  

See Also

Operators (Transact-SQL)
Compound Operators (Transact-SQL)
Expressions (Transact-SQL)