MSSQL Cursor Fetch Kullanarak Döngü ile Select İnsert Into

[code lang=”sql”]
USE [TestDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SP_Test]
AS

DECLARE @ParametersOne INT
DECLARE @ParametersTwo INT

DECLARE CRS_Test CURSOR FOR
select TcNo,Ad from Kisi

CREATE TABLE TempKisiler(
[ParameterOne] [int] NOT NULL,
[ParameterTwo] [int] NULL,
[ParameterThree] [nvarchar] (100) NULL,
[ParameterFour] [nvarchar] (100) NULL,
)

OPEN CRS_Test

FETCH NEXT FROM CRS_Test INTO @ParametersOne,@ParametersTwo
WHILE @@FETCH_STATUS =0
BEGIN
insert into TempKisiler
Select * from TempKisi where TcNo=@ParametersOne and Ad=@ParametersTwo
FETCH NEXT FROM CRS_Test INTO @ParametersOne,@ParametersTwo
END

CLOSE CRS_Test

DEALLOCATE CRS_Test

Bir cevap yazın