Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8556

Re: Logical operations on binary columns

$
0
0

> I think you mixed up bit and binary datatype.

> Binary datatype is normally used for images, text, storing a pdf in your db, etc

 

I'm aware that's what they're usually used for (although I have thought varbinary would have been better)

but I need to store lots of bit fields and  was hoping I could use a binary datatype, rather than have status1, status2, status3, etc

 

> If you want 1 column to store multiple values using bitmasks, than you can use an integer to do that.

> e.g. see examples in system tables like sysdatabases..status (small int) and sysdatabases..status4 (int)

 

That's what we're using at the moment - if fact we're now using unisgned bigint - that gives 64 bits.

The fact that sys* tables have multiple status fields shows it would be useful here.

 

> Sybooks: The bitwise operators are a Transact-SQL extension for use with integer type data.

> So it looks like you've got to use multiple columns to achieve wat you want.

 

Yep - that's exactly what we've found.

It seems unfortunate to not allow bitwise operations on binary datatypes. Its not a common use of them I know

but I've worked at couple of places which would have benefited from this.

 

We've spent some time writing our own functions that implement bitwise operations on binary fields, but would have been better if these were build in.

 

> Why would you want to store 200 bitfields in 1 column?


For a similar reason as the sys* tables have multiple status columns - If binary columns allowed bitwise operations - they'd only need 1 status field.


Viewing all articles
Browse latest Browse all 8556

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>