
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[PAKETTEKI_AMELIYATLARIN_ITEMID]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION [dbo].PAKETTEKI_AMELIYATLARIN_ITEMID
go

CREATE FUNCTION [dbo].[PAKETTEKI_AMELIYATLARIN_ITEMID] (@PaketId as Integer)  
RETURNS nvarchar(1000) AS  
BEGIN 
declare @ALISTE as nvarchar(1000),
	@PAKET as nvarchar(100)
SET @ALISTE = '' 
DECLARE PAKET_AMELIYAT_CURSOR CURSOR
   FOR SELECT TA.ITEMID  FROM TDRAMELIYATPAKET  INNER JOIN TDRAMELIYATPAKETAMELIYATLARI TA ON TDRAMELIYATPAKET.DRPAKETID=TA.DRPAKETID  WHERE TDRAMELIYATPAKET.AKTIF=1 AND TDRAMELIYATPAKET.DRPAKETID = @PaketId ORDER BY ITEMID
OPEN PAKET_AMELIYAT_CURSOR
FETCH NEXT FROM PAKET_AMELIYAT_CURSOR INTO @PAKET
WHILE @@FETCH_STATUS = 0
BEGIN
	SET @ALISTE = @ALISTE + @PAKET +', '
	FETCH NEXT FROM PAKET_AMELIYAT_CURSOR INTO @PAKET
END
	IF CHARINDEX(',', ISNULL(@ALISTE,' ')) <> 0
		SET @ALISTE = LEFT(@ALISTE,LEN(@ALISTE)-1)
return @ALISTE
END
GO


