我有一个sql函数返回一个字符串数组,...,现在我想把它转换成一个int数组,
消息245,级别16,状态1,行14转换时转换失败 varchar值','数据类型int。
我的代码:
DECLARE @ListZoneId as varchar(200);
SET @ListZoneId = [dbo].[CMS_fGetListOfZoneIdByParentZoneId](1)
// sql函数返回字符串数组:' 1,22,30,14'
declare @tempTb table
(
TempId int
)
while charindex(',',@ListZoneId) > 0
begin
insert into @tempTb select substring(@ListZoneId,1,1)
SET @ListZoneId = substring(@ListZoneId,3,len(@ListZoneId))
end
SELECT COUNT(*) from Shop as s inner join ShopInZone as z on s.Id=z.ShopId inner join Zone as zo on zo.Id = z.ZoneId
where z.ZoneId IN ( select * from @tempTb)