September 20, 2012 at 12:53 pm
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
September 20, 2012 at 1:02 pm
This is short and obscure: :satisfied:
select cos('')
Results:
----------------------
1
(1 row(s) affected)
September 20, 2012 at 1:04 pm
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
September 20, 2012 at 1:09 pm
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:
September 20, 2012 at 1:10 pm
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.
September 20, 2012 at 1:13 pm
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.
September 20, 2012 at 1:48 pm
Another short one.
select day('')
September 20, 2012 at 3:00 pm
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.
September 20, 2012 at 3:39 pm
vax09 (9/20/2012)
One moreSELECT 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
Change is inevitable... Change for the better is not.
September 20, 2012 at 3:45 pm
Well, let's be charitable and assume that he is suitably embarrassed by his behavior.
September 20, 2012 at 5:30 pm
Not the shortest but interesting
SELECT COUNT(*)
September 21, 2012 at 3:37 am
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 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
September 21, 2012 at 3:42 am
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
September 21, 2012 at 3:46 am
Andy Hyslop (9/21/2012)
Hi DwainNot 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 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
September 21, 2012 at 4:56 am
...
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
Viewing 15 posts - 16 through 30 (of 46 total)
You must be logged in to reply to this topic. Login to reply