Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table named as Displacement, in which there is a column containg date of displacement. I want the count of dates for the columns mentionted below. What should be the query for such condition.

Before 2007, Between 2007-2008, Between 2008-2009,

I have tried the following query but its not working.
SQL
Select
SUM(CASE isnull(Year(IO7_DateOfDisplacement), 0) WHEN (IO7_DateOfDisplacement is < 2007) THEN 1 ELSE 0 END) AS [Before 2007],
SUM(CASE isnull(Year(IO7_DateOfDisplacement), 0) WHEN  (Between 2007 and 2008) THEN 1 ELSE 0 END) AS [Between 2007-2008]


I shall be thankful for you help.
Usama Javed
Posted
Updated 2-Aug-13 22:14pm
v2

1 solution

C#
select SUM(xyz) from table_name where YEAR(your date field)=//or whatever is your condition

Regards..:laugh:
 
Share this answer
 
Comments
osama.javed 3-Aug-13 5:58am    
but it will return only one column with respect to where condition, for example where Year(Date)<2007. It will only return the number of years less than 2007. What about year between 2007-2008.
Thanks7872 5-Aug-13 0:09am    
I have commented in code something like //or whatever is your condition,there you just have to change the condition.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900