Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
547 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Software ==> | SQL (203 exercises) |
Topic ==> | Calculations using dates (7 exercises) |
Level ==> | Harder than average |
Subject ==> | SQL training |
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
This will generate the database that you'll need to use in order to do this exercise (note that the database and script are only to be used for exercises published on this website, and may not be reused or distributed in any form without the prior written permission of Wise Owl).
Create a query to show the full dates for any event:
The first few events, in chronological order.
To get the suffix, you'll need to use a CASE statement based on the day number for any date.
Save this query as Query suffices (marvelling at the wordplay involved in the title), then close it down.
You can find other training resources for the subject of this exercise here:
From: | Bhavya59 |
When: | 01 Aug 24 at 05:52 |
SELECT [EventName]
,[EventDate]
,DATENAME(WEEKDAY,EventDate)+' '+DATENAME(DAY,EventDate)+
CASE
WHEN DATEPART(DAY,EventDate) IN (1,21,31) THEN 'st '
WHEN DATEPART(DAY,EventDate) IN (2,22) THEN 'nd '
WHEN DATEPART(DAY,EventDate) IN (3,23) THEN 'rd '
ELSE 'th '
END +
DATENAME(MONTH,EventDate)+' '+DATENAME(YEAR,EventDate) AS 'FullDate'
FROM [WorldEvents].[dbo].[tblEvent]
ORDER BY EventDate
From: | Orin |
When: | 02 Jan 24 at 10:42 |
One solution with Format and Day :
format(EventDate, 'dddd d') + CASE WHEN day(EventDate) IN (1,21,31) THEN 'st ' WHEN day(EventDate) IN (2,22) THEN 'nd ' WHEN day(EventDate) IN (3,23) THEN 'rd ' ELSE 'th ' END + format(EventDate, 'MMMM yyyy') AS 'Full Date2'
From: | Yash2211 |
When: | 24 Sep 23 at 12:15 |
select EventName, concat(week_name,' ',date_name,' ',month_name,' ',year_no) as 'Full date' from
(select eventname,eventdate,datename(weekday,eventdate) as week_name,datename(year,eventdate) as year_no,datename(month,eventdate)as month_name
,datename(day,eventdate)as date_no,
case
when datename(day,eventdate) = 1 then '1st'
when datename(day,eventdate) =2 then '2nd'
when datename(day,eventdate) = 3 then '3rd'
when datename(day,eventdate) not in (1,2,3) then CONCAT(cast(datename(day,eventdate) as varchar(10)),'th')
end as date_name
from tblevent
) as t
order by eventdate
From: | Chinmaykumar |
When: | 04 Jul 23 at 13:31 |
Query_Sol. for MySQL users
SELECT EventName,
CONCAT(DAYNAME(EventDate),' ',DAY(EventDate),
CASE WHEN DAY(EventDate) IN (1,21,31) THEN 'st'
WHEN DAY(EventDate) IN (2,22) THEN 'nd'
WHEN DAY(EventDate) IN (3,23) THEN 'rd'
ELSE 'th'
END,' ',MONTHNAME(EventDate),' ',YEAR(EventDate)) AS 'FULL date'
FROM tblevent
ORDER BY EventDate ASC;
From: | waltz |
When: | 09 May 21 at 10:55 |
select EventName as [Event Name]
,concat(datename(weekday,EventDate),' '
,case when datepart(day,EventDate) in (1,21,31)
then convert(varchar,datepart(day,EventDate))+'st'
when datepart(day,EventDate) in (2,22)
then convert(varchar,datepart(day,EventDate))+'nd'
when datepart(day,EventDate) in (3,23)
then convert(varchar,datepart(day,EventDate))+'rd'
else convert(varchar,datepart(day,EventDate)) +'th'
end ,' '
,datename(month, EventDate) ,' '
,year(EventDate)) as [Full Date]
from [dbo].[tblEvent]
From: | ShukiMolk |
When: | 10 Apr 20 at 02:12 |
Why do we need to use the CASE function?
What's wrong with this:
SELECT EventName, EventDate, ( (DATENAME(Weekday, EventDate)) + ' ' + (DATENAME(day, EventDate)) + 'th ' + (DATENAME(month, EventDate)) + ' ' + (DATENAME(year, EventDate)) ) AS 'Full Date'
FROM [tblEvent]
ORDER BY EventDate
From: | DbEnthusiast |
When: | 18 Dec 20 at 18:47 |
SELECT EventName
,EventDate
,CASE WHEN DATEPART(day,EventDate) IN (1,21,31) THEN CONCAT(DATENAME(weekday,EventDate),' ',DATEPART(day,EventDate),'st ',DATENAME(month,EventDate),' ',DATEPART(year,EventDate))
WHEN DATEPART(day,EventDate) IN (2,22) THEN CONCAT(DATENAME(weekday,EventDate),' ',DATEPART(day,EventDate),'nd ',DATENAME(month,EventDate),' ',DATEPART(year,EventDate))
WHEN DATEPART(day,EventDate) IN (3,23) THEN CONCAT(DATENAME(weekday,EventDate),' ',DATEPART(day,EventDate),'rd ',DATENAME(month,EventDate),' ',DATEPART(year,EventDate))
ELSE CONCAT(DATENAME(weekday,EventDate),' ',DATEPART(day,EventDate),'th ',DATENAME(month,EventDate),' ',DATEPART(year,EventDate))
END as FullDate
FROM tblEvent
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.