Blog Of Sem: sql fetch

sql fetch

--FATURALAR IPTALLERIN YERINE
DECLARE @TSQL varchar(8000), @HASTAKODU VARCHAR(10), @FATURATARIH VARCHAR(10)
DECLARE TENAY2ZV_VIEW_IPTAL_FATURA_LOG CURSOR FOR
SELECT DISTINCT FATURATARIH,HASTAKODU FROM ZV_VIEW_IPTAL_FATURA_LOG
OPEN TENAY2ZV_VIEW_IPTAL_FATURA_LOG
FETCH NEXT FROM TENAY2ZV_VIEW_IPTAL_FATURA_LOG INTO @FATURATARIH,@HASTAKODU

WHILE @@FETCH_STATUS = 0
BEGIN
--SELECT  @HASTAKODU = '31588'
--SELECT  @FATURATARIH = '2018-12-10'
--TABLOYU YARAT ONCE : SONRA ALTTAKI SELECT  @TSQL = ' SELECT * into ZV_LOGO_FATURALANMISLAR_TEMP_IPTALYERINE FROM OPENQUERY(TENAY,''SELECT * FROM V_LOGO_SATISFATURASI WHERE HASTAKODU = ''''' + @HASTAKODU + ''''' AND TARIH='''''+@FATURATARIH+'''''  '')'
  SELECT  @TSQL = 'INSERT INTO ZV_LOGO_FATURALANMISLAR_TEMP_IPTALYERINE SELECT * ,''0''  FROM OPENQUERY(TENAY,''SELECT * FROM V_LOGO_SATISFATURASI WHERE HASTAKODU = ''''' + @HASTAKODU + ''''' AND TARIH='''''+@FATURATARIH+'''''  '') AS T WHERE NOT EXISTS (Select ID From ZV_LOGO_FATURALANMISLAR_TEMP_IPTALYERINE WHERE ZV_LOGO_FATURALANMISLAR_TEMP_IPTALYERINE.ID = T.ID)'
 EXEC (@TSQL)
    FETCH NEXT FROM TENAY2ZV_VIEW_IPTAL_FATURA_LOG
    INTO @FATURATARIH, @HASTAKODU
END
CLOSE TENAY2ZV_VIEW_IPTAL_FATURA_LOG
DEALLOCATE TENAY2ZV_VIEW_IPTAL_FATURA_LOG
GO