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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 If statement in SQL server so easy in Access

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-06-20 : 11:41:16
stuart writes "High,
I'm to convert this access query to a MS SQL 2000 Stored procedure, but I'm getting nowhere fast with the If statements, I've tried using CASE but endup with a lot of null values.

I just copied it straight from access and I know no spaces

SELECT DISTINCTROW
SMR01.[New Trust],
Left([CMGDG1],2) AS spec,
SMR01.Consultant,
Sum(IIf([inpatient/daycase]='I',1,0)) AS [Total Inps],
Sum(IIf([inpatient/daycase]='D',1,0)) AS [Total DC],
[Total Inps]+[Total DC] AS Total,
Sum(IIf([inpatient/daycase]='I'
And [Waiting List Type]=1
And [Elective Indicator]='E'
And [Waiting Time]<=998,1,0)) AS [Total WaitL],
Sum(IIf([inpatient/daycase]='I'
And [Elective Indicator]='N',1,0)) AS [Total Emerg]
FROM SMR01
GROUP BY SMR01.[New Trust], Left([CMGDG1],2), SMR01.Consultant;"
   

- Advertisement -