begin
INSERT INTO IP_Subject(stId,sName,sIndex,sState,sRevalue,
sReturnState,sAddTime,sEndTime,sOPUid,sPic,sText,sNote1,sNote2)
VALUES(@stId,@sName,@sIndex,@sState,@sRevalue,@sReturnState,getdate(),
getdate(),@sOPUid,@sPic,@sText,@sNote1,@sNote2)
DECLARE @length int --长度
DECLARE @next int --标量
DECLARE @did int --地区id
DECLARE @sId1 int --获取插入的id
SET @sId1=@@IDENTITY
SET @next=0
SELECT @length=COUNT(*) FROM IP_CityCountry --获取长度
WHILE(@next<@length)
BEGIN
SELECT TOP 1 @did=ccId FROM IP_CityCountry
WHERE ccId NOT IN (SELECT TOP (@next) ccId FROM IP_CityCountry)
INSERT INTO IP_District_Sub_Relation(dId,sId,usrCustomID,usrState,usrRebate)
VALUES(@dId,@sId1,0,0,@sRevalue)
--exec MS_InsertIP_Subject 2,'修改密码',19,1,0.00,21,0,'','','','',0,0
SET @next=@next+1
END
SELECT @sId1
END
这是我写的一个循环插入的存储过程。发现,执行的时候效率很慢。求高手指点,提高其效率!</p>
相关分类