Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old December 21st, 2004, 09:16 AM
aliasbdi aliasbdi is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 17 aliasbdi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m
Reputation Power: 0
Exclamation Simple Query Question

I have a table with these three columns:

archiveYear (char,4)
archiveMonth (char,2)
archiveDay (char,2)

They contain elements for the date. ArchiveMonth and ArchiveDay use doubleDigit characters like "01, 02, 03, etc." So when written out they can read "12/03/2004" which is the datetime format. For sorting purposes, I need to combine the three tables into one (archiveMonth/archiveDay/archiveYear). Then I can sort it and call what I need easier. I assume that this can be done with the CAST function. Anybody know?

Reply With Quote
  #2  
Old December 21st, 2004, 11:04 AM
Lauramc's Avatar
Lauramc Lauramc is offline
SQL Slarentice
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2004
Location: In My Happy Place
Posts: 1,783 Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 15 h 48 m 56 sec
Reputation Power: 1095
Well I could be wrong, but I think you need a cursor to do this (if you are going through each record in the table). For the cursor you will need variables to represent the day, month and year. Then for each record, combine the values of each varaible and the "/", casting the result as datetime.

Reply With Quote
  #3  
Old December 21st, 2004, 04:38 PM
A2k's Avatar
A2k A2k is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 166 A2k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 44 m 10 sec
Reputation Power: 4
I'm sure you can do it quite easily by just doing something like this:

ORDER BY archiveDay + '/' + archiveMonth + '/' + archiveYear

if not try looking at the convert function.

Reply With Quote
  #4  
Old December 28th, 2004, 04:20 PM
aliasbdi aliasbdi is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 17 aliasbdi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m
Reputation Power: 0
yeah

Actually, CONVERT would be the idea, I think. But I'm not sure how to do the query with CONVERT. The plan would be to do this:

SELECT *, CONVERT(archiveDay + '/' + archiveMonth + '/' + archiveYear) AS recordDate
WHERE recordDate >= now
ORDER BY recordDate ASC

Something like that...but I'm not formatting the CONVERT correctly. Any suggestions?

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Simple Query Question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway