What does “&” means in this sql where clause?

后端 未结 5 713
长情又很酷
长情又很酷 2021-01-24 20:29

What does the \"&\" mean here:

select pt.TrTp, sum(pt.TrTp)
from ProdTr pt
where TransSt & 16 <> 16  // this is the row that i don´t understand..
g         


        
5条回答
  •  温柔的废话
    2021-01-24 20:46

    It's a bitwise AND.

    The & bitwise operator performs a bitwise logical AND between the two expressions, taking each corresponding bit for both expressions. The bits in the result are set to 1 if and only if both bits (for the current bit being resolved) in the input expressions have a value of 1; otherwise, the bit in the result is set to 0.

    From http://msdn.microsoft.com/en-us/library/ms174965.aspx

    In this case it's used with a flag, where multiple values are stored in one field and then the bitwise AND operation is used to check for specific states - or in this particular case - check that the field doesn't contain the specified state.

提交回复
热议问题