Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 431
IronicMuffin Avatar asked Feb 14 '11 14:02

IronicMuffin


2 Answers

That is a bitwise OR

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

like image 90
Randy Minder Avatar answered Oct 05 '22 18:10

Randy Minder


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 :)

like image 38
Matt Gibson Avatar answered Oct 05 '22 18:10

Matt Gibson