Bitwise Help!

Nov 27, 2007

Hi,

This is a crosspost, I also asked this question in the learnvisualstudio.net forum. I'm trying to engineer a bit of code in SQL that "decodes" a value stored in a table that represents an array of boolean values, stored using bitwise operations. I have the number, a reference of bit positions for each item, and the actual items checked per the program that normally processes this value. I'm trying to write a sproc that will perform actions based on the booleans in my list, but I can't get the same results the interface gives me.
Here's an example:
Value is 66756
Bit positions 2, 6, 7, and 10 should all return true. I was trying to deduce this using the following:




Code BlockSELECT CONVERT (BIT, <value> & (2 ^ <position>))





but that doesn't work at all. It's my (broken) translation of the code normally used to display this value as a checkbox, which comes from VB6 and looks something like this:




Code Block.ListItems(CStr() & "_").Checked = CBool <value> And (2 ^ <position>))





Can anyone tell me what I'm doing wrong? Thanks in advance.

View 3 Replies


ADVERTISEMENT

Aggregate Bitwise OR

Dec 4, 2003

I was doing a SUM on my returned rows and i found that what i really want is an aggregate bitwise OR on all the returned rows. Do you know what's the function for that?

Thank you

View 4 Replies View Related

Bitwise NOT Operation

Sep 6, 2006

I was looking into some of the System stored procedures like sp_denylogin, sp_grantLogin etc. I found bit wise operations like

update master.dbo.sysxlogins set xstatus = (xstatus & ~1) | 2, xdate2 = getdate()
where name = @loginame and srvid IS NULL

How does the bitwise NOT(~) works with different datatypes like INT, SMALLINT and TINYINT?

Look at the following sample code and result. I just wanted to understand how it works with int and smallint


declare @a int
declare @b smallint
declare @c tinyint

select @a = 1, @b = 1, @c = 1

select @a=~@a, @b= ~@b, @c= ~@c

select @a, @b, @c

Result
~~~~~
-2-2254

Thanks in advance
Gnana

View 3 Replies View Related

Non-bitwise Exclusive Or?

Jan 30, 2004

Is there a way to do a logical exclusive OR (XOR) in sql server?

I'm trying to do this in where clause, something like:

WHERE
(not exists (select 1 from table a where a.date > '01/30/03') XOR
exists (select 1 from table a where a.date < '01/30/03'))

Thanks!

View 14 Replies View Related

Bitwise Question -

Jul 23, 2005

I am new to bitwise thing in MSSQL.Let's suppose there's a table of favorite foodsinsert int fav_foods(food_name,bitwiseVal)values('Pasta',1)insert int fav_foods(food_name,bitwiseVal)values('Chicken',2)insert int fav_foods(food_name,bitwiseVal)values('Beef',4)insert int fav_foods(food_name,bitwiseVal)values('Fish',8)insert int fav_foods(food_name,bitwiseVal)values('Pork',16)How do I write query to find people who selected more than one item andselected items from "Pasta, Chicken, Beef, Pork"(but not fish)?I hope my question is not confusing.....

View 6 Replies View Related

Decoding Days Bitwise AND

Nov 11, 2004

Hello All

I'm working on a recurring multi-day appointment program. Basically the user can choose a meeting on multiple days of the week over a span of time. For example: Tuesday and Thursday from 10:00 to 10:30 from December 1st 2004 to February 27th 2005.

So I've decided the best way to handle this is to assign a value to each day of the week like so:
MON = 1
TUE = 2
WED = 4
THU = 8
FRI = 16
SAT = 32
SUN = 64

So if the user picks TUE and THU that would be 2 + 8 = 10. The value is unique and seems to work.

So the values would be:
@begin_date = '12/01/2004'
@begin_time = '10:00 AM'
@end_date = '02/27/2005'
@end_time = '10:30 AM'
@recur_days = 10

Now I want to pass the values to stored procedure that will decode the recur_days variable and create entries in a table for each date. I'm struggling to figure out 2 things

1. How do I decode the 10 back into 2(TUE) + 8(THU) ( I think it has something to do with the bitwise AND "&" operator but I'm not sure how to use it.)

2. What is the best way to loop through the date range and create a record for each day?

Regards
Russ

View 2 Replies View Related

Aggregate Bitwise OR On A Column

Oct 22, 2014

I am trying to get a culmulative Bitwise OR operation on a column by query - rather than using a CLR function.

The problem is shown below:

CREATE TABLE #Operations (
PK INT NOT NULL IDENTITY(1,1),
UserName VARCHAR(50) NOT NULL,
UserProcess VARCHAR(50) NOT NULL,
ServerOperation VARCHAR(50) NOT NULL,
Permission INT NOT NULL );

[Code] ....

So Far I've tried SUM - wrong results, and STUFF - which doesn't seem appropriate for bitwise operation - neither give useful results.

-- SUM Operation - fails
SELECT DISTINCT
UserName,
ServerOperation,
SUM(Permission) AS Permission
FROM #Operations

[Code] ....

It may be possible to materialise the permissions each time one is changed (e.g. by to use a cursor ), however I would prefer a query or function or combination to generate the result.

View 5 Replies View Related

Bitwise &&amp; Operator Does Not Work

Jan 15, 2007

I would like to do something like a SELECT * FROM Files WHERE (Attributes & ?) but the & operator isn't recognized. I looked at the documentation sample for it and in the sample the & operator isn't used in the WHERE clause so I thought that might be the reason but I still can't get the operator to work. So even the doc sample code for it doesn't work.

View 3 Replies View Related

Query Trouble Regarding Bitwise Exclusive

Feb 25, 2001

HI, i am trying to make query that has computations with it. but when there's a point computing between int and float i had to use cast() function to convert certain data types. somehow it only works on converting float to integer because when i'm converting an integer into float inorder to be computed with a float it bombs. my query is like this ....


SELECT cast(((cast(((lat - (SELECT LAT FROM TPS_ZIPUSA WHERE ZIP_CODE = 00210)) * 69.1) AS int) ^ 2) + (cast((69.1 * (lng - (SELECT Lng FROM TPS_ZIPUSA WHERE ZIP_CODE = 00210)) * (COS((SELECT LAT FROM TPS_ZIPUSA WHERE ZIP_CODE = 00210) / 57.3))) AS int) ^ 2)) AS float) ^ .5
FROM TPS_ZIPUSA


.5 is where the query bombs. any idea why is this happenning?

by the way, i'm using sql server 7.0.

francis,

View 2 Replies View Related

SQL 2012 :: Custom Bitwise OR Aggregate Function

Mar 18, 2014

I want to create a custom bitwise OR aggregate function.

I want to use it like the built in aggregate functions (MIN, MAX etc.)

SELECT dbo.bitwise_or(bit_string) FROM table

where bit_string is a nvarchar(3)

so for example if the table contains two rows ('100', '001') the above query should return '101'

I would like to implement this as a CLR function/assembly with the aggregate below:

CREATE AGGREGATE dbo.bitwise_or (bit_string nvarchar(3))
RETURNS [nvarchar(3)]
EXTERNAL NAME [Aggregate].[bitwise_or]

I have followed this post to implement amedian aggregate function [URL] ..... but there is a lot of code (not sure what is really needed in my case).

View 9 Replies View Related

Escaping Bitwise In Full Text Search 2005

Feb 6, 2007

Hi,

We are facing a problem while passing a string containing the "&" character into Full Text search CONTAINS predicate. The records that do have this character are not being returned by the search.

I'd like to raise two questions:

1) Is there any special way to escape this character?
2) Does FTS index it at all?

We have tried all known (to us) ways of escaping like doubling the character, using char(38), using ESCAPE etc..Nothing seem to work. Any help would be appreciated.

Thanks,
Alex

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved