What does the pipe/veritcal bar character mean in TSQL? [duplicate]
Google-fu is failing me on this one. Can anyone briefly explain what the following statement would do?:
UPDATE
message WITH (ROWLOCK)
SET
message = message | 2
I found this in a trigger, and I am unable to find docs explaining what the | character does in a statement like this.
That is a bitwise OR
http://msdn.microsoft.com/en-us/library/ms176122.aspx
It's the bitwise OR operator. See this article. Effectively, message
is a bitfield, and by bitwise-ORing it with 2, you're setting the second bit. See Wikipedia's bitwise operation article for a good overview of bit-twiddling :)
| is a bitwise OR in T-SQL:
http://msdn.microsoft.com/en-us/library/ms186714.aspx
So if message contained 0, it would contain 2, if it contained 1, it would contain 3, etc.
精彩评论