Intresting Question need answer ASAP

  • Well, without using any arabic numerals, you could also do:

    SELECT PI()/PI();

    But those are "numbers", without being "digits", so it's probably not acceptable.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • This is short and obscure: :satisfied:

    select cos('')

    Results:

    ----------------------

    1

    (1 row(s) affected)

  • David Moutray (9/20/2012)


    Somehow I think SELECT LEN('a') is too simple for Dave's competition. There must be some really obscure way of returning a 1.

    I can think of several hundred increasingly obscure ways.

    SELECT ASCII('B') - ASCII('A') comes to mind, but it's longer than simpler options.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • GilaMonster (9/20/2012)


    David Moutray (9/20/2012)


    Somehow I think SELECT LEN('a') is too simple for Dave's competition. There must be some really obscure way of returning a 1.

    I can think of several hundred increasingly obscure ways.

    SELECT ASCII('B') - ASCII('A') comes to mind, but it's longer than simpler options.

    I mainly meant obscure. SELECT LEN('a') is 13 characters. SELECT cos('') is 12 characters. Is it possible to trim any more characters off of this?

    I also saw someone use the PRINT function (which would be one character less than SELECT). Are there any command shortcuts? Perhaps something from SQL 6.5 (or older)? :alien:

  • David Moutray (9/20/2012)


    GilaMonster (9/20/2012)


    David Moutray (9/20/2012)


    Somehow I think SELECT LEN('a') is too simple for Dave's competition. There must be some really obscure way of returning a 1.

    I can think of several hundred increasingly obscure ways.

    SELECT ASCII('B') - ASCII('A') comes to mind, but it's longer than simpler options.

    I mainly meant obscure. SELECT LEN('a') is 13 characters. SELECT cos('') is 12 characters. Is it possible to trim any more characters off of this?

    I also saw someone use the PRINT function (which would be one character less than SELECT). Are there any command shortcuts? Perhaps something from SQL 6.5 (or older)? :alien:

    The OP specified a SELECT.

  • True, and the competition on SQLAuthority shows a SELECT statement in the sample, but I imagine that something different might be accepted, if it were creative. At least it might get an honorable mention.

  • Another short one.

    select day('')

  • The only other answer I could come up with was

    SELECT DB_ID()

    which will return '1' if you are in the Master database (which is usually the default).

    This, of course, is the same length as the answers from the previous responses

    SELECT cos('')

    and

    SELECT day('')

    It will be interesting to see if anyone does better.

  • vax09 (9/20/2012)


    One more

    SELECT CAST(634 AS VARCHAR(2))

    why it display * in result

    vax09 (9/20/2012)


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

    David Moutray (9/20/2012)


    Now, now, Gentlemen. :rolleyes:

    The questions posted here are from today's blog by Pinal Dave on SQLAuthority. You can ask any question, but perhaps some of us would like to compete as well. (Dave is offering a $50 Amazon.com gift card to the winner.)

    For those interested, you can enter the competition here: http://blog.sqlauthority.com/

    I wonder if the OP knows what "black balled for unethical behaviour" means?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Well, let's be charitable and assume that he is suitably embarrassed by his behavior.

  • Not the shortest but interesting

    SELECT COUNT(*)

  • David Moutray (9/20/2012)


    GilaMonster (9/20/2012)


    David Moutray (9/20/2012)


    Somehow I think SELECT LEN('a') is too simple for Dave's competition. There must be some really obscure way of returning a 1.

    I can think of several hundred increasingly obscure ways.

    SELECT ASCII('B') - ASCII('A') comes to mind, but it's longer than simpler options.

    I mainly meant obscure. SELECT LEN('a') is 13 characters. SELECT cos('') is 12 characters. Is it possible to trim any more characters off of this?

    I also saw someone use the PRINT function (which would be one character less than SELECT). Are there any command shortcuts? Perhaps something from SQL 6.5 (or older)? :alien:

    Uh, perhaps I am counting wrong but:

    - SELECT LEN('a') looks like 15 characters to me

    - SELECT COS('') is 14 characters

    So how about:

    SELECT LEN(0)


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • Hi Dwain

    Not allowed to use numbers in the SELECT 😉

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

    ==========================================================================================================================
    A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila. Mitch Ratcliffe

  • Andy Hyslop (9/21/2012)


    Hi Dwain

    Not allowed to use numbers in the SELECT 😉

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

    Oh! Thought I could only not use the number 1! 😛

    Guess I'll have to submit this and settle for a tie.

    SELECT EXP('')

    Should get points for obscure.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • ...

    I mainly meant obscure. SELECT LEN('a') is 13 characters. SELECT cos('') is 12 characters. Is it possible to trim any more characters off of this?

    ...

    How did you count characters? I got:

    SELECT LEN('a') - 15 characters

    SELECT COS('') - 14 characters

    And I can give you one less:

    SELECT COS(0) - 13 characters

    Edited: OOps, didn't see the second page of conversation 🙂

    Yeah and I've used number, so LEN or EXP will do better

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

Viewing 15 posts - 16 through 30 (of 46 total)

You must be logged in to reply to this topic. Login to reply