= (指派運算子) (Transact-SQL)

適用于: Microsoft Fabric 中 Microsoft Fabric 倉儲中的 SQL Server Azure SQL 資料庫 Azure SQL 受控執行個體 Azure Synapse Analytics Analytics Platform System (PDW) SQL 分析端點

等號 (=) 是唯一的 Transact-SQL 指派運算子。 下列範例會先建立 @MyCounter 變數,然後指派運算子再將 @MyCounter 設為運算式所傳回的值。

DECLARE @MyCounter INT;  
SET @MyCounter = 1;  

您也可以利用指派運算子來建立資料行標題和定義資料行值的運算式之間的關聯性。 下列範例會顯示資料行標題 FirstColumnHeadingSecondColumnHeading。 所有資料列的 xyz 資料行標題都會顯示 FirstColumnHeading 字串。 之後,Product 資料表中的每個產品識別碼都會列在 SecondColumnHeading 資料行標題中。

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

另請參閱

運算子 (Transact-SQL)
複合運算子 (Transact-SQL)
運算式 (Transact-SQL)