0

I'm trying to get a true/false column in my select statement to tell me if two other columns are equal

SELECT 
    dol.RequestedBy = dol.RequestedFor AS "EQ",
    dol.*
FROM DaysOnLeave AS dol WHERE Status = 'Approved';

But having the = there gives a Incorrect Syntax error.

RequestedBy and RequestedFor are both foreign keys to the same table (Numeric)

1 Answers1

2

The syntax you're trying to use does not work in SQL Server. Also there is no boolean datatype in SQL Server. Use case expression for this:

SELECT CASE WHEN dol.RequestedBy = dol.RequestedFor THEN 1 ELSE 0 END AS "EQ", ...
Salman A
  • 262,204
  • 82
  • 430
  • 521