Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12345»»»

Multipe letters into one Expand / Collapse
Author
Message
Posted Monday, October 1, 2012 11:21 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, July 30, 2014 8:23 AM
Points: 2,025, Visits: 2,521
All,

I have read and asked lot of questionss about "Multiple space into one" here. I just thought the below scenario which came suddenly in my mind.

Incase if the user entered wrongly or if the file contain wrong data as below

kaarthi
jefff moden
steevve
gillla
barrry youuung
mattt milller
Joeee celkko
lowweel
maaark
biiit buucket
graant fritchey
phhhill factor
ChriiisM

We all know their names. :)


Expected Output:

karthi
jef moden
steve
gila
rbary young
mat miler
Joe celko
lowel
mark
bit bucket
grant fritchey
phil factor
ChrisM

For no, I just removed all the multiple letters into one. But this may also cause some issue if some one has really two letters in their name.
I think we have to handle this one too.







karthik
Post #1366675
Posted Monday, October 1, 2012 11:39 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 10:11 AM
Points: 36,995, Visits: 31,516
Actually, I don't recommend handling this at all. It will break properly spelled names.

--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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1366681
Posted Monday, October 1, 2012 1:01 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 1:54 PM
Points: 1,081, Visits: 6,527
Jeff Moden (10/1/2012)
Actually, I don't recommend handling this at all. It will break properly spelled names.


+1



Low-hanging fruit picker and defender of the moggies





For better assistance in answering your questions, please read this.




Understanding and using APPLY, (I) and (II) Paul White

Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Post #1366712
Posted Monday, October 1, 2012 3:31 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, December 4, 2013 1:49 PM
Points: 1,104, Visits: 1,174
Jeff Moden (10/1/2012)
Actually, I don't recommend handling this at all. It will break properly spelled names.

+1

Just because you can do something doesn't mean you should. Doing this sort of data validation within the database will only result in a mess. Even if you have a valid list of names to check against and write the code to "figure out" what they really meant, the chance would remain that two distinct names could be identical after all duplicate letters are removed.

Furthermore, it's not a good architectural philosophy. The application that is the transit between the human who can't spell and the database is the appropriate location for the validation. That is where the 'did you really mean X?' conversation can reliably occur. It is then the database's job to store that data and retrieve it on demand.


└> bt


Forum Etiquette: How to post data/code on a forum to get the best help
Post #1366794
Posted Monday, October 1, 2012 3:33 PM
UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Wednesday, August 13, 2014 12:03 PM
Points: 1,480, Visits: 1,028
+1
GIGO
Post #1366795
Posted Tuesday, October 2, 2012 2:02 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, July 18, 2014 9:09 AM
Points: 870, Visits: 2,385
While I agree its not a practical solution, as there are names (Yvonne, Pattinson, Lee, off the top of my head) where consecutive characters can be the same and so you will be destroying potentially valid names

However, I can see its use as a test question in a technical interview for an SQL developer just to see how they think and solve a complex SQL problem.


_________________________________________________________________________
SSC Guide to Posting and Best Practices
Post #1366889
Posted Tuesday, October 2, 2012 6:59 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 10:11 AM
Points: 36,995, Visits: 31,516
Jason-299789 (10/2/2012)
While I agree its not a practical solution, as there are names (Yvonne, Pattinson, Lee, off the top of my head) where consecutive characters can be the same and so you will be destroying potentially valid names

However, I can see its use as a test question in a technical interview for an SQL developer just to see how they think and solve a complex SQL problem.


I try not to ask "oolies" during an interview. Asking improbable questions just ticks off the good ones and makes them think the interviewer is just showing off. Ask practical questions. There are plenty of them.

If you want to break the ice on "the next level" of T-SQL programming, explain how important counting is in T-SQL and then ask them to write a script that will count from 1 to 100. You'll be amazed at how many people still resort to a While Loop or a (gasp!) Recursive CTE.


--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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1367005
Posted Tuesday, October 2, 2012 7:20 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, July 18, 2014 9:09 AM
Points: 870, Visits: 2,385
As always a Fair point Jeff.

_________________________________________________________________________
SSC Guide to Posting and Best Practices
Post #1367022
Posted Tuesday, October 2, 2012 10:07 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, July 30, 2014 8:23 AM
Points: 2,025, Visits: 2,521
I do agree all your points. I just thought this one while reading/replying to my another post. As all of you mentioned, it will break the original name into some useless one. I wanted to know the different opinion on this topic from the sql masters. Thats all the intention :)

Jeff,

Coming back to your question, count 1 to 100,

select sum(n) from tally where n < 101

am i right :)


karthik
Post #1367391
Posted Tuesday, October 2, 2012 11:09 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: 2 days ago @ 8:30 PM
Points: 3,627, Visits: 5,273
karthik M (10/2/2012)


Jeff,

Coming back to your question, count 1 to 100,

select sum(n) from tally where n < 101

am i right :)


How about:

 SELECT 50*101 

instead?

Seriously, I don't think that was the answer to Jeff's question, but if it was mine's probably faster.



My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

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?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
Post #1367405
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse