Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Kwozzie
Starting Member
4 Posts |
Posted - 2012-04-15 : 23:25:26
|
Hi,I've been asked to provide extra reports for a program that uses an MSSQL server. I have some experience with MySQL so understand a fair bit of the syntax but I'm stumped by a part of a query and would like some help understanding what the (Flags & 2) part of the query is trying to achieve.Where CreditLimit > 0 And (Flags & 2) = 0 --And (Flags & 8) = 0--And (Flags & 128) = 0 The Flags field is an int and allows NULLs. I'm not sure what other information is needed?I don't have any background knowledge of the structure of this db, nor any reference for Flags intended purpose. Am I on a wild goose chase without this info?I ran a query on just Flags so there is an idea of the data in there:SELECT TOP 30 Flags FROM [tableinquestion] GROUP BY Flags ORDER BY Flags Results:-----------NULL045678910121314157278128132133134135136138140141142143196198200202Any ideas/suggestions? |
|
Kwozzie
Starting Member
4 Posts |
Posted - 2012-04-16 : 00:50:30
|
NM. I understand what it's doing, still no idea what it's for, a question for the developer of the program if I were allowed to ask.[url]http://msdn.microsoft.com/en-US/library/ms174965%28v=sql.90%29.aspx[/url] and [url]http://en.wikipedia.org/wiki/Bitwise_operations_in_C[/url] should help those looking for similar answers.It also helped me understand what's happening by doing another query to show the outcomes...SELECT Flags, (Flags & 2) as Flags_2, (Flags & 8) as Flags_8, (Flags & 128) as Flags_128 FROM [tableinquestion] ORDER BY Flags ASC |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-16 : 12:15:30
|
i think Flags is field which indicates the status of multiple things based on bits that are set inside it. By doing an & 2,& 8 etc you're trying to check whether a particular bit is set or reset which will determine some condition as per your business logic------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|