Home All Groups Group Topic Archive Search About

Enum and Database question

Author
10 Mar 2006 1:09 AM
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

Author
10 Mar 2006 1:49 AM
Armin Zingler
Show quote Hide quote
"Nicolas" <nlie***@hotmail.com> schrieb
> 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
Author
10 Mar 2006 4:07 AM
Nicolas
Thanks a lot
it's great


Show quoteHide quote
"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:e6bvmp%23QGHA.2276@tk2msftngp13.phx.gbl...
> "Nicolas" <nlie***@hotmail.com> schrieb
> > 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).
Show quoteHide quote
>
>
> Armin
>