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:
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:
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?
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.....
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?
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.
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.
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?
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.