A Fun Thanksgiving Day Query.

Download PDF

Download the Thanksgiving query sample code here.

I thought it would be fun to put together a query to get us in the spirit of Thanksgiving dinner tonight.

This query is using techniques from another recent posting on CSV formatting query output.

 

Here is my Thanksgiving gift to you, the Thanksgiving day query.

 

Don’t copy and paste, your browser may mess up the single quotes… Instead download the Thanksgiving query sample code here.

-- a fun Thanksgiving day sql query
SELECT 'turkey'
UNION
SELECT 'stuffing'
UNION
SELECT 'cranberry sauce'
UNION
SELECT 'yams'
UNION
SELECT 'sweet potato pie'
UNION
SELECT 'gravy'
UNION
SELECT 'beans'
UNION
SELECT 'green bean casserole'
UNION
SELECT 'mashed potatos'
UNION
SELECT 'collard greens'
UNION
SELECT 'beer'
UNION
SELECT 'cider'
UNION
SELECT 'pumpkin pie';

GO

-- but thats too much food, 
--so lets keep on the diet track with only 5 items for turkey day dinner

SELECT TOP 5 fooditem FROM (
SELECT 'turkey' AS fooditem
UNION
SELECT 'stuffing'
UNION
SELECT 'cranberry sauce'
UNION
SELECT 'yams'
UNION
SELECT 'sweet potato pie'
UNION
SELECT 'gravy'
UNION
SELECT 'beans'
UNION
SELECT 'green bean casserole'
UNION
SELECT 'mashed potatos'
UNION
SELECT 'collard greens'
UNION
SELECT 'beer'
UNION
SELECT 'cider'
UNION
SELECT 'pumpkin pie' ) AS t1
ORDER BY Newid(); -- throw in some random ordering

GO
-- ok, but lets throw it into a comma delimited list rather than a table

SELECT Substring((SELECT ', ' + fooditem
FROM (
SELECT TOP 5 fooditem FROM (
SELECT 'turkey' AS fooditem
UNION
SELECT 'stuffing'
UNION
SELECT 'cranberry sauce'
UNION
SELECT 'yams'
UNION
SELECT 'sweet potato pie'
UNION
SELECT 'gravy'
UNION
SELECT 'beans'
UNION
SELECT 'green bean casserole'
UNION
SELECT 'mashed potatos'
UNION
SELECT 'collard greens'
UNION
SELECT 'beer'
UNION
SELECT 'cider'
UNION
SELECT 'pumpkin pie' ) AS t1 ORDER BY Newid()) AS t2
FOR XML PATH('')),3,10000000) AS list

 

Here is the output…

Happy Thanksgiving Everyone!

 

More from Stedman Solutions:

SteveStedman5
Steve and the team at Stedman Solutions are here for all your SQL Server needs.
Contact us today for your free 30 minute consultation..
We are ready to help!

Leave a Reply

Your email address will not be published. Required fields are marked *

*