Ask a Question related to ASP Database, Design and Development.
-
Aaron Bertrand - MVP #1
Re: Convert Month Names To Sortable Values?
You should keep another column which stores the date as a date (as it should
be). Or have *just* the date column.
In case (1), you can have
SELECT
formattedDate
FROM table
ORDER BY realDate
In case (2), you can have something like this (not sure of the exact syntax
in Access, which I assume you're using).
SELECT DATENAME('m', realDate) + RIGHT(YEAR(realDate, 2))
FROM table
ORDER BY realDate
Please, ALWAYS indicate what database you're using.
As a final try, you could reverse engineer the abbreviation and make a
computed column in the query only, and order by that.
--
Aaron Bertrand
SQL Server MVP
[url]http://www.aspfaq.com/[/url]
"MDW" <anonymous@discussions.microsoft.com> wrote in message
news:B3BB87DA-0ED7-446F-B739-4DD488991770@microsoft.com...field that is very important for my users. Its data come from an outside> Hey all,
>
> I've got a database I'm going to be linking to via ASP. It's got a "date"
source and I don't have a lot of control over it. Essentially, this field
contains the appreviated month name, concatenated with the last two digits
of the year, making it effectively a text field. For instance, "DEC03" or
"MAR04".If I sorted it as text, then "FEB04" would come before "JAN04", etc.>
> What I want to do is sort on this column, but sort it by the actual date.some value, such as #01/01/2004# for "JAN04"....but I'm unsure how to>
> I can create a function that would receive this field as input, and return
incorporate that into a SQL statement.
Aaron Bertrand - MVP Guest
-
xml sortable columns
Hello everyone, Can I somehow import an XML file into a table and then be able to sort the information alphabetically by each column? Is this... -
Find specific column names AND their values.
Okay, so I'm working on this project that tracks communities and how they're doing. The communities are judged based on their indicators. There... -
Retrieve Form Names and values
Is there a way to loop through a list of fields that have been submitted to a page?? I know how to do it in asp, but im new to CF. Also do you... -
to convert a month to previous month
How to convert a month to previous month in a very easy way? For example, I have AUGUST, but I want JULY to return. Thanks. *** Sent via... -
How to convert timestamp values to numeric (SQL70)
Pedro, How big is your numeric value? It sounds like an outside of range problem. Timestamp is 8 bytes, which means a pretty big number as a... -
Bob Barrows [MVP] #2
Re: Convert Month Names To Sortable Values?
MDW wrote:
What database? And version?> Hey all,
>
> I've got a database
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Bob Barrows [MVP] Guest
-
Bob Barrows [MVP] #3
Re: Convert Month Names To Sortable Values?
You DO realize that your database will have a Y2100 bug ...
Or are you planning on this to guarantee some work for your children ... ?
;-)
Yes, something like what you propose will work, however, coming up with a
single solution that will work in both Access and SQL Server will be
difficult (convert is the name of a builtin T-SQL function, so you would not
want to use that as the name of your custom function ... you'd want to use a
less "generic" name anyways, wouldn't you?).
MDW wrote:--> Sorry, I forgot to mention the databases I'm using.
>
> Yes, plural. I've got an Access version of it that I'm using to
> develop the thing, but when it goes live it will be on SQL Server.
> Lovely, isn't it?
>
> Using your third option, would something like this work?
>
> "SELECT ACCT,[FORMATTED DATE] FROM Table ORDER BY convert([FORMATTED
> DATE])"
>
> Where [FORMATTED DATE] is the field that contains "MAR04" and convert
> is a function that can change that to 03/01/2004? (I would simply
> change all the dates to the first of the month, as that will
> accomplish the sort order I need. There isn't a specific date
> attached to these records.)
>
> ----- Aaron Bertrand - MVP wrote: -----
>
> You should keep another column which stores the date as a date
> (as it should be). Or have *just* the date column.
>
> In case (1), you can have
>
> SELECT
> formattedDate
> FROM table
> ORDER BY realDate
>
> In case (2), you can have something like this (not sure of the
> exact syntax in Access, which I assume you're using).
>
> SELECT DATENAME('m', realDate) + RIGHT(YEAR(realDate, 2))
> FROM table
> ORDER BY realDate
>
> Please, ALWAYS indicate what database you're using.
>
> As a final try, you could reverse engineer the abbreviation and
> make a computed column in the query only, and order by that.
>
> --
> Aaron Bertrand
> SQL Server MVP
> [url]http://www.aspfaq.com/[/url]
>
>
>
>
> "MDW" <anonymous@discussions.microsoft.com> wrote in message
> news:B3BB87DA-0ED7-446F-B739-4DD488991770@microsoft.com...> got a "date" field that is very important for my users. Its data> > Hey all,> >> I've got a database I'm going to be linking to via ASP. It's
> come from an outside source and I don't have a lot of control
> over it. Essentially, this field contains the appreviated month
> name, concatenated with the last two digits of the year, making
> it effectively a text field. For instance, "DEC03" or "MAR04".> actual date. If I sorted it as text, then "FEB04" would come> >> What I want to do is sort on this column, but sort it by the
> before "JAN04", etc. >> I can create a function that would
> receive this field as input, and return some value, such as
> #01/01/2004# for "JAN04"....but I'm unsure how to incorporate
> that into a SQL statement.
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Bob Barrows [MVP] Guest
-
Aaron Bertrand - MVP #4
Re: Convert Month Names To Sortable Values?
> Yes, plural. I've got an Access version of it that I'm using to develop
the thing, but when it goes live it will be on SQL Server. Lovely, isn't it?
Well, have you considered developing in MSDE (free) or SQL Server Developer
Edition ($49)?
Then you can develop in a single codebase and not have to worry about any
side effects of code conversion, syntax changes, upsizing, data type
changes, differing keyword violations, etc.
DATE])"> "SELECT ACCT,[FORMATTED DATE] FROM Table ORDER BY convert([FORMATTED
Yes, but I still think you should consider adding a column that, upon
initial population of the table, has the date in the proper format. In SQL
Server you can use a computed column for this, or handle all inserts with a
stored procedure that does the work. In fact, I think this is the only
column you will need, because you can always generate the presentation
format after the fact. If it looks and smells like date, and you want it to
act like a date, you should store it as a date, not as a char(5).
--
Aaron Bertrand
SQL Server MVP
[url]http://www.aspfaq.com/[/url]
Aaron Bertrand - MVP Guest
-
MDW #5
Re: Convert Month Names To Sortable Values?
I'll let them worry about it in 96 years!
Besides, the data we're looking at is going to be current month, going back maybe 6 months at best.
I'f it'll make you feel better, I'll use Year(Date) somehow and ensure that if we're in year 2100+, it records the dates properly
And no, the function will probably be called convertAbbDate or something
----- Bob Barrows [MVP] wrote: ----
You DO realize that your database will have a Y2100 bug ..
Or are you planning on this to guarantee some work for your children ...
;-
Yes, something like what you propose will work, however, coming up with
single solution that will work in both Access and SQL Server will b
difficult (convert is the name of a builtin T-SQL function, so you would no
want to use that as the name of your custom function ... you'd want to use
less "generic" name anyways, wouldn't you?)
MDW wrote--> Sorry, I forgot to mention the databases I'm using> develop the thing, but when it goes live it will be on SQL Server>> Yes, plural. I've got an Access version of it that I'm using t
> Lovely, isn't it> DATE])>> Using your third option, would something like this work
>> "SELECT ACCT,[FORMATTED DATE] FROM Table ORDER BY convert([FORMATTE> is a function that can change that to 03/01/2004? (I would simpl>> Where [FORMATTED DATE] is the field that contains "MAR04" and conver
> change all the dates to the first of the month, as that wil
> accomplish the sort order I need. There isn't a specific dat
> attached to these records.> (as it should be). Or have *just* the date column>> ----- Aaron Bertrand - MVP wrote: ----
>> You should keep another column which stores the date as a dat> formattedDat>> In case (1), you can hav
>> SELEC
> FROM tabl
> ORDER BY realDat> exact syntax in Access, which I assume you're using)>> In case (2), you can have something like this (not sure of th> FROM tabl>> SELECT DATENAME('m', realDate) + RIGHT(YEAR(realDate, 2)
> ORDER BY realDat> make a computed column in the query only, and order by that>> Please, ALWAYS indicate what database you're using
>> As a final try, you could reverse engineer the abbreviation an> Aaron Bertran>> -
> SQL Server MV
> [url]http://www.aspfaq.com[/url]> news:B3BB87DA-0ED7-446F-B739-4DD488991770@microsoft.com..>>>>> "MDW" <anonymous@discussions.microsoft.com> wrote in messag> got a "date" field that is very important for my users. Its dat>> Hey all>>> I've got a database I'm going to be linking to via ASP. It'
> come from an outside source and I don't have a lot of contro
> over it. Essentially, this field contains the appreviated mont
> name, concatenated with the last two digits of the year, makin
> it effectively a text field. For instance, "DEC03" or "MAR04"> actual date. If I sorted it as text, then "FEB04" would com>>> What I want to do is sort on this column, but sort it by th
> before "JAN04", etc. >> I can create a function that woul
> receive this field as input, and return some value, such a
> #01/01/2004# for "JAN04"....but I'm unsure how to incorporat
> that into a SQL statement
Microsoft MVP -- ASP/ASP.NE
Please reply to the newsgroup. The email account listed in my Fro
header is my spam trap, so I don't check it very often. You will get
quicker response by posting to the newsgroup
MDW Guest
-
Aaron Bertrand - MVP #6
Re: Convert Month Names To Sortable Values?
> And no, the function will probably be called convertAbbDate or something.
And then plan to rewrite your function from scratch when you move to SQL
Server. :-(
I honestly think you will be more efficient with time if you start with MSDE
or Personal Edition / Developer Edition.
Aaron Bertrand - MVP Guest



Reply With Quote

