日期:2014-05-18 浏览次数:20495 次
Declare @Id int Declare @Name varchar(10) DECLARE TabA CURSOR FOR SELECT aid, aname FROM AA Open TabA Fetch Next From TabA into @Id,@Name while(@@FETCH_STATUS=0) begin insert into BB values(@Id,@Name) Fetch Next From TabA into @Id,@Name end Close TabA
------解决方案--------------------
Delcare @name varchar(50) Declare MyCursor Cursor for select Aname from A Open MyCursor FETCH NEXT FROM Aname into @name WHILE @@FETCH_STATUS = 0 BEGIN insert into B(BName) values(@name) FETCH NEXT FROM MyCursor into @name END CLOSE MyCursor DEALLOCATE MyCursor
------解决方案--------------------
DECLARE @CityName NVARCHAR(100) DECLARE table_cur CURSOR FOR SELECT top 10 CityName FROM City OPEN table_cur FETCH NEXT FROM table_cur INTO @CityName WHILE( @@fetch_status = 0) BEGIN PRINT @CityName FETCH NEXT FROM table_cur INTO @CityName END DEALLOCATE table_cur
------解决方案--------------------
加到最后:
Declare @Id int Declare @Name varchar(10) DECLARE TabA CURSOR FOR SELECT aid, aname FROM AA Open TabA Fetch Next From TabA into @Id,@Name while(@@FETCH_STATUS=0) begin insert into BB values(@Id,@Name) Fetch Next From TabA into @Id,@Name end Close TabA DEALLOCATE TabA