DB2 Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDB2 Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old October 3rd, 2006, 09:28 AM
Aberon44 Aberon44 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 2 Aberon44 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 27 sec
Reputation Power: 0
SQL Statement (from MS to DB2)

Can anyone help with the following. I have a Microsoft SQL Statement that I need to get working in DB2. I explain the concept in detail below the SQL Statement


SELECT Part_Number
FROM fpv_Product
WHERE ( @BitPack & Location ) > 0

@BitPack is a parameter sent in to the select statement.


---------------------------------------------------
See explanation below:


Suppose we have same tables :
1 Users : for storing user account information.
2. Locations : for storing locations.

Here we will store the locations in the Locations table, but with bit-packID which can be calculated as :

Bit-packID Locations
2^0 = 1 AA
2^1 = 2 BB
2^2 = 4 CC
2^3 = 8 DD

In the Users table, we will have one extra field for each user as ‘Bit-Pack-Total’ . This field will have value equal to addition of all bit-packIDs, if user is having access to multiple locations.
Example :
For Admin, value for this field will be 1+2+4+8 = 15
For User with location DD, it will be 8.

To retrieve the locations for the user , we can just use bitwise And operator between Bitpack-Total for user and each Bit-packID for location. If the value is greater than 0, we can say that user is having that location.

For ex. Admin : 15 AND 1 = 1
15 AND 2 = 2
15 AND 4 = 4
15 AND 8 = 8
This shows that admin belongs to all the locations.

For user with location DD it will be as :
8 AND 1 = 0
8 AND 2 = 0
8 AND 4 = 0
8 AND 8 = 8

This way we can maintain relationship between users and locations.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDB2 Development > SQL Statement (from MS to DB2)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway