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 |
|
sql_2k
Starting Member
26 Posts |
Posted - 2008-05-05 : 11:50:52
|
| Need help for the below requirement.I have below table projcode startdate enddate1 2008-04-01 2008-10-012 2008-01-01 2009-12-013 2008-02-01 2008-09-014 2008-07-22 2008-10-055 2009-01-08 2009-05-20what I want based on the input parameter quarter(Q1/Q2/Q3/Q4) and year fetch all project code where the selected quarter will fall in between the startdate and enddate.Ex- if Quarter = Q2 and year = 2008 then the o/p should be projcode 123Thanks,Srain. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-05 : 12:16:54
|
try this;-SELECT * FROM Table WHERE @quarter between DATEPART(qq,startdate) AND DATEPART(qq,enddate) |
 |
|
|
sql_2k
Starting Member
26 Posts |
Posted - 2008-05-05 : 12:31:26
|
Many Thanks. quote: Originally posted by visakh16 try this;-SELECT * FROM Table WHERE @quarter between DATEPART(qq,startdate) AND DATEPART(qq,enddate)
|
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-05-05 : 12:33:30
|
| [code]Select projcode from tableWhere cast(right(@quarter,1) as tinyint) between datepart(quarter, startdate) and datepart(quarter, enddate) and @year between datepart(year, startdate) and datepart(year, enddate)[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
|
|
|