Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 14th, 2006, 06:25 AM
Registered User
 
Join Date: Oct 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Select where hex

How does the following statement work?

select *
from data
where (Flags & 0x400 = 0x400) AND (Vtype & 0xff00 = 0x100)

This statement is taken from SQL profiler while working on an accounting package. I'am unable to understand what this does.
sp_cursofetch and some declare execute before this statement.
 
Old October 14th, 2006, 06:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

I'm not sure I understand what you don't understand about the statement. :)

The expressions in parenthesis in the WHERE are the logical AND of the results of each expression. These are logical equality tests of bit-wise AND expressions. For example:
Code:
Flags & 0x400 = 0x400
is the bitwise AND of the 'Flags' column with the hex value 400. This is compared to hex 400. If these expressions are equal, bit 10 of the 'Flags' column is set. If not, it isn't.

So, the statement is selecting rows from the 'data' table where the 'Flags' column has bit 10 set and the 'Vtype' column has bit 8 set.

BTW. those columns are definitely NOT first normal form...

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old October 14th, 2006, 02:15 PM
Registered User
 
Join Date: Oct 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Jeff,

The table structure shows ...

Colname Data Type Length
vtype smallint 2
flags int 4

value for one of the record shows ...
  vtype = 256
  flags = 2098176

Pls. clarify further as I have never worked useing hex or bits before.


 
Old October 15th, 2006, 05:50 AM
Registered User
 
Join Date: Oct 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Further for your understanding

SELECT distinct VType, Flags
FROM data
WHERE (Flags & 0x400 = 0x400) AND (VType & 0xff00 = 0x100)

OR

SELECT distinct VType, Flags
FROM data
WHERE (VType & 0xff00 = 0x100)

shows the following ....
VType Flags
256 2098176
256 1024

Whereas ....

SELECT distinct VType, Flags
FROM data
WHERE (Flags & 0x400 = 0x400)

Shows the following ....

VType Flags
3328 2098688
3328 1536
4864 2098176
1792 2098688
4864 1024
768 2098688
1792 1536
3584 3150848
768 1536
3584 1053696
3328 2164224
3328 67072
1792 2164224
256 2098176
4608 2098176
3584 3146752
1792 67072
3584 2098176
4608 1024
256 1024
3584 1049600
3584 1024

 
Old October 15th, 2006, 07:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

With all due respect, we're talking about some pretty basic stuff here.

Your display of representative values of the 'VType' and 'Flags' columns is in decimal. Convert the values to hex and it'll be easier to understand why an expression like (Flags & 0x400 = 0x400) is TRUE for a Flags value of 1024 (dec).

It's almost impossible for me to avoid appearing condescending when talking at that level, and discussing such things as binary and hexadecimal representations of numbers, bit-wise operations on those numbers, etc. will make me appear just that.

Please don't take this the wrong way, but you need to get a good basic introductory book on computers and how they work...

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old October 16th, 2006, 11:39 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

It seems to be a trend... I recently tried to hire folks to fill the position of SQL developer. 5 people, 4 with Masters Degrees and 1 PHD in Computer Science responded... all claimed to be experts in SQL and computers in general. None of the 4 could tell me what 2 to the 3rd was and none of them knew what 2 to the 0 was nor could they tell me the decimal equivelent of 14 base 16. Apparently, no one thinks they need to know the basic numbering systems of computers, anymore.

--Jeff Moden





Similar Threads
Thread Thread Starter Forum Replies Last Post
convert byte[] to hex value gunjan.sh C# 2005 4 January 24th, 2008 05:15 AM
convert byte[] to hex wkm1925 C# 1 December 14th, 2006 09:07 PM
hex num changed.. life_s Ng ASP.NET 2.0 Professional 1 October 30th, 2006 12:41 PM
hex conversion to binary files chrispbrown2255 C++ Programming 1 March 15th, 2006 06:06 PM
convert otb files to hex string ela Classic ASP Professional 1 October 14th, 2004 01:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.