错误:将varchar值'...'转换为数据类型int时转换失败

时间:2018-12-28 17:20:58

标签: variables user-defined-functions

declare   @EmployeeID INT
declare   @age       varchar(4)
   select      @age = 'birthdate'  
   select      @EmployeeID = 'BusinessEntityID'

select BusinessEntityID , Birthdate 
from AdventureWorks2016.HumanResources.Employee
where BirthDate=@age  and  BusinessEntityID= @EmployeeID

错误是:

  

消息245,级别16,状态1,第58行转换时转换失败   数据类型为int的varchar值“ BusinessEntityID”。

1 个答案:

答案 0 :(得分:0)

只需输入ID,而不是字符串'BusinessEntityID'

 select      @EmployeeID = 10