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 |
rugvedmandrekar
Starting Member
2 Posts |
Posted - 2012-12-02 : 06:15:10
|
Hello everyone,This is not my first experience with SQL but I have completely lost touch with SQL statements from the past 3 years. I needed to brush up my knowledge on SQL once again in order to get my basics right. Hence, this question may look silly. This question is regarding the 'Between' range tests. Can I combine two simple range test queries into a single query? For example, I have a table, EmployeePayHistory(EmployeeId, RateChangeDate, Rate, Frequency). I want to get all the rows from from this table whose 'RateChangeDate' comes between two different ranges - 01/01/1996 & 31/12/1997 and 01/01/2000 & 31/12/2003 (Date format: dd/mm/yyyy) taking the help of the 'Between' range test.If I were to achieve the above results I could fire the following two queries simultaneously1) select *from employeepayhistorywhere ratechangedate between '01-jan-1996' and '31-dec-1997'2) select *from employeepayhistorywhere (ratechangedate between '01-jan-2000' and '31-dec-2003')However, could I combine the above two queries into a single query of something like this:-select *from employeepayhistorywhere ratechangeddate between (select * from employeepayhistory where ratechangeddate between '01-jan-1996' and '31-dec-1997') and (select * from employeepayhistory where ratechangeddate between '01-jan-2000' and '31-dec-2003') /*** Incorrect syntax***/? ? ? ? ?Replies to this question will be highly appreciated. Thanking in advance. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
rugvedmandrekar
Starting Member
2 Posts |
Posted - 2012-12-04 : 05:24:44
|
Thank you very much for your kind advice visakh16. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-12-06 : 01:34:39
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|