Print Christmas tree in SQL Server

Lets see how to print a Xmas or Christmas Tree in SQL Server.

The best way of implementing a Xmas tree pattern you can use a Recursive CTE, as shown in below T-SQL.



Note that:  After writing a below T-SQL, execute your query with Results to text for better format.

WITH CTE
AS (
   SELECT 
   CAST(REPLICATE(' ', 10) + '^' AS NVARCHAR(100)) AS Pattern,
   0 AS n
   UNION ALL
  SELECT 
  CAST(REPLICATE(' ', 9 - n) + 'O' + REPLICATE('V', 2 * n + 1) + 'O' AS NVARCHAR(100)),
  CTE.n + 1
  FROM CTE WHERE n < 10
)
SELECT Pattern As 'Happy Merry Christmas !! ' 
FROM CTE 
UNION ALL
SELECT CAST(REPLICATE(' ', 8) + '| |' AS NVARCHAR(100)) AS Pattern
UNION ALL
SELECT CAST(REPLICATE(' ', 5) + '~~~``~~~' AS NVARCHAR(100)) AS Pattern

 

Also Read..

Displaying Emoji in SQL Server

Create a custom shortcuts in SQL Server

Displaying line numbers in Query Editor Window

SQL Basics TutorialSQL Advance TutorialSSRSInterview Q & A
SQL Create tableSQL Server Stored ProcedureCreate a New SSRS Project List Of SQL Server basics to Advance Level Interview Q & A
SQL ALTER TABLESQL Server MergeCreate a Shared Data Source in SSRSSQL Server Question & Answer Quiz
SQL DropSQL Server PivotCreate a SSRS Tabular Report / Detail Report
..... More.... More....More
Power BI TutorialAzure TutorialPython TutorialSQL Server Tips & Tricks
Download and Install Power BI DesktopCreate an Azure storage accountLearn Python & ML Step by stepEnable Dark theme in SQL Server Management studio
Connect Power BI to SQL ServerUpload files to Azure storage containerSQL Server Template Explorer
Create Report ToolTip Pages in Power BICreate Azure SQL Database ServerDisplaying line numbers in Query Editor Window
....More....More....More




 362 total views,  1 views today

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.