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.
| Author |
Topic |
|
MechMon
Starting Member
2 Posts |
Posted - 2011-06-10 : 08:51:32
|
| Hello All,I have a table with data like this:Salesman Location SalesDateWhat I would like to query is:Select * from Salesman Where [SalesDate] Between '01/01/01' AND '01/30/01' OR [SalesDate] Between '06/01/11' AND '06/09/11' I retrieve the first set of data fine ie,Bob 01/01/01Bob 01/02/01Bob 01/15/01 Which is correct and complete.However, the query then pulls in all Saleman from the "OR" date ie,Bob 06/01/11Steve 06/03/11Sven 06/09/11Bob 06/05/11Sue 06/02/11Bob 06/23/11B'jorn 06/04/11The resulting table looks like this:Bob 01/01/01Bob 01/02/01Bob 01/15/01Bob 06/01/11Steve 06/03/11Sven 06/09/11Bob 06/05/11Sue 06/02/11Bob 06/23/11B'jorn 06/04/11It seems I need to match the "Where" with a "Between".However this fails:Select * from Salesman Where [SalesDate] Between '01/01/01' AND '01/30/01' OR Where [SalesDate] Between '06/01/11' AND '06/09/11'If I run two different queries, the resulting table is over written.Do I need to append the second set of data to the first? If so where do I specify it.Regards,MechMon |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-06-10 : 09:06:48
|
| WHat do you actually want?The first result with 10 rows looks like what you are asking for.>> Which is correct and complete.If that's thecase just remove the "or" part==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-06-12 : 04:22:04
|
| whats the datatype of SalesDate?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
MechMon
Starting Member
2 Posts |
Posted - 2011-06-15 : 07:40:33
|
| [Solved]I found the issue. Parenthesis are needed around each [SalesDate] and the entire expression as well, i.e.(([SalesDate] Between '01/01/01' AND '01/30/01') OR ([SalesDate] Between '06/01/11' AND '06/09/11'))Thank you. |
 |
|
|
|
|
|