Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

sort a sql text field by date

Posted on 2007-03-28
6
Medium Priority
?
498 Views
Last Modified: 2010-07-27
I have a field in an sql database that I want to sort in a list. It's a text value that stores the file name where the data was imported from by its week range
20070225-20070303.txt                            

How can I sort this field by date in the sql statement.

' here is my start

strSQL2 = "Select distinct RUNDATE from edstats"

Rs.Open strSQL2, Conn
if   not Rs.EOF then
do until rs.EOF
RUNDATE = Rs("RUNDATE")
rundate2=LEFT(rundate,8)
rundate2=FormatDateTime(rundate2,2)
'this is what I want to display by date order soonest to oldest
RESPONSE.WRITE("<A href='LOADEXCEL.ASP?value="&rundate&"'>Week of "&rundate2&"<BR>")

    Rs.MoveNext
loop
end if

Rs.Close
set Rs = Nothing

conn.close
set conn= nothing
%>
0
Comment
Question by:cseink
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 5

Accepted Solution

by:
jalalmegadeth earned 260 total points
ID: 18808633
hi
you can try
strSQL2 = "Select distinct RUNDATE from edstats order by RUNDATE"
or
strSQL2 = "Select distinct RUNDATE from edstats order by RUNDATE desc"


GL
0
 

Author Comment

by:cseink
ID: 18808679
OK. That is working for now but I only have 3 weeks in there. Will it get out of order if the field is not formatted somehow?
0
 
LVL 2

Expert Comment

by:MeDude21
ID: 18808767
No. The order will be fine. As long as RUNDATE is a datetime field it will store it in the correct format.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:cseink
ID: 18811001
The field is text field not a datetime. Is there any way through sql to convert  the field to a datetime in 20070311-20070317.txt  is how the field is stored in the DB  depending on the week.  Read the first 8 chars or something.??
0
 
LVL 16

Assisted Solution

by:ThinkPaper
ThinkPaper earned 260 total points
ID: 18811288
so your "date" field looks like: "20070311-20070317.txt "  ? If the filename somehow does get out of format, it will throw your order off. But let's hope you've provided all the checks & limitations so it won't be off.

You can also consider using the string functions provided in SQL to format it, but it would be basically the same method you'd be doing now. You'd still be grabbing the left side for the date. And again, if the name is messed up, the query would mess up:
http://msdn2.microsoft.com/en-us/library/aa258891(SQL.80).aspx

not sure if this is completely right, but you get the idea:
Select distinct RUNDATE, LEFT(RUNDATE,4) as runYear from edstats ORDER BY runYear
0
 

Author Comment

by:cseink
ID: 18811312
Great Thanks for the info
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Loops Section Overview

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question