-1

What is the difference between set and select in SQL Server as both the keywords are used to assign a parameter value in Microsoft SQL Server?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

SET uses to assign single value whereas SELECT uses to assign multiple values. For example

DECLARE @Product TABLE (ProductId INT,ProductCode VARCHAR(10), Name VARCHAR(100))
INSERT INTO @Product(ProductId,ProductCode,Name) 
(SELECT 1,'P001','Computer')

DECLARE @variable1 INT,@variable2 AS VARCHAR(100),@variable3 AS VARCHAR(100)
SET @variable1 = (SELECT ProductId FROM @Product)

SELECT @variable2 =  ProductCode, @variable3 = Name FROM @Product
SELECT @variable1,@variable2,@variable3
Emdad
  • 822
  • 7
  • 14