Enum and Database question

N

Nicolas

What would be the Select Query for the following case.
I scratch my head but i'm only loosing my hair so far.

2 Records in tables
table Person

[Name] [FavSports]
Nicolas 12
Frank 2
John 10


Those entries and specialy the FavSports are based on an enum with
FlagsAttibute which allow multiple choice
<FlagsAttribute()> _
public enum Sports
None = 0
Soccer = 1
Tennis = 2
Hockey = 4
Swimming = 8
Football = 16
end enum

Now I want to retrive from the database all person who have Tennis (2) as
their favorite sport

SELECT * FROM Person WHERE FavSport = ?????? ORDER BY Name Asc;

I shoul get Frank and John

So what who be the routin to get the proper SELECT Statement

Thanks a lot for the help
 
A

Armin Zingler

Nicolas said:
What would be the Select Query for the following case.
I scratch my head but i'm only loosing my hair so far.

2 Records in tables
table Person

[Name] [FavSports]
Nicolas 12
Frank 2
John 10


Those entries and specialy the FavSports are based on an enum with
FlagsAttibute which allow multiple choice
<FlagsAttribute()> _
public enum Sports
None = 0
Soccer = 1
Tennis = 2
Hockey = 4
Swimming = 8
Football = 16
end enum

Now I want to retrive from the database all person who have Tennis
(2) as their favorite sport

SELECT * FROM Person WHERE FavSport = ?????? ORDER BY Name Asc;

I shoul get Frank and John

So what who be the routin to get the proper SELECT Statement

Thanks a lot for the help


"SELECT * FROM Person WHERE (FavSport & @mask) = @mask ORDER BY Name Asc;"

Set the value of Parameter "@mask" to Sports.Tennis. Or CInt(Sports.Tennis).


Armin
 
N

Nicolas

Thanks a lot
it's great


Armin Zingler said:
Nicolas said:
What would be the Select Query for the following case.
I scratch my head but i'm only loosing my hair so far.

2 Records in tables
table Person

[Name] [FavSports]
Nicolas 12
Frank 2
John 10


Those entries and specialy the FavSports are based on an enum with
FlagsAttibute which allow multiple choice
<FlagsAttribute()> _
public enum Sports
None = 0
Soccer = 1
Tennis = 2
Hockey = 4
Swimming = 8
Football = 16
end enum

Now I want to retrive from the database all person who have Tennis
(2) as their favorite sport

SELECT * FROM Person WHERE FavSport = ?????? ORDER BY Name Asc;

I shoul get Frank and John

So what who be the routin to get the proper SELECT Statement

Thanks a lot for the help


"SELECT * FROM Person WHERE (FavSport & @mask) = @mask ORDER BY Name Asc;"

Set the value of Parameter "@mask" to Sports.Tennis. Or CInt(Sports.Tennis).


Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top