Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Teaser 2: Rank 1

Status
Not open for further replies.

SQLDenis

Programmer
Oct 1, 2005
5,575
US
Shortest code wins and gets a purple star. do not post your solutions yet, just post the length of your SQL statement

you can use SQL server 2005 windowing functions, temp tables whatever you like

here is the table

Code:
create table blah2 (Col1 varchar(666) primary key clustered)
insert blah2 values('AAAAA')
insert blah2 values('ABBBBB')
insert blah2 values('ACCCCC')
insert blah2 values('BAAAAA')
insert blah2 values('BBBBBB')
insert blah2 values('BCCCCC')

expected output


Code:
Col1	Row
AAAAA	1
ABBBBB	1
ACCCCC	1
BAAAAA	2
BBBBBB	2
BCCCCC	2

Denis The SQL Menace
--------------------
SQL Server Code,Tips and Tricks, Performance Tuning
Google Interview Questions





 
you guys are tricky so and so's ;-)

Ignorance of certain subjects is a great part of wisdom
 
Make it 49, col starts at 1, not 0. Too many Javascript arrays.

[monkey][snake] <.
 
Yeah, it was 49 with the len function. I like these puzzles Denis.

[monkey][snake] <.
 
Denis,

You have an extra space where you don't need it.

select*,ascii(col1)-64Row from blah2

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Dan,

What did you end up with?

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
How do I share the code without making it visible? My solution was a hack, btw. It just happens to work, but wouldn't work automatically if you added, say, "CAAAA" and "CBBBB" to the table. Still, it DID produce the results desired, though I wouldn't give me a star for it.

Thanks,
Dan
 
use these tags

[ignore]
Your results
[/ignore]

- Paul [batman]
- If at first you don't succeed, find out if the loser gets anything.
 
It should also be mentioned that highlighting the text within spoiler tags will reveal the hidden message.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Sorry, got this to 41.
select col1,ascii(col1)-64 row from blah2

Like I said, this won't work for all values of col1, but I think will work for A-Z.

Thanks,
Dan
 
Good work. That's almost what we came up with. Now, instead of returning col1, return [!]*[/!] instead. Then play around a little more to see which spaces can be removed. You'll be surprised at which ones can go.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Duh...you're right.
select*,ascii(col1)-64 row from blah2
. Down to 37.

Thanks,
Dan
 
There is one more space that you can remove. It's add, but works. Keep going. [wink]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Wow, 36. Can't believe that works.
select*,ascii(col1)-64row from blah2

Thanks,
Dan
 
That's exactly what I thought too. [bigsmile]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top