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.
In SQL, problems require us to compare two columns for equality to achieve certain desired results. This can be achieved through the use of the =(equal to) operator between 2 columns names to be compared.
SQL Equal to ( = ) operator The equal to operator is used for equality test within two numbers or expressions.
As a result, SQL doesn't have the problem of ambiguity of = meaning either assignment or equality check. As a result, there is no problem with using = to check equality. On the other hand, in a programming language such as Java, single = is used for assignments, while == is used for comparison.
In SQL Server database, Equality Operator "=" is used to test for equality in a query.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With