Click here to Skip to main content
14,332,555 members
Rate this:
Please Sign up or sign in to vote.
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.
Rate this:
Please Sign up or sign in to vote.

Solution 2

Hi Swapnil 2009,

Small changes in your query

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.

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


Cheers :)
   
Comments
Dalek Dave 7-Sep-10 18:00pm
   
Good Call.
Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

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 :)
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100