Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

count (case when) not working in sql

$
0
0

Hi All,

I am trying to find the count of members for a perticular date range, it seems not working correclty.

Could any one help me out.

here is the query...I am getting same output for all the cases..please help

Select

t

.MemberNbr,t.patcom

,

count(casewhendatediff(d, mbrs.DischargeDate,convert(datetime,convert(varchar(12),t.specificdateofservice),112))between-1and-365then t.MemberNbrelse 0end)as edvisits365daysprior

,

count(casewhendatediff(d, mbrs.DischargeDate,convert(datetime,convert(varchar(12),t.specificdateofservice),112))between 1and 3then t.MemberNbrelse 0end)as edvisits3Days

,

count(casewhendatediff(d, mbrs.DischargeDate,convert(datetime,convert(varchar(12),t.specificdateofservice),112))between 1and 30then t.MemberNbrelse 0end)as edvisits30Days

,

count(casewhendatediff(d, mbrs.DischargeDate,convert(datetime,convert(varchar(12),t.specificdateofservice),112))between 1and 60then t.MemberNbrelse 0end)as edvisits60Days

,

count(casewhendatediff(d, mbrs.DischargeDate,convert(datetime,convert(varchar(12),t.specificdateofservice),112))between 1and 90then t.MemberNbrelse 0end)as edvisits90Days

--,*--membernbr,specificdateofservice,count( membernbr)--, specificdateofservice)as visitcount--, patcom

--Into #Tmp_PPCSEDCnt1

From

stg_tbl_InPatientPrepost Mbrs

join

#Tmp_MCCSEDVisits t

on

mbrs.MemberNbr=t.MemberNbr

--where UPPER(t.MR_Line_Desc) in ('FOP EMERGENCY ROOM - HOSPITAL', 'FOP EMERGENCY ROOM Urgent Care',

--'PROF ER VISITS AND OBSERVATION CARE')

group

by t.MemberNbr,t.patcom


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>