7
\$\begingroup\$

In as few bytes as possible in t-sql, return 100 rows containing the phrase 'Have a great Christmas'

92 (I think) to beat :D

CREATE TABLE #(m char(99))
GO
INSERT # SELECT'Have a great Christmas'
GO 100
SELECT * FROM #

Previous best effort was:

WITH t(m,r)AS(SELECT'Have a great Christmas',1 UNION ALL SELECT m,r+1 FROM t WHERE r<100)SELECT m FROM t;
\$\endgroup\$
6
  • 1
    \$\begingroup\$ Welcome to Code Golf! By the way, why is the scoring in characters instead of the site default of bytes? \$\endgroup\$ Dec 17 '21 at 17:54
  • 1
    \$\begingroup\$ If you posted your 96 byte code here, you could also make this a tips question. \$\endgroup\$ Dec 17 '21 at 18:04
  • \$\begingroup\$ Ok cool, as an answer or comment? \$\endgroup\$ Dec 17 '21 at 18:07
  • 2
    \$\begingroup\$ For a language-specific tips question, you can put the code in the body of the question, like this one. \$\endgroup\$
    – DLosc
    Dec 17 '21 at 18:11
  • \$\begingroup\$ What version of TSQL are you looking for? \$\endgroup\$
    – pajonk
    Dec 17 '21 at 18:34
4
\$\begingroup\$

SQL Server (tested on 2016) - 82 78 bytes

SELECT TOP 100*FROM STRING_SPLIT(REPLICATE('Have a great Christmas!',100),'!')

SQL Server (tested on 2016) - 88 87 bytes (Old Solution)

WITH N(a)AS(SELECT'Have a great Christmas'UNION ALL SELECT*FROM N)SELECT TOP 100*FROM N

Of course, on a sql instance with existing objects, you can come up with some... hackier solutions.

For example, 58 bytes that are pretty darn likely to work:

SELECT TOP 100'Have a great Christmas'FROM sys.all_objects
\$\endgroup\$
1
  • \$\begingroup\$ All Brilliant!! \$\endgroup\$ Dec 17 '21 at 19:26
4
\$\begingroup\$

SQL Server 2016, 54 53 bytes

Edit: -1 byte thanks to @Kevin Cruijssen.

select top 100'Have a great Christmas'from spt_values

Works in my instance of SQL Server 2016.

spt_values may be replaced with any system view/table of at least 100 rows.

Inspired by this tips answer.

\$\endgroup\$
3
  • \$\begingroup\$ Very good! I should have gone with a bigger number :D \$\endgroup\$ Dec 17 '21 at 19:27
  • 1
    \$\begingroup\$ Can the space at Christmas'from be removed? \$\endgroup\$ Dec 17 '21 at 21:19
  • 1
    \$\begingroup\$ @KevinCruijssen, yes, it seems so. Thanks! \$\endgroup\$
    – pajonk
    Dec 18 '21 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.