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 2005 Forums
 Transact-SQL (2005)
 IIF function in SQL server

Author  Topic 

dsousa187
Starting Member

2 Posts

Posted - 2012-08-14 : 01:13:11
How could I translate this SQL query in MS access into SQL SERVER query or t_SQL.
SELECT student.district, Sum(IIf([educlevel]="Primary",1,0)) AS Primary
FROM student
GROUP BY student.district;

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-14 : 01:23:12
[code]
SELECT student.district, Sum(CASE WHEN [educlevel]="Primary" THEN 1 ELSE 0 END) AS Primary
FROM student
GROUP BY student.district;
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-14 : 01:24:05
and one more thing
IIF is available in SQL from 2012 version onwards

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -