开发者

What does the pipe/veritcal bar character mean in TSQL? [duplicate]

This question already has answers here: 开发者_开发技巧 What does the pipe operator do in SQL? (4 answers) Closed 7 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜