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)
 Need help for query

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 enddate
1 2008-04-01 2008-10-01
2 2008-01-01 2009-12-01
3 2008-02-01 2008-09-01
4 2008-07-22 2008-10-05
5 2009-01-08 2009-05-20

what 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
1
2
3


Thanks,
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)
Go to Top of Page

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)


Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-05-05 : 12:33:30
[code]Select projcode from table
Where 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 Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -