How do I store the select column in a variable?

前端 未结 3 1456
你的背包
你的背包 2021-02-07 11:14

How do I store the select column in a variable?

I tried this, but it throws me an error "Incorrect syntax":

declare @EmpId int
SELECT  dbo.Employ         


        
3条回答
  •  忘了有多久
    2021-02-07 11:44

    This is how to assign a value to a variable:

    SELECT @EmpID = Id
      FROM dbo.Employee
    

    However, the above query is returning more than one value. You'll need to add a WHERE clause in order to return a single Id value.

提交回复
热议问题