在单个 sql 语句中按位加减

Bitwise Addition and Subtraction in a single sql statement

我想从按位字段中删除一个标志,同时我想添加两个标志

Declare @status int = 3
SET @status &= ~3 -- this will remove 1 and 2 if exists
SET @status |= 12 -- this will add 4 and 8 if exists

我想同时执行这两个操作,因为它用在像

这样的更新语句中
SET @status = (@status | 12 ) - (CASE WHEN (@status & 2 = 2) THEN 2 ELSE 0 END) - (CASE WHEN (@status & 1 = 1) THEN 1 ELSE 0 END)

任何人都知道如何使用按位运算符和加法部分来做减法部分。

有点像,

SET @status |= 12 & ~2 --But this doesn't do what I want

提前致谢。

这不行吗?

SET @status = ((@status & ~3) | 12)