DECLARE @length int --长度
DECLARE @next int --标量
DECLARE @did int --地区id
DECLARE @sId1 int
SET @stId=@@IDENTITY
SET @next=0
SELECT @length=COUNT(*) FROM Subject
WHILE(@next<@length)
BEGIN
SELECT TOP 1 @did=ccId FROM CityCountry
WHERE ccId NOT IN (SELECT TOP @next ccId FROM CityCountry)
INSERT INTO IP_District_Sub_Relation(dId,sId,usrCustomID,usrState,usrRebate)
VALUES(@dId,@sId1,0,0,0)
SET @next=@next+1
END
消息 102,级别 15,状态 1,过程 MS_InsertIP_Subject,第 71 行'@next' 附近有语法错误。
老提示错误,是怎么回事呢?
WHERE ccId NOT IN (SELECT TOP (@next) ccId FROM CityCountry)