Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Date formatting help

Author  Topic 

Spacewarp
Starting Member

2 Posts

Posted - 2006-12-20 : 15:51:34
O.K. Here comes the wierd question of the day.

How do I tack on the ordinal on the end of a date?

I know, the normal answer is to put it in the VB .NET code or ASP .NET code.

Here's my problem.

I have a database table that stores SQL statements. The data fields from that are directly fed into an XML doc to create the Word document for our customers. I need to be able to have the SQL statement state 4th, 5th, 1st, etc. So, January 1 would be 1st. I've got month and year. Just can't seem to get this silly date issue.

Thanks for any help.

Paul

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-12-20 : 16:04:46
[code]
select
convert(varchar(10),datepart(day,DT))+
case datepart(day,DT)
when 1 then 'st'
when 2 then 'nd'
when 3 then 'rd'
when 4 then 'th'
when 5 then 'th'
/*... and so on ...*/
end
from
(select DT ='20061204' ) a
[/code]


CODO ERGO SUM
Go to Top of Page

Spacewarp
Starting Member

2 Posts

Posted - 2006-12-20 : 16:19:16
Wow. Amazingly quick. Thank you so very much.

I'm relatively slow on SQL. I was brought on to a project with a HUGE DB and told to just "muddle your way through it."

Paul
Go to Top of Page
   

- Advertisement -