SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Question of the Day for 21 Dec 2009


Question of the Day for 21 Dec 2009

Author
Message
Steve Jones
Steve Jones
SSC Guru
SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)

Group: Administrators
Points: 84530 Visits: 19224
Discussions about the question: Riddle Me This

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
GSquared
GSquared
SSC-Dedicated
SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)

Group: General Forum Members
Points: 31313 Visits: 9730
I had to decipher the code based on the usual methodology. I haven't seen the Frosty the Snowman movie since the 70s. Amusing question though.

Steve: Is there a way to get the code in these to copy-and-paste without losing line-breaks? After I answer, I like to test it, and I have to go through and manually re-add line breaks after copying it into SSMS.

- 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
SQLRNNR
SQLRNNR
SSC-Forever
SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)

Group: General Forum Members
Points: 41353 Visits: 18565
Thanks Gus. I was hoping for that kind of response.

Along the code copy comment - It would be nice to be able to use the ifCode for SQL code in the QOD. I think that may help with the line break issue. I didn't see that option being a QOD novice.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Jedak
Jedak
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2779 Visits: 1125
GSquared (12/21/2009)
Steve: Is there a way to get the code in these to copy-and-paste without losing line-breaks? After I answer, I like to test it, and I have to go through and manually re-add line breaks after copying it into SSMS.


Agreed, I pulled the code out and put it in Query Analyzer to be able to read it better, and had to put all the line breaks. I enjoyed the question.
SanjayAttray
SanjayAttray
SSCarpal Tunnel
SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)

Group: General Forum Members
Points: 4767 Visits: 1619
Doesn't 8,1,16,16,25,27,2,9,18,20,8,4,1,25 stands numerical order for HAPPY BIRTHDAY in alphabets.
In code is selecting top 26.

SQL DBA.
SQLRNNR
SQLRNNR
SSC-Forever
SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)

Group: General Forum Members
Points: 41353 Visits: 18565
I am not certain I follow your question.

The code does do a select top 26, and then an additional insert after that for 27. The insert for 27 is an empty string.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Steve Jones
Steve Jones
SSC Guru
SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)

Group: Administrators
Points: 84530 Visits: 19224
We have gone back and forth on the code and haven't had a good solution for people to enter it and then have it display as well as cut paste. I think if you drop it in a text editor and copy back out it works.

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
SQLRNNR
SQLRNNR
SSC-Forever
SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)

Group: General Forum Members
Points: 41353 Visits: 18565
Thanks Steve. It only seems to happen every once in a while that the code doesn't copy so well from the QOD.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)

Group: General Forum Members
Points: 118838 Visits: 41482
BWAA-HAA!!! Frosty needs to get a set-based decoder ring! :-P

DECLARE @ToAllGoodPeople TABLE
(
RowNum INT,
Cypher VARCHAR(100)
)

INSERT INTO @ToAllGoodPeople
(RowNum, Cypher)
SELECT 1,'8.1.16.16.25.27.2.9.18.20.8.4.1.25' UNION ALL
SELECT 2,'1.14.4.27.7.15.15.4.23.9.12.12' UNION ALL
SELECT 3,'20.15.27.1.12.12'

SELECT REPLACE((SELECT CHAR(SUBSTRING('.'+p2.Cypher,N+1,CHARINDEX('.',p2.Cypher+'.',N)-N)+64)
FROM dbo.Tally t
CROSS JOIN @ToAllGoodPeople p2
WHERE p1.RowNum = p2.RowNum
AND t.N <= LEN(p2.Cypher)+1
AND SUBSTRING('.'+p2.Cypher,t.N,1) = '.'
ORDER BY t.N
FOR XML PATH(''))
,'[',' ')
FROM @ToAllGoodPeople p1
GROUP BY p1.RowNum
ORDER BY p1.RowNum



--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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
vk-kirov
vk-kirov
Hall of Fame
Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)

Group: General Forum Members
Points: 3912 Visits: 4408
Jeff Moden (12/21/2009)

...
SELECT REPLACE((SELECT CHAR(SUBSTRING('.'+p2.Cypher,N+1,CHARINDEX('.',p2.Cypher+'.',N)-N)+64)
FROM dbo.Tally t
...


Msg 208, Level 16, State 1, Line 13
Invalid object name 'dbo.Tally'. ;-)

I guess there are natural numbers in this table. This would work:

...
SELECT REPLACE((SELECT CHAR(SUBSTRING('.'+p2.Cypher,N+1,CHARINDEX('.',p2.Cypher+'.',N)-N)+64)
FROM (SELECT number AS N FROM master.dbo.spt_values WHERE type = 'P') t
...


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search