Order by clause
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi.
I've got the following HQL:
Basically I want to convert the periodFrom to a String and put that into a list, but it should be sorted by the Date value that PeriodFrom is.
Thanks
I've got the following HQL:
Basically I want to convert the periodFrom to a String and put that into a list, but it should be sorted by the Date value that PeriodFrom is.
Thanks
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
What type is period? If its a data can you not just order by it without the function?
Oddbjorn Lona
Greenhorn
Posts: 28
posted 16 years ago
Period is an alias for a converted periodFrom, so in other words a string.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Paul Sturrock wrote:What type is period? If its a data can you not just order by it without the function?
Period is an alias for a converted periodFrom, so in other words a string.
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Ok, so you can't sort this chronologically since it is text. Another question: why do you convert to character data in the first place? Could you not just treat tge periodFrom property as a java.sql.Date?
Oddbjorn Lona
Greenhorn
Posts: 28
posted 16 years ago
Exactly.
I could probably treat the periodFrom as a date, and use a List<Date> instead of a List<String>. Probably would work.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Paul Sturrock wrote:Ok, so you can't sort this chronologically since it is text. Another question: why do you convert to character data in the first place? Could you not just treat tge periodFrom property as a java.sql.Date?
Exactly.
I could probably treat the periodFrom as a date, and use a List<Date> instead of a List<String>. Probably would work.
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Its a general rule of thumb (well, one of mine anyway
) that if formatting logic appears in a SQL or HQL query something has gone wrong with the design somewhere. If you need to format stuff, do it after the query has returned results, assuming you don;t need the formatting to get the results in the first place, which with Dates you should not.
) that if formatting logic appears in a SQL or HQL query something has gone wrong with the design somewhere. If you need to format stuff, do it after the query has returned results, assuming you don;t need the formatting to get the results in the first place, which with Dates you should not. Oddbjorn Lona
Greenhorn
Posts: 28
posted 16 years ago
hmm... good point.... i am coming from a plsql background so its a bit hard NOT to do as much formatting etc as possible in the sql
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Paul Sturrock wrote:Its a general rule of thumb (well, one of mine anyway
) that if formatting logic appears in a SQL or HQL query something has gone wrong with the design somewhere. If you need to format stuff, do it after the query has returned results, assuming you don;t need the formatting to get the results in the first place, which with Dates you should not.
hmm... good point.... i am coming from a plsql background so its a bit hard NOT to do as much formatting etc as possible in the sql

| Mo-om! You're embarassing me! Can you just read a tiny ad like a normal person? The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |








