Sample Header Ad - 728x90

How does the operator "&" work in sql server?

6 votes
1 answer
29700 views
I was running a trace on one of our test servers when someone did this: enter image description here and one of the queries I could catch in the trace was: declare @UserOption int select @UserOption=convert(int, c.value) from sys.configurations c where c.name='user options' SELECT CAST(@UserOption & 1 AS bit) AS [DisableDefaultConstraintCheck], CAST(@UserOption & 2 AS bit) AS [ImplicitTransactions], CAST(@UserOption & 4 AS bit) AS [CursorCloseOnCommit], CAST(@UserOption & 8 AS bit) AS [AnsiWarnings], CAST(@UserOption & 16 AS bit) AS [AnsiPadding], CAST(@UserOption & 32 AS bit) AS [AnsiNulls], CAST(@UserOption & 64 AS bit) AS [AbortOnArithmeticErrors], CAST(@UserOption & 128 AS bit) AS [IgnoreArithmeticErrors], CAST(@UserOption & 256 AS bit) AS [QuotedIdentifier], CAST(@UserOption & 512 AS bit) AS [NoCount], CAST(@UserOption & 1024 AS bit) AS [AnsiNullDefaultOn], CAST(@UserOption & 2048 AS bit) AS [AnsiNullDefaultOff], CAST(@UserOption & 4096 AS bit) AS [ConcatenateNullYieldsNull], CAST(@UserOption & 8192 AS bit) AS [NumericRoundAbort], CAST(@UserOption & 16384 AS bit) AS [AbortTransactionOnError] there is lots of information that can fit in a int if you know - How does the operator & work?
Asked by Marcello Miorelli (17274 rep)
Aug 17, 2016, 12:12 PM
Last activity: Apr 18, 2019, 07:32 PM