SqlException:smalldatetime 和时间类型与添加运算符不兼容

SqlException : smalldatetime and time types are incompatible with add operator

我在 SQL Server 2012(具有 2008 兼容级别)上有一个数据库,我的代码如下所示:

DECLARE @BeginTime time
...
SELECT CONVERT(datetime2, BeginDate + ' ' + @BeginTime)
FROM MyTable ...

BeginDate 定义为 smalldatetime.

此代码运行良好,直到我将数据库切换到 2012 兼容级别,在这种情况下出现此错误:

SqlException : smalldatetime and time types are incompatible with add operator...

我应该在继续之前将我的 2 个操作数转换为 varchar 吗?担心性能...

感谢您的帮助。

尝试这样的事情...

DECLARE @BeginTime time;
SET @BeginTime = '12:20:00.467'

SELECT CONVERT(datetime2, BeginDate + CONVERT(SmallDateTime, @BeginTime))
FROM MyTable