1

My SQL code looks like this:

SELECT 
    Scores.PupilId, Scores.BoysName, Scores.FormGroup,
    IF (Scores.FormGroup = "10SB", "Great", "ok")
FROM 
    Scores

I get this message

no such function: if: SELECT Scores.PupilId, Scores.BoysName, Scores.FormGroup,
if(Scores.FormGroup="10SB","Great","ok")
FROM Scores

This is flat file database

Can anyone please help me understand why I am getting a message?

Shawn
  • 4,758
  • 1
  • 20
  • 29

1 Answers1

2

The correct ANSI-standard conditional expression in SQL is the case expression:

SELECT Scores.PupilId, Scores.BoysName, Scores.FormGroup,  
       (CASE WHEN Scores.FormGroup = '10SB' THEN 'Great' ELSE 'ok' END)
FROM Scores ;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • 1
    Yes. MS SQL 2012 added an `IIF()` conditional function, but I believe it essentially evaluates out to a `CASE` statement. – Shawn Jul 11 '18 at 20:18