Task 8(added)

–For each battle find out the first and the last day of the month when the

–battle took place.

–Result set: tne battle name, the first day of month, the last day of month.

–Note: dates must be given in the format "yyyy-mm-dd".

–battle firstD lastD

–Guadalcanal 1942-11-01 1942-11-30

–North Atlantic 1941-05-01 1941-05-31

–North Cape 1943-12-01 1943-12-31

–Surigao Strait 1944-10-01 1944-10-31

–#Cuba62a 1962-10-01 1962-10-31

–#Cuba62b 1962-10-01 1962-10-31

select name, replace(str(Year(date), 4), ‘ ‘, ‘0’) + ‘-‘ + replace(str(month(date), 2), ‘ ‘, ‘0’) + ‘-01’,

replace(str(Year(dateadd( DAY, 1 , (dateadd(month, 1, replace(str(Year(date), 4), ‘ ‘, ‘0’) + ‘-‘ + replace(str(month(date), 2), ‘ ‘, ‘0’) + ‘-01’)))), 4), ‘ ‘, ‘0’)

+ ‘-‘ + replace(str(month(dateadd( DAY, 1 , (dateadd(month, 1, replace(str(Year(date), 4), ‘ ‘, ‘0’) + ‘-‘ + replace(str(month(date), 2), ‘ ‘, ‘0’) + ‘-01’)))), 2), ‘ ‘, ‘0’) +

+ ‘-‘ + replace(str(day(dateadd( DAY, 1 , (dateadd(month, 1, replace(str(Year(date), 4), ‘ ‘, ‘0’) + ‘-‘ + replace(str(month(date), 2), ‘ ‘, ‘0’) + ‘-01’)))), 2), ‘ ‘, ‘0’)

from

Battles

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s