SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL 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 ASP Free Forums Sponsor:
  #1  
Old July 29th, 2003, 04:16 PM
Tha_Big_Guy22 Tha_Big_Guy22 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 2 Tha_Big_Guy22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
using & in SQL Statement

Hello,

I've got a slight problem with the way I want to get data out of my database using ASP. Let me explain a little about what i'm trying to do.

I've got a field in a table that uses powers of 2 to determine what the field represents, ie. 2 = one thing, 4= something else, 8 = yet another thing. Anyway, I use and statements in my ASP to determine what the power of number in the database represents. To give you an example:

Within the database The following numbers represent single values:

1 = Pencil
2 = Pen
4 = Chalk

Now, by using the and statement I can assign a value in the database that can represent more than one of these items at a time. Now, the following numbers represent values that can be in the table, and what they actually are:

1 Pencil
2 Pen
3 Pencil Pen
4 Chalk
5 Pencil Chalk
6 Pen Chalk
7 Pencil Pen Chalk


To get that list I just used this code. It explains a bit about what i'm trying to accomplish.

Dim VarCount

While (VarCount < 8)

Response.Write(VarCount & " ")

If((VarCount and 1) > 0) then Response.Write("Pencil ") End If
If((VarCount and 2) > 0) then Response.Write("Pen ") End If
If((VarCount and 4) > 0) then Response.Write("Chalk ") End If

Response.Write("<br>")

VarCount = VarCount + 1
Wend

Now, the problem that i'm having is getting the information out of the database where I want it, instead of having to pull all the tables and then sort out the mess. I've tried select statements like this:

Select * From tblItems WHERE ItemType & 4

Which should give me all the items in the database that relate to Chalk.. Instead it's giving me all the items in the database.

I've also tried:

Select * From tblItems WHERE ItemType and 4

Same problem as before.

So is there any way that I can use the and statement from my select statement to get it to work properly?

Reply With Quote
  #2  
Old July 29th, 2003, 05:07 PM
dcarva's Avatar
dcarva dcarva is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 633 dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 18 m 20 sec
Reputation Power: 7
If you want to get any item that is equal to 4, and 4 is an integer, do it like this:

Select * From tblItems WHERE ItemType = 4

Is this what you are looking for?
Danny

Reply With Quote
  #3  
Old July 29th, 2003, 05:09 PM
dcarva's Avatar
dcarva dcarva is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 633 dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 18 m 20 sec
Reputation Power: 7
Also, with this statement you have:

If((VarCount and 4) > 0) then Response.Write("Chalk ")

I think what you mean to do is this:

If (VarCount = 4) then Response.Write("Chalk ")

Hope this helps.

Reply With Quote
  #4  
Old July 29th, 2003, 05:24 PM
Tha_Big_Guy22 Tha_Big_Guy22 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 2 Tha_Big_Guy22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
That doesn't exactly work... I'm using the "and" as a bitwise statement. if i set the select to:

WHERE ItemType = 4

Then all i would get would be "Chalk"

But i want all instances of Chalk, which would also include 5 and 7...

When you use "and" as a bitwise statment it will only return a positive integer or Zero if it is true, which is why the "> 0" has to be there.

Hope that helps clarify the situation a bit more.

Last edited by Tha_Big_Guy22 : July 29th, 2003 at 06:03 PM.

Reply With Quote
  #5  
Old July 29th, 2003, 06:58 PM
dcarva's Avatar
dcarva dcarva is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 633 dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 18 m 20 sec
Reputation Power: 7
Oh I see what you are doing. I know SQL Server supports BITWISE operations. Go to:

http://msdn.microsoft.com/library/d..._oa-oz_3qpf.asp

I Hope this helps,
Danny

Reply With Quote
  #6  
Old July 30th, 2003, 03:32 PM
consulbanana consulbanana is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Portland, OR
Posts: 2 consulbanana User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Bitwise logic

This one works in T-SQL:

Select *
From tblItems
WHERE (ItemType & 4)=4


both of your sample queries just give me errors.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > using & in SQL Statement


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



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT