SQL SERVER – 2 T-SQL Puzzles and Win USD 50 worth Amazon Gift Card and 25 Other Prizes

We all love brain teasers and interesting puzzles. Today I decided to come up with 2 interesting puzzles and winner of the contest will get USD 50 worth Amazon Gift Card. The puzzles are sponsored by NuoDB. Additionally, The first 25 individuals who download NuoDB Beta 8 by midnight Friday, Sept. 21 (EST) will automatically receive a $10 Amazon gift card.

Puzzle 1:

Why following code when executed in SSMS displays result as a * (Star)?

SELECT CAST(634 AS VARCHAR(2))

SQL SERVER - 2 T-SQL Puzzles and Win USD 50 worth Amazon Gift Card and 25 Other Prizes puzzlestar

Puzzle 2:

Write the shortest code that produces results as 1 without using any numbers in the select statement.

SQL SERVER - 2 T-SQL Puzzles and Win USD 50 worth Amazon Gift Card and 25 Other Prizes puzzle1

Bonus Q:

How many different Operating System (OS) NuoDB support?
Click here HINT

If you can solve above puzzles you will be eligible for winning USD 50 Amazon Gift Card. However, you can always enroll yourself for following Bonus Prizes where if you have good chance of winning USD 10 Amazon Gift Card (if you are first 25 individual in specific time).

Bonus Prizes:

The first 25 individuals who download NuoDB Beta 8 by midnight Friday, Sept. 21 (EST) will automatically receive a $10 Amazon gift card.

Rules:

  • Please leave an answer in the comments section below.
  • You can resubmit your answer multiple times, the latest entry will be considered valid.
  • The winner will be announced on 1st October.
  • Last day to participate in the puzzle is September 28th, 2012.
  • All valid answer will be kept hidden till September 28th, 2012.
  • Only One Winner will get USD 50 worth Amazon Gift Card.
  • The first 25 individuals who download NuoDB Beta 8 by midnight Friday, Sept. 21 (EST) will automatically receive a $10 Amazon gift card.
  • The winner will be selected using random algorithm.

UPDATE: The winner of the contest is Jaime Mtnz Lafargue (@jaimeml)

Reference: Pinal Dave (https://blog.sqlauthority.com)

NuoDB
Previous Post
SQL SERVER – Effect of Collation on Resultset – SQL in Sixty Seconds #026 – Video
Next Post
SQL SERVER – Replace a Column Name in Multiple Stored Procedure All Together

Related Posts

365 Comments. Leave new

  • couple of way
    1. select count(*)
    2. select len(‘a’)

    Reply
  • a. Truncation. The length of the number (3) as a string exceeds the 2 character limit specified
    b. select @@ROWCOUNT
    c. Five supported OS’s

    Reply
  • *answer For First Question is”Because we select nvarchar(2)..that store only
    tow charcter

    *answer for second Question is “select LEN(‘a’))

    Reply
  • keith kryne velasco
    September 30, 2012 7:39 am

    select len(‘a)

    Reply
  • select cast(634 as varchar(2))

    means the length of the integer value is greater than the converting value that time it is showing the result.

    Reply
  • select len(‘a’)

    Reply
  • Bonus Q:

    5 operating system

    Reply
  • SELECT @@Option/@@Option

    Reply
    • Manish Kaushik
      October 1, 2012 8:26 am

      Klaine07,

      I tried SELECT @@Option/@@Option,
      and I faced this error

      Msg 137, Level 15, State 2, Line 1
      Must declare the scalar variable “@@Option”

      Reply
  • SELECT CAST(‘TRUE’ AS BIT)

    Reply
  • (1) VARCHAR(2) isn’t big enough for three digit int, and conversion from int to VARCHAR which doesn’t fit returns * instead of truncating
    (2) select (count(*))
    (3) 5

    Reply
  • Hey Pinal, I am exited and desperate to know the result, and its already Oct 1st started in India, Please share the results as early as possible.

    Reply
  • Manish Kaushik
    October 1, 2012 8:23 am

    Hey Pinal, I am exited and desperate to know the result, and its already Oct 1st in India, Please share the results as early as possible.

    Thanks
    Manish

    Reply
  • SELECT ‘1’

    the reason for using ‘1’ (and I got some slack for using ‘1’) is because technically ‘1’ is NOT a number it is a char! so select ‘1’ does reproduce the requested output, and if you where using ado to set to int sql server likes to do something called implicit casting.

    Reply
  • SELECT ’1′

    the reason for using ’1′ (and I got some slack for using ’1′) is because technically ’1′ is NOT a number it is a char! so select ’1′ does reproduce the requested output, and if you where using ado to set to int sql server likes to do something called implicit casting.

    Reply
  • Đoàn Thanh Sa
    October 3, 2012 12:12 pm

    Hi pinaldave. Why is my answer not correct? I answer sooner than Jaime.

    “This is my answer. Question 1: When converting number to character type, the result display * if result length too short to display.
    Question 2: select cos($)”

    Reply
  • Jaime Mtnz Lafargue (@jaimeml)
    October 6, 2012 4:39 pm

    Hi all,

    I’m very glad I won the contest. I’ve already received my Amazon.com gift card.
    Thank You Pinal, NuoDB and everybodoy involved.

    Kind Regards,

    Jaime

    Reply
  • ARUNAGIRI GOPAL
    May 27, 2016 4:26 pm

    select count(*)

    Reply
  • select count(*)

    Reply

Leave a Reply