Published
Tuesday, November 22, 2005 3:50 PM
/*
This puzzle is simple. Given the table below you have to output the
words of the famous Christmas carol using a single select statement.
Each line must be a separate row of the results set. I am also adding
the restriction that you can not use a union statement. This is to stop
cheating such as having a select statement for each line. The
output should be as follows (A space between each verse would be good).
EDIT Sorry missed the table creation code of the first post DOH!!.
On the first day of Christmas,
my true love sent to me
A partridge in a pear tree.
On the second day of Christmas,
my true love sent to me
Two turtle doves,
And a partridge in a pear tree.
On the third day of Christmas,
my true love sent to me
Three French hens,
Two turtle doves,
And a partridge in a pear tree.
On the fourth day of Christmas,
my true love sent to me
Four calling birds,
Three French hens,
Two turtle doves,
And a partridge in a pear tree.
On the fifth day of Christmas,
my true love sent to me
Five golden rings,
Four calling birds,
Three French hens,
Two turtle doves,
And a partridge in a pear tree.
On the sixth day of Christmas,
my true love sent to me
Six geese a-laying,
Five golden rings,
Four calling birds,
Three French hens,
Two turtle doves,
And a partridge in a pear tree.
On the seventh day of Christmas,
my true love sent to me
Seven swans a-swimming,
Six geese a-laying,
Five golden rings,
Four calling birds,
Three French hens,
Two turtle doves,
And a partridge in a pear tree.
On the eighth day of Christmas,
my true love sent to me
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five golden rings,
Four calling birds,
Three French hens,
Two turtle doves,
And a partridge in a pear tree.
On the ninth day of Christmas,
my true love sent to me
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five golden rings,
Four calling birds,
Three French hens,
Two turtle doves,
And a partridge in a pear tree.
On the tenth day of Christmas,
my true love sent to me
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five golden rings,
Four calling birds,
Three French hens,
Two turtle doves,
And a partridge in a pear tree.
On the eleventh day of Christmas,
my true love sent to me
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five golden rings,
Four calling birds,
Three French hens,
Two turtle doves,
And a partridge in a pear tree.
On the twelfth day of Christmas,
my true love sent to me
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five golden rings,
Four calling birds,
Three French hens,
Two turtle doves,
And a partridge in a pear tree!
(114 row(s) affected)
*/
SET NOCOUNT ON
DECLARE @Presents TABLE
(
InitialDayRecieved VARCHAR(50),
Present VARCHAR(50)
)
INSERT INTO @Presents(InitialDayRecieved, Present)
SELECT 'first', 'A partridge in a pear tree'
INSERT INTO @Presents(InitialDayRecieved, Present)
SELECT 'second', 'Two turtle doves'
INSERT INTO @Presents(InitialDayRecieved, Present)
SELECT 'third', 'Three French hens'
INSERT INTO @Presents(InitialDayRecieved, Present)
SELECT 'fourth', 'Four calling birds'
INSERT INTO @Presents(InitialDayRecieved, Present)
SELECT 'fifth', 'Five golden rings'
INSERT INTO @Presents(InitialDayRecieved, Present)
SELECT 'sixth', 'Six geese a-laying'
INSERT INTO @Presents(InitialDayRecieved, Present)
SELECT 'seventh', 'Seven swans a-swimming'
INSERT INTO @Presents(InitialDayRecieved, Present)
SELECT 'eighth', 'Eight maids a-milking'
INSERT INTO @Presents(InitialDayRecieved, Present)
SELECT 'ninth', 'Nine ladies dancing'
INSERT INTO @Presents(InitialDayRecieved, Present)
SELECT 'tenth', 'Ten lords a-leaping'
INSERT INTO @Presents(InitialDayRecieved, Present)
SELECT 'eleventh', 'Eleven pipers piping'
INSERT INTO @Presents(InitialDayRecieved, Present)
SELECT 'twelfth', 'Twelve drummers drumming'
SET NOCOUNT OFF