


--DECLARE @Tarih      DATE      = @BaslangicTarih --'2025-01-01';
--DECLARE @BitisTarih DATE = @BitisTarih2--'2026-03-01';
--DECLARE @PaketTipi  INT   = @PaketTipi2--3;  -- 3 : yatan 106  ,   13 :  ayatan 106
--DECLARE @TedaviTipi INT  = @TedaviTipi2--2;   -- <<< TEDAVİ TİPİ 0 HEPSİ   1:A  2:Y   3:G
--DECLARE @SubeId INT      = @SubeId2--3;   -- <<< ŞUBE
--SELECT  * FROM  [TUSSOTOGONDERIMAYAR] WHERE ACIKLAMA='@@@' or ACIKLAMA= '~~sina 106 cikis gonderim' AND  SUBEID=3
--EXEC SPUSS_106_OTO_GONDERIM_KAYITLARI_TOPLU_INSERT


IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[SPUSS_106_OTO_GONDERIM_KAYITLARI_TOPLU_INSERT]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE SPUSS_106_OTO_GONDERIM_KAYITLARI_TOPLU_INSERT
GO

CREATE PROCEDURE [dbo].[SPUSS_106_OTO_GONDERIM_KAYITLARI_TOPLU_INSERT] 

AS
BEGIN


	DELETE [TUSSOTOGONDERIMAYAR] WHERE ACIKLAMA='@@@' or ACIKLAMA= '~~sina 106 cikis gonderim'


	DECLARE @SUBEID INT

	DECLARE sube_cursor CURSOR FOR
	SELECT DISTINCT SUBEID
	FROM subeler

	OPEN sube_cursor
	FETCH NEXT FROM sube_cursor INTO @SUBEID

	WHILE @@FETCH_STATUS = 0
	BEGIN

	     exec SPUSS_106_OTO_GONDERIM_OLUSTUR '2025-01-01','2026-12-31', 14 /*106 genel*/ ,0 /*tüm hastalar*/    ,@SUBEID /*subeıd*/

		--exec SPUSS_106_OTO_GONDERIM_OLUSTUR '2025-01-01','2026-12-31', 3 /*106 Y*/ ,2 /*yatan*/   ,@SUBEID /*subeıd*/
		
		--exec SPUSS_106_OTO_GONDERIM_OLUSTUR '2025-01-01','2026-12-31', 3 /*106 Y*/ ,3 /*gb*/      ,@SUBEID /*subeıd*/

		--exec SPUSS_106_OTO_GONDERIM_OLUSTUR '2025-01-01','2026-12-31', 13 /*106 A*/ ,1 /*AYAKTAN*/      ,@SUBEID /*subeıd*/

		--exec SPUSS_106_OTO_GONDERIM_OLUSTUR '2025-01-01','2026-12-31', 13 /*106 A*/ ,3 /*gb*/      ,@SUBEID /*subeıd*/


		FETCH NEXT FROM sube_cursor INTO @SUBEID
	END

	CLOSE sube_cursor
	DEALLOCATE sube_cursor
END


