SQL SERVER – Puzzle – Shortest Code to Produce the Number 1000000000 (One Billion)

This shortest code puzzle asks for 1000000000 without writing that literal or using arithmetic operators. Short-code puzzles always bring a flood of clever answers, and this one is a good test of how well you know T-SQL’s built-in functions.

A compact folded fitting is compared with a larger assembly beside a constrained guide channel.

The Rules

  1. You may use numbers, but not the literal 1000000000 itself.
  2. You may not use arithmetic operators.

The benchmark is ten characters, including spaces. Submit the exact code, its character count and the value it returns in SQL Server. Can you meet or beat that length while following both rules?

Before you post, run your answer and check two things. Does it return exactly 1000000000, and not 1000000000.0 or a string? Does it avoid every arithmetic operator, including the ones hiding inside an expression? A clever answer that breaks a rule is still a miss.

Puzzle rules: Make 1000000000

A compact expression is not a solution until checked, it is a candidate against the puzzle rules.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

SQL Function, SQL Scripts, SQL Server
Previous Post
SQL SERVER – Select Unique Data From a Column Exist in Two Different Table
Next Post
Adding Two Dates in SQL Server: Why the Year Is 2126

Related Posts

33 Comments. Leave new

  • select power(10,9)

    Reply
  • select ‘1’ + replicate(‘0’,9)

    Reply
  • select 1E9

    Reply
  • Does the 10 count include a select at the start? Otherwise SELECT POWER(10,9)

    Reply
  • I think scientific notation is the answer to this one:

    SELECT 1E9

    10 characters, including space.

    Reply
  • select convert(int,’10000’+’00000′)

    Reply
  • SELECT CAST(CONCAT(‘100000000′,’0’ ) AS INT)

    Reply
  • SELECT POWER(10,9)

    Reply
  • Ramesh Pothuraju
    October 13, 2017 8:12 pm

    SELECT CONCAT(‘1’, ‘000000000’)

    Reply
  • Justin Terry (Syswright Limited)
    September 3, 2018 6:31 pm

    SELECT SQRT(1E18)

    Reply
  • Let’s split hairs….

    If you are obeying the rules you cannot use scientific notation. Rule 1 says you cannot use the number “One billion”. 1E9 is the number one billion, just represented differently.

    It also doesn’t say that the output format must be standard notation. It says the number “One billion”. So, if Scientific notation is allowed, we can do:

    PRINT 1E9

    The rules don’t specify the value must be returned, just “produced”.

    But if we can’t use scientific notation:

    PRINT power(10,9)

    But you may consider POWER to be an arithmetic operator, as it is in other languages. In VB you could say

    Debug.Print 10^9

    My final contribution then, is:

    PRINT’1’+’000000000′

    Where we drop the space after PRINT because it’s not required for parsing, and the ‘+’ is concatenation and not an arithmetic operator.

    Hairs split. What a lovely parting I now have :-)

    Reply

Leave a Reply

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

Fill out this field
Fill out this field
Please enter a valid email address.