Home > SQL Development > Date problem

Date problem



Hi,



I have a field called reg_date which is varchar



it stores dates in it the format it stores is like this 01/12/2007





str ="SELECT * FROM Products order by reg_date asc



when it displays the products they are displayed like this



1/01/2008

1/16/2008

1/27/2008

2/12/2008

09/19/2007

07/25/2007



if you see the 4 record which is in the month of feb should be at top

but its not i even tried ordering it by reg_date desc it didnt work



any idea



todd

    
Guest


because it's a varchar field and not a date field, your sort will not work properly. try something like this:


Code:


str ="SELECT * FROM Products order by convert(smalldatetime,reg_date) asc




we've discussed with you about storing date values as varchar.

Was this answer helpful ? Yes No   
Guest


mehere,



that fixes it



todd

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved