|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Databases > DB2 Development > SQL Statement (from MS to DB2) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|