I Want to Select opposite Value of AbsenceStatus in tsql ,
AbsenceStatus DataType is Bit
SELECT
[Date],
NOT(AbsenceStatus) As IsWorkday
FROM
tkp_DailyStatistics
I Want to Select opposite Value of AbsenceStatus in tsql ,
AbsenceStatus DataType is Bit
SELECT
[Date],
NOT(AbsenceStatus) As IsWorkday
FROM
tkp_DailyStatistics
You can use -
:
select 1 - b
Here is a db<>fiddle.
Note: This converts the value to a number, so you might really want:
select convert(bit, 1 - b)
In addition to Gordon's answer +1, we could also try using the modulus here:
SELECT
[Date],
(AbsenceStatus + 1) % 2 AS IsWorkday
FROM tkp_DailyStatistics;
This logic works because a zero absent status becomes 1, while a 1 absent status gets incremented to 2, but then the modulus takes it back to zero.