将您的数组转换为具有一列的临时表,然后从 ID 所在的目标表中删除(从临时表中选择 ID)
这是一个例子:
declare @RegionID varchar(50)
SET @RegionID = '853,834,16,467,841'
declare @S varchar(20)
if LEN(@RegionID) > 0 SET @RegionID = @RegionID + ','
CREATE TABLE #ARRAY(region_ID VARCHAR(20))
WHILE LEN(@RegionID) > 0 BEGIN
SELECT @S = LTRIM(SUBSTRING(@RegionID, 1, CHARINDEX(',', @RegionID) - 1))
INSERT INTO #ARRAY (region_ID) VALUES (@S)
SELECT @RegionID = SUBSTRING(@RegionID, CHARINDEX(',', @RegionID) + 1, LEN(@RegionID))
END
delete from from your_table
where regionID IN (select region_ID from #ARRAY)