34,590
社区成员
发帖
与我相关
我的任务
分享
declare @T table([col] sql_variant)
insert @T
select 1 union all
select 2 union all
select 0
select * from @T where cast(col as varchar(4)) like '%1'
declare @T1 table([col] varchar(4))
insert @T1
select 1 union all
select 2 union all
select 0
select * from @T1 where col like '%1'
/*
col
----
1
*/
-- 上面的正常,下面的不正常,因为like用于查询的字段不能是sql_variant类型的
declare @T table([col] sql_variant)
insert @T
select 1 union all
select 2 union all
select 0
select * from @T where col like '%1'
/*
Argument data type sql_variant is invalid for argument 1 of like function.
*/