title: Translating Access SQL Statement to T-SQL
body: <p>I have the following code, which i generated using Access DB, i need to translate it to
  T-SQL, am mainly getting error on the IIF statement</p>
  
  <pre><code>SELECT dbo.casyAgeGroups.Sequence, dbo.casyAgeGroups.Description, 
  Sum(IIf([gender]='Male' And [age]&gt;=[startage] And [age]&lt;=[endage],1,0)) AS Male, 
  Sum(IIf([gender]='Female' And [age]&gt;=[startage] And [age]&lt;=[endage],1,0)) AS Female
  
   FROM dbo.casyAgeGroups, [qryStats-AgeGenderProfileDetails]
  GROUP BY dbo.casyAgeGroups.Sequence, 
           dbo.casyAgeGroups.Description, 
           [qryStats-AgeGenderProfileDetails].EntityType
  HAVING ((([qryStats-AgeGenderProfileDetails].EntityType)=0));
  </code></pre>