码迷,mamicode.com
首页 > 数据库 > 详细

Sqlserver游标的尝试

时间:2014-09-03 10:58:26      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:os   ar   for   on   c   ad   sql   har   as   

DECLARE @ProName NVARCHAR(50)
DECLARE @CityName NVARCHAR(50)
DECLARE @ProId INT
DECLARE @CityId INT
DECLARE Test_Cursor CURSOR 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

Sqlserver游标的尝试

标签:os   ar   for   on   c   ad   sql   har   as   

原文地址:http://www.cnblogs.com/baiyunchen/p/3952931.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!