Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Select question

Author  Topic 

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2009-02-06 : 10:03:28
I have a table

year period user
2006 2 Bob
2006 3 Sam
2006 3 Sue
2006 4 Candice
2007 2 Bob
2007 5 Mike


I want to be able to select all fields for the periods 3 and 5 in 2006
to give

2006 3 Sam
2006 3 Sue
2006 4 Candice

How can I do this please?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-06 : 10:06:29
do you mean this?
select year,period,user FROM table WHERE period >= 3 AND period<5 AND year=2006
Go to Top of Page

webappguru
Starting Member

10 Posts

Posted - 2009-02-06 : 10:51:06
How about this:

SELECT year, period, user from table where year = 2006 and
(period = 3 or period = 5)

But then Candice would not show up because she is period 4.

quote:
I want to be able to select all fields for the periods 3 and 5 in 2006
to give

2006 3 Sam
2006 3 Sue
2006 4 Candice



"I live for programming"
www.aliabidhusain.net
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-07 : 08:44:57
quote:
Originally posted by webappguru

How about this:

SELECT year, period, user from table where year = 2006 and
(period = 3 or period = 5)

But then Candice would not show up because she is period 4.

quote:
I want to be able to select all fields for the periods 3 and 5 in 2006
to give

2006 3 Sam
2006 3 Sue
2006 4 Candice



"I live for programming"
www.aliabidhusain.net


that will bring back
2007 5 Mike
also
Go to Top of Page

sg2255551
Constraint Violating Yak Guru

274 Posts

Posted - 2009-02-07 : 12:25:32
hi

you can also try this:

select year,period,user FROM table WHERE period between 3 AND 5 AND year = 2006
Go to Top of Page
   

- Advertisement -