Reputation: 10806
In SQL Server, I'm dealing with these columns:
tblSchedule
ID
StaffID
StartTime
EndTime
I want to include a boolean field in my result set that indicates whether StartTime and EndTime are equal. Something analogous to this:
SELECT StaffID, StartTime, EndTime, (StartTime = EndTime) AS AreEqual
FROM tblSchedule Where StaffID = xxx
But I'm not sure of the actual syntax for an operation like that.
Upvotes: 22
Views: 7397
Reputation: 1574
I think this is what you are looking for
SELECT StaffID
, StartTime
, EndTime
, Case
When StartTime = EndTime Then 1
else 0
End as AreEqual
FROM tblSchedule
Where StaffID = xxx
Upvotes: 27
Reputation: 100607
Try using a CASE WHEN
in your SELECT
statement; something like this:
SELECT CASE WHEN StartTime = EndTime THEN 1 ELSE 0 END AS AreEqual
FROM MyTable
Upvotes: 7