我在查询中遇到以下问题
将 nvarchar 值“190,191,192”转换为数据类型 int 时转换失败。
询问
SELECT *
FROM SGI_User
JOIN SGI_Agency_User
ON SGI_User.User_Id = SGI_Agency_User.User_Id
WHERE SGI_Agency_User.Agency_Id IN
(select STUFF(
(select CAST(',' as varchar(max)), cast(agency_id as int)
from sgi_agency
where filial_de_int_matriz = 192 or
(Agency_Id = 192 and Filial_De_int_matriz = 0)
for xml path('')), 1, 1, ''))
and SGI_User.Deleted = 0
这 3 个值190,191,192
来自此查询
select STUFF(
(select CAST(',' as varchar(max)), cast(agency_id as int)
from sgi_agency
where filial_de_int_matriz = 192 or
(Agency_Id = 192 and Filial_De_int_matriz = 0)
for xml path('')), 1, 1, '')
返回 avarchar
但我的SGI_Agency_User.Agency_Id
领域是INT
我尝试了一些CAST
但没有成功。我该怎么做这个查询?