Assignment Operator

The name itself is saying that, it assigns values to the variables or fields of a table. We have only one assignment operator ‘=’ in SQL Server. It plays a key role while writing queries. We cannot write complex queries without Assignment Operator.  

Syntax:
Field/variable = Expression

Examples:
——————————————————————————
USE [ADVENTUREWORKS2012]
GO
——————————————————————————
— Assigned ‘AUSTRALI0001’ to [AccountNumber] Field.
——————————————————————————
SELECT [BusinessEntityID], [Name]
FROM [Purchasing].[Vendor]
WHERE [AccountNumber] = ‘AUSTRALI0001’
——————————————————————————
— Assigned ‘SQLVersity’ to @My_Name variable.
——————————————————————————
DECLARE @My_Name Varchar(100) = ‘SQLVersity’
SELECT @My_Name AS My_Name
——————————————————————————
— Assigned sum of StoreID and TerritoryID to [ID_Sum].
——————————————————————————
SELECT TOP 3 [ID_Sum] = StoreID + TerritoryID
FROM [Sales].[Customer]
——————————————————————————

Result:

Assignment Operator Example

Leave a Reply

Your email address will not be published. Required fields are marked *