General information
Forum:
Microsoft SQL Server
When I lauch the Query Analizer the first time and run some code for the first time the insertions work fine.
If I run the same code again I get a message saying the following :
The command(s) completed successfully.>
But, the problem is that the insertions did not work!.
For them to work again I will need to close the Query Analizer and open it again.
Here is the code that I run:
use vips
DECLARE @ac varchar(40)
DECLARE agency_cursor CURSOR FOR SELECT ac FROM agt_data
OPEN agency_cursor
WHILE (@@FETCH_STATUS = 0)
BEGIN
FETCH NEXT FROM agency_cursor INTO @ac
PRINT @ac
INSERT INTO pt_agency (ProducerCode) VALUES (@ac)
END
CLOSE agency_cursor
DEALLOCATE agency_cursor
GO
Thanks,
Sergio
Sergio,
Change your code as follows:
OPEN agency_cursor
FETCH NEXT FROM agency_cursor INTO @ac
WHILE (@@FETCH_STATUS = 0)
BEGIN
PRINT @ac
INSERT INTO pt_agency (ProducerCode) VALUES (@ac)
FETCH NEXT FROM agency_cursor INTO @ac
END
This is the proper code that you need using cursor.
Rene
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only