pr3mium
Posts: 31
|
Posted: 02/22/2004, 11:17 PM |
|
I have a birthday field in my employees table, but it's in the form of YYYYMMDD (generated from Social security number). How could I do the ORDER BY '%DD' or something like that? I query this month's birthdays and would like to order the results by the day.
I've heard of the CONVERT function in SQL - can I use this to somehow convert the field to datetime while querying?
Any ideas would be highly appreciated.
Thanks
|
|
|
pr3mium
Posts: 31
|
Posted: 02/22/2004, 11:36 PM |
|
Sorry for bothering, after some research I used the following query:
SELECT DISTINCT name,birth,DATEPART(dd, birth) FROM emp_view
WHERE birth LIKE '____02__'
ORDER BY DATEPART(dd, birth)
|
|
|
DonB
|
Posted: 02/23/2004, 11:53 AM |
|
I would highly recommend storing the date parts you are interested in as
their own columns in the table so you can properly index them. A 'LIKE'
forces a table-scan (all records are read and compared).
You will be fine for a small amount of rows, but will suffer greater
overhead as the number increases.
--
DonB
http://www.gotodon.com/ccbth
"pr3mium" <pr3mium@forum.codecharge> wrote in message
news:64039ad84c28d2@news.codecharge.com...
> Sorry for bothering, after some research I used the following query:
>
> SELECT DISTINCT name,birth,DATEPART(dd, birth) FROM emp_view
> WHERE birth LIKE '____02__'
> ORDER BY DATEPART(dd, birth)
>
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
|