DEFINITIONS

Definitions More Info.
Definition ID71
TitleSQL
CategorySCRIPT
DefinitionFETCH_ILE_DEGISKENLI_INSERT_ETMEYE_GUZEL_BIR_ORNEK
Definition DescriptionUSE [cunay] GO
/****** Object: StoredProcedure [piyango].[up_FazlaCikanSayilar] Script Date: 10/14/2011 17:30:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [piyango].[up_FazlaCikanSayilar]
WITH EXECUTE AS CALLER
AS truncate table piyango.FazlaCikanSayilar
-- Declare the variables to store the values returned by FETCH.
DECLARE @NumaraHede char(10)
DECLARE @string varchar(500)
DECLARE Numara_cursor CURSOR FOR
SELECT c.name
FROM sys.columns c
INNER JOIN sys.tables t ON c.object_id = t.object_id
WHERE t.object_id = 341576255
AND c.name LIKE '%Numara%'
OPEN Numara_cursor;
-- Perform the first fetch and store the values in variables.
-- Note: The variables are in the same order as the columns
-- in the SELECT statement.

FETCH NEXT FROM Numara_cursor INTO @NumaraHede
-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN set @string= 'insert into piyango.FazlaCikanSayilar (Numara,Tane)
select '+@NumaraHede+',COUNT('+@NumaraHede+')Tane
from piyango.SayisalLoto
group by '+@NumaraHede+'
having COUNT('+@NumaraHede+')= (select max(Tanecik)MaxTane
from (select COUNT('+@NumaraHede+')Tanecik,piyango.SayisalLoto.'+@NumaraHede+'
from piyango.SayisalLoto Group By '+@NumaraHede+' )t )
Order By Tane Desc'
execute (@string)
---- Concatenate and display the current values in the variables.
--insert into piyango.hede (Column_Name)
--Values (@NumaraHede)
-- This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM Numara_cursor INTO @NumaraHede
END
CLOSE Numara_cursor;
DEALLOCATE Numara_cursor;
RecordBycunay
Record Date15-02-2012 16:34:27
Düzenle
Kopyala
Sil