Login or Sign Up to become a member!
LessThanDot Site Logo

LessThanDot

A Technical Community for IT Professionals

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Highly Rated Users

Forum
No Posts Rated

Top 50
Given
Received

Forum Statistics

Users
Members:
1875
Members Online:
2
Guests Online:
78

Total Post History
Posts:
81446
Topics:
18714

7-Day Post History
New Posts:
0
New Topics:
0
Active Topics:
0

Our newest member
konam534As

Other

FAQ
All times are UTC [ DST ]

Google Ads

Fun with strings

Mind Boggling Puzzles, to keep that grey matter in shape...
Forum rules
Always post answers in a "Hidecode" tag, so that others have a chance to answer the question too.
Please wait...

Fun with strings

Postby Thirster42 on Wed Mar 30, 2011 6:28 pm

Where I work at we have a lot of Standard Operating Procedures (sop’s) that have to be adhered to to ensure that the proper steps are taken in every situation. An SOP number looks like the following: AB-CD 1.2.3.

The AB part is the division, the CD part is a sub-division, the 1 part is the section, the2 part is the sub-section, and the 3 is the revision. Given the following list of SOP’s, break each SOP number into Division, Sub-Division, Section, Sub-section, and Revision:

  1. DECLARE @list TABLE (SOP VARCHAR(50))
  2.  
  3. INSERT INTO @list VALUES ('AB-CD 1.2.3')
  4. INSERT INTO @list VALUES ('EF-GH 11.2.4')
  5. INSERT INTO @list VALUES ('IJ-KL 30.10.006')
  6. INSERT INTO @list VALUES ('MN-OP 5.7.012')
  7. INSERT INTO @list VALUES ('QR-ST 9.12.100')
  8.  
  9. SELECT * FROM @list


Expected output (order doesn’t matter):

  1. AB  CD  01  02  003
  2. EF  GH  11  02  004
  3. IJ  KL  30  10  006
  4. MN  OP  05  07  012
  5. QR  ST  09  12  100

Division and Subdivision will always be 2 characters, section and subsection will never exceed 99, and revisions will never exceed 999.

1 point will be given for each answer that works, 3 will be given to anything that is set-based, and 10 will be for anything creative/unique/interesting.
Ask three DBAs a question, and you’ll get four different answers.

-Brent Ozar
User avatar
Thirster42
Guru
Guru
LTD Silver - Rating: 517LTD Silver - Rating: 517LTD Silver - Rating: 517LTD Silver - Rating: 517LTD Silver - Rating: 517
LTD Silver - Rating: 517LTD Silver - Rating: 517LTD Silver - Rating: 517
 
Posts: 4646
Joined: Tue Nov 11, 2008 5:49 pm
Location: Jefferson City, Mo
Unrated

Re: Fun with strings

Postby SQLDenis on Wed Mar 30, 2011 6:57 pm

Here we go..good old parsename


Code is hidden, SHOW
User avatar
SQLDenis
LTD Admin
LTD Admin
LTD Gold - Rating: 3467LTD Gold - Rating: 3467LTD Gold - Rating: 3467LTD Gold - Rating: 3467LTD Gold - Rating: 3467
LTD Gold - Rating: 3467LTD Gold - Rating: 3467LTD Gold - Rating: 3467LTD Gold - Rating: 3467LTD Gold - Rating: 3467
LTD Gold - Rating: 3467LTD Gold - Rating: 3467LTD Gold - Rating: 3467
 
Posts: 21784
Joined: Wed Oct 10, 2007 6:43 pm
Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond

Re: Fun with strings

Postby AlexCuse on Wed Mar 30, 2011 7:05 pm

Well, you didn't specify SQL ;)

Here's some F# to load the strings into a record type with your defined structure and then write it out in the specified format.

Code is hidden, SHOW
Say what you like about the tenets of National Socialism Dude, at least it's an ethos
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Gold - Rating: 1031LTD Gold - Rating: 1031LTD Gold - Rating: 1031LTD Gold - Rating: 1031LTD Gold - Rating: 1031
LTD Gold - Rating: 1031LTD Gold - Rating: 1031LTD Gold - Rating: 1031LTD Gold - Rating: 1031LTD Gold - Rating: 1031
LTD Gold - Rating: 1031
 
Posts: 5523
Joined: Tue Oct 09, 2007 5:26 pm
Location: Pennsylvania, US

Re: Fun with strings

Postby Thirster42 on Fri Apr 01, 2011 8:55 pm

my awesome code ;)

Code is hidden, SHOW
Ask three DBAs a question, and you’ll get four different answers.

-Brent Ozar
User avatar
Thirster42
Guru
Guru
LTD Silver - Rating: 517LTD Silver - Rating: 517LTD Silver - Rating: 517LTD Silver - Rating: 517LTD Silver - Rating: 517
LTD Silver - Rating: 517LTD Silver - Rating: 517LTD Silver - Rating: 517
 
Posts: 4646
Joined: Tue Nov 11, 2008 5:49 pm
Location: Jefferson City, Mo