Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL ERROR HELP

Author  Topic 

w1102157
Yak Posting Veteran

80 Posts

Posted - 2012-07-16 : 12:07:30

hi guys i am getting and error 'Msg 206, Level 16, State 2, Line 1
Operand type clash: int is incompatible with date'

when i run the below any idea why?

select PatientKey, Count (case when Provider = 'ChelWest' AND AdmissionMethodType = 'Elective'
then StartDate Else 0 end) as [Chel West Elective From [Mirror_PCPP_Presentation].[dbo].[WholeSystemPatientMasterAdmissions1]
Group by PatientKey

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-07-16 : 12:19:07
then StartDate Else 0 end
try
then StartDate Else '19000101' end

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

jleitao
Posting Yak Master

100 Posts

Posted - 2012-07-16 : 12:21:01
try:

select PatientKey,
Count
(case
when Provider = 'ChelWest' AND AdmissionMethodType = 'Elective'
then StartDate Else NULL end)
as [Chel West Elective]
From [Mirror_PCPP_Presentation].[dbo].[WholeSystemPatientMasterAdmissions1]
Group by PatientKey


But i think wath you realy need is:

select PatientKey, count(1)
From [Mirror_PCPP_Presentation].[dbo].[WholeSystemPatientMasterAdmissions1]
WHERE Provider = 'ChelWest' AND AdmissionMethodType = 'Elective'
Group by PatientKey

Go to Top of Page
   

- Advertisement -