DECLARE @START VARCHAR(30);
DECLARE @END VARCHAR(30);
DECLARE @BIRIM VARCHAR(10);
SET @START='2015-06-01 00:00:00';
SET @END='2015-06-30 00:00:00';
SET @BIRIM='200';
IF ((@BIRIM='200') and datediff( day,@START, GETDATE())>7 )
select distinct(orn.ornek_adi + '' + orn.ornek_soyadi) as HASTA,orn.ornek_id as ORNEKNO,
datediff( day,orn.ornek_gelis_tarihi, GETDATE()) as GECENSURE,
orn.ornek_gelis_tarihi as ORNEKGELISTARIHI,
orn.ornek_protokol as KABULNO,orn.ornek_cinsiyet as CINSIYET,
orn.ornek_tc_kimlik as TCNO, orn.ornek_kayit_tarihi AS ORNEKKAYITTARIHI,
orn.ornek_dosya_no as HASTAARSİV,snc.sonuc_cihazdan_alma_tarih as CIHAZDANSONUCALMATARIHI,
snc.sonuc as SONUC,snc.sonuc_aciklama as SONUCACIKLAMA from
lis.. ViewOrnek orn,lis..ViewSonuc snc,lis..test tst,lis..unite u
where orn.ornek_id=snc.sonuc_ornekno
AND tst.test_id=snc.test_id
AND tst.test_ontanimli_unite=u.unite_id
AND snc.sonuc_cihazdan_alma_tarih is null
AND snc.sonuc is null
AND snc.numune_kabul is null
AND orn.ornek_gelis_tarihi>=@START
AND orn.ornek_gelis_tarihi<=@END
AND u.unite_id=@BIRIM
AND tst.test_adi <> 'Gluko test (Hastabaşı, glukometrik)'
ELSE IF ((@BIRIM='116') and datediff( day,@START, GETDATE())>4 )
select distinct(orn.ornek_adi + '' + orn.ornek_soyadi) as HASTA,orn.ornek_id as ORNEKNO,
datediff( day,orn.ornek_gelis_tarihi, GETDATE()) as GECENSURE,
orn.ornek_gelis_tarihi as ORNEKGELISTARIHI,
orn.ornek_protokol as KABULNO,orn.ornek_cinsiyet as CINSIYET,
orn.ornek_tc_kimlik as TCNO, orn.ornek_kayit_tarihi AS ORNEKKAYITTARIHI,
orn.ornek_dosya_no as HASTAARSİV,snc.sonuc_cihazdan_alma_tarih as CIHAZDANSONUCALMATARIHI,
snc.sonuc as SONUC,snc.sonuc_aciklama as SONUCACIKLAMA from
lis.. ViewOrnek orn,lis..ViewSonuc snc,lis..test tst,lis..unite u
where orn.ornek_id=snc.sonuc_ornekno
AND tst.test_id=snc.test_id
AND tst.test_ontanimli_unite=u.unite_id
AND snc.sonuc_cihazdan_alma_tarih is null
AND snc.sonuc is null
AND snc.numune_kabul is null
AND orn.ornek_gelis_tarihi>=@START
AND orn.ornek_gelis_tarihi<=@END
AND u.unite_id=@BIRIM
AND tst.test_adi <> 'Gluko test (Hastabaşı, glukometrik)'
ELSE IF ((@BIRIM='192') and datediff( day,@START, GETDATE())>10)
select distinct(orn.ornek_adi + '' + orn.ornek_soyadi) as HASTA,orn.ornek_id as ORNEKNO,
datediff( day,orn.ornek_gelis_tarihi, GETDATE()) as GECENSURE,
orn.ornek_gelis_tarihi as ORNEKGELISTARIHI,
orn.ornek_protokol as KABULNO,orn.ornek_cinsiyet as CINSIYET,
orn.ornek_tc_kimlik as TCNO, orn.ornek_kayit_tarihi AS ORNEKKAYITTARIHI,
orn.ornek_dosya_no as HASTAARSİV,snc.sonuc_cihazdan_alma_tarih as CIHAZDANSONUCALMATARIHI,
snc.sonuc as SONUC,snc.sonuc_aciklama as SONUCACIKLAMA from
lis.. ViewOrnek orn,lis..ViewSonuc snc,lis..test tst,lis..unite u
where orn.ornek_id=snc.sonuc_ornekno
AND tst.test_id=snc.test_id
AND tst.test_ontanimli_unite=u.unite_id
AND snc.sonuc_cihazdan_alma_tarih is null
AND snc.sonuc is null
AND snc.numune_kabul is null
AND orn.ornek_gelis_tarihi>=@START
AND orn.ornek_gelis_tarihi<=@END
AND u.unite_id=@BIRIM
AND tst.test_adi <> 'Gluko test (Hastabaşı, glukometrik)'
Ben uzun uğraşlar sonrası yukarıdaki else ifle çözdüm sorunu fakat bunu daha kısa yapabilir miyiz?