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


CREATE FUNCTION dbo.fn_MuayeneEk3000Detay (@HMUAYENEID INT)
RETURNS NVARCHAR(MAX)
AS
BEGIN
    DECLARE @Sonuc NVARCHAR(MAX);

    SELECT @Sonuc = 
        CASE WHEN ISNULL(SAT,'')<>'' THEN N'[SAT] : '+ CONVERT(VARCHAR(10),SAT, 104)+char(13)  ELSE '' END+
        CASE WHEN ISNULL(USG_YONTEM,'')<>'' THEN N'[USG Yöntem]'+char(13)+USG_YONTEM+char(13)  ELSE '' END+
        CASE WHEN ISNULL(USG_UTERUS,'')<>'' THEN N'[USG Uterus]'+char(13)+USG_UTERUS+char(13)  ELSE '' END+
        CASE WHEN ISNULL(USG_ENDOMETRIUM,'')<>'' THEN N'[Endometrium Özelliği]'+char(13)+USG_ENDOMETRIUM+char(13)  ELSE '' END+
        CASE WHEN ISNULL(USG_ENDOMETRIUM_MM,0)<>0 THEN N'[Endometrium (mm)] : '+CAST(USG_ENDOMETRIUM_MM AS NVARCHAR)+char(13)  ELSE '' END+
        CASE WHEN ISNULL(USG_SAGADNEX,'')<>'' THEN N'[USG Sağ Adnex]'+char(13)+USG_SAGADNEX+char(13)  ELSE '' END+
        CASE WHEN ISNULL(USG_SOLADNEX,'')<>'' THEN N'[USG Sol Adnex]'+char(13)+USG_SOLADNEX+char(13)  ELSE '' END+
        CASE WHEN ISNULL(USG_MEME,'')<>'' THEN N'[USG Meme]'+char(13)+USG_MEME+char(13)  ELSE '' END+
        CASE WHEN ISNULL(USG_DIGER,'')<>'' THEN N'[USG Diğer]'+char(13)+USG_DIGER+char(13)  ELSE '' END
    FROM HMUAYENEEK3000 
    WHERE HMUAYENEID = @HMUAYENEID;

    RETURN ISNULL(@Sonuc, '');
END
GO