DECLARE @ProName NVARCHAR(50)
DECLARE @CityName NVARCHAR(50)
DECLARE @ProId INT
DECLARE @CityId INT
DECLARE Test_Cursor CURSOR LOCAL READ_ONLY STATIC FORWARD_ONLY FOR
SELECT a.AreaId,a.AreaName,b.AreaName FROM AreaFull AS a RIGHT JOIN AreaFull AS b ON a.AreaPid=b.AreaId WHERE a.AreaPid>34
OPEN Test_Cursor
FETCH NEXT FROM Test_Cursor INTO @CityId,@CityName,@ProName
WHILE @@FETCH_STATUS = 0
BEGIN
SET @ProId=(SELECT ID FROM dbo.Web_Area WHERE Name=@ProName AND OrderId=27 )
INSERT INTO Web_Area(Name,HeadID,LV,Family,OrderId) VALUES(@CityName,@ProId,4,4,28)
FETCH NEXT FROM Test_Cursor INTO @CityId,@CityName,@ProName
END
CLOSE Test_cursor
DEALLOCATE Test_cursor
SELECT * FROM dbo.Web_Area