How do I store the select column in a variable?

前端 未结 3 1463
你的背包
你的背包 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:47

    Assuming such a query would return a single row, you could use either

    select @EmpId = Id from dbo.Employee
    

    Or

    set @EmpId = (select Id from dbo.Employee)
    

提交回复
热议问题