Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I guys i have a table expenses with multiple records.
SQL
expenseID       ratename         description          workcompleted

51699   	Base Rate	SNL Financial inquiry	08/09/2011
51699   	Base Rate	SNL Financial inquiry	08/19/2011
51699	        Base Rate	SNL Financial inquiry	08/09/2012
51699   	Base Rate	SNL Financial inquiry	08/19/2012

But when i search record only for year 2012 but it return record for both the year(2011, 2012). But i need my record comes by year only i.e.


51699	Base Rate	SNL Financial inquiry	08/09/2012
51699	Base Rate	SNL Financial inquiry	08/19/2012

Please see my query :


select expenseid,ratename,description,workcompleted from EXPENSES 
where workcompleted >= '08/08/2012' and workcompleted <= '08/19/2012'

I also try this by using between query but it doesn't work. If any body have an idea kindly share to me.
Posted

when ever compare dates ,
in where condition pass value in 'yyyy-MM-dd' format

SQL
select expenseid,ratename,description,workcompleted from EXPENSES
where workcompleted >= '2012/08/08' and workcompleted <= '2012/08/19'


Happy Coding!
:)
 
Share this answer
 
Comments
Mas11 6-Dec-12 0:45am    
I hope in this way i have to do big changes in my database. There is 20000 record & date comes mm/dd/yyyy format (as per my need it has to be same format). But according to your query i have to convert this in yyyy/mm/dd. There is any other solution rather then converting this.
Aarti Meswania 6-Dec-12 0:56am    
hey no man

do not do that

'workcompleted' column is having datatype datetime then
just fire this query in database not required little change

ok dear
:)
Mas11 6-Dec-12 0:59am    
Thanks Aarti, but now i got the solution actually my datatype is nvarchar, so it create a problem. Now i change this into datetime & problem solve. Thanks for your support.
Aarti Meswania 6-Dec-12 1:00am    
welcome :)
Try this I hope it will help you
SQL
select expenseid,ratename,description,workcompleted from EXPENSES 
where year(workcompleted)='2012'


keep smiling:):):) happy coding:)
 
Share this answer
 
v2
Comments
Mas11 6-Dec-12 1:00am    
Thanks for the answer.

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