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

CREATE VIEW  ENT_YBBYS_ODAYATAK_LISTESI
AS
SELECT TODA.SUBEID,TYATAK.ODANO,YATAKNO,YTKDURUMU,ODADURUMU,MDLYATAKKODU,YOGUNBYATAKSEVIYE,VENTILATOR ,YOGUNBAKIMODASI,
CASE WHEN YATAKTURUID=1 THEN 'STANDART YATAK'
	 WHEN YATAKTURUID=2 THEN 'DETOX YATAK'
	 WHEN YATAKTURUID=3 THEN 'YOĞUN BAKIM YATAĞI'
	 WHEN YATAKTURUID=4 THEN 'KUVÖZ'
	 END YATAKTURU,YATAKTURUID
, ODATIPIADI,  TODA.ODATIPIID
 FROM TYATAK WITH(NOLOCK)
INNER JOIN TODA ON TODA.ODANO=TYATAK.ODANO
LEFT JOIN  TODATIPI ON TODATIPI.ODATIPIID=TODA.ODATIPIID
