I got a sql function that returns a string array,..., now I want to convert it into an int array,
Msg 245, Level 16, State 1, Line 14 Conversion failed when converting the varchar value ',' to data type int.
My code :
DECLARE @ListZoneId as varchar(200);
SET @ListZoneId = [dbo].[CMS_fGetListOfZoneIdByParentZoneId](1)
//sql function return string array : '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)