Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello,

i am using C# with asp.net.
i am unable to fetch data from database using particulate month.
this is for current year:
DateTime sys = System.DateTime.Now;

year = sys.Year;

this is for next year :
DateTime next =sys.AddYears(1);

Next = next.Year;


this is part of my query:
string query = "select DISTINCT(App_Code),App_Name from Appraisal where year(App_Date)>='" + year + "' and YEAR(App_Date)<='" + Next + "'";


now this query shows the data of month of jan,feb,march.. which i dont want to show.
because this is a last financial year.
So please help me for that. what can i do?
Posted
Comments
CHill60 5-May-15 9:32am    
Your query is not showing the month! Next (with a capital) is an integer, as is year
Tomas Takac 5-May-15 9:35am    
What do you mean? You need to provide correct date range. If you want to select data from 1 Apr 2014 to 31 Mar 2015 then this is exactly what you need to pass into your query.
Member 11221185 6-May-15 0:57am    
but how to pass that range.

1 solution

TRY THIS

string query = "select DISTINCT(App_Code),App_Name from Appraisal where datepart(yy,App_Date)>='" + year + "' and datepart(yy,App_Date)<='" + Next + "'";
 
Share this answer
 
Comments
Member 11221185 6-May-15 0:56am    
This query is showing the same result as before.
i want to classified using month. such as from date will start from 1-Apr-2015 to 31 - march -2016

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