 IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ENT_YBBYS_RADYOLOJI_TETKIK_LISTESI]') AND OBJECTPROPERTY(id,N'IsVIew') = 1)
BEGIN
    INSERT INTO SCRIPT_BACKUPS (SCRIPTNAME,SCRIPT,SCRIPTDATE) SELECT 'ENT_YBBYS_RADYOLOJI_TETKIK_LISTESI' SCRIPTNAME,OBJECT_DEFINITION(OBJECT_ID('ENT_YBBYS_RADYOLOJI_TETKIK_LISTESI')) AS SCRIPT,GETDATE() AS SCRIPTDATE
    DROP VIEW ENT_YBBYS_RADYOLOJI_TETKIK_LISTESI
END
go

CREATE VIEW  ENT_YBBYS_RADYOLOJI_TETKIK_LISTESI
AS

SELECT  TETKIKTURADI,SUBEID, HKIMLIKID [KimlikEntegreReferansKodu],HDOSYAID [HbysDosyaId],TETKIKADI,RAPORBASLIK, LUYGBOLUM,LUYGDRADI ,ANABOLUM,ITARIH,HTRAPORU,HTSONUC FROM [VWTETKIK] WITH(NOLOCK) 
LEFT JOIN (SELECT COUNT(*) DETAYADET,HTETKIKID FROM HTETKIKDETAY WITH(NOLOCK) GROUP BY HTETKIKID) T ON T.HTETKIKID=[VWTETKIK].HTETKIKID

WHERE  ISNULL(DETAYADET,0)=0 AND DURUM=2 /*AND HKIMLIKID = 728499 AND HDOSYAID = 3483526 */





