Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends,

I am stuck with this small query.
It would be nice if any ofyou provide me with right solution.

I want to retrieve data for a date stored in table.
I have written following query.

select * from retinvoice where retinvoice.CREATEDDATE = convert (varchar,'08/28/2010',103)


But somehow it is not providing me with output.

If I give
select * from retinvoice
where   retinvoice.CREATEDDATE > convert(varchar,'08/27/2010',103) and
        retinvoice.CREATEDDATE < convert(varchar,'08/29/2010',103)


I am getting right answer.

Can anybody please help me?

Thanking you

Swapnil
Posted
Updated 7-Sep-10 11:59am
v2
Comments
Dalek Dave 7-Sep-10 17:59pm    
Edited for Readability, Code Block and Grammar.

Hi Swapnil 2009,

Small changes in your query

SQL
select * from retinvoice
where retinvoice.CREATEDDATE > '08/27/2010' and
retinvoice.CREATEDDATE < '08/29/2010'


My suggestion use between operator also you can achieve your output.

SQL
select * from retinvoice
where retinvoice.CREATEDDATE between '08/27/2010' and
 '08/29/2010'


Cheers :)
 
Share this answer
 
Comments
Dalek Dave 7-Sep-10 18:00pm    
Good Call.
Firstly why are you using convert(varchar.... Use YYYY-MM-DD format date instead.
Does your CREATEDDATE field contain time value also? Thats may be one of the reason not to geting any output. If so and you still want to convert the date then convert your CREATEDDATE field also same as you are converting the date value.
 
Share this answer
 
your query is not working because perhaps your field is of type DateTime. And when you are saving data you are saving with time.

So if your providing parameter like where retinvoice.CREATEDDATE = convert(varchar,'08/28/2010',103) then you won't get data because it stored with time for example like "08/28/2010 4:31:29 PM". So your condition will never match the given criteria.

So what I can suggest you is instead of passing convert function in select statement pass it in insert statement.

I hope this will help you.
 
Share this answer
 
Hello Friendz

Thank you very much for your reply. I finally sorted out the problem. It was that both the dates were not in the same format. so I converted my created date also in the same format and now its working fine.

Thank you all who gave me their valuable advice.

Cheers :)
 
Share this 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