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 ««12

Stripping out all non-numerical characters Expand / Collapse
Author
Message
Posted Thursday, January 3, 2013 4:05 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, February 20, 2014 3:23 AM
Points: 50, Visits: 126
I have no experience in CRL, so would like T-SQL for now please?
the answer to the second question is yes.
Post #1402280
Posted Friday, January 4, 2013 10:03 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, November 13, 2014 10:04 AM
Points: 141, Visits: 641
@GSquared:

Sorry to be thick-headed (read: slow-witted) but I have to ask: why did you SELECT TOP (8000) ROW_NUMBER... when it [seems] to work with TOP (10). Since we're using only the numbers 0-9, I would have figured using a generic "number generator" like SELECTING ROW_NUMBER() ... from a "known" source that would have at least 10 records (like sys.objects), you could skinny down the code and maybe processing as well:

DECLARE @String VARCHAR(8000) = 'ABC12D34E56';

SELECT (
SELECT SUBSTRING(@String, n.[Number], 1)
FROM (
SELECT TOP (10) ROW_NUMBER()
OVER (ORDER BY [object_id]) AS [Number]
FROM sys.objects) n
WHERE n.[Number] <= LEN(@String)
AND SUBSTRING(@String, n.[Number], 1) LIKE '[0-9]'
ORDER BY n.[Number]
FOR XML PATH(''), TYPE).[value]('.[1]', 'VARCHAR(8000)');

Factoring in inflation, health care, taxes and cost of living, my two cents isn't worth much so I apologize if I missed something. I'll blame the lack of coffee for any oversight on my part.

Cheers,
Ken
Post #1402976
Posted Friday, January 4, 2013 10:58 AM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Today @ 7:29 AM
Points: 35,554, Visits: 32,150
Your Name Here (1/4/2013)
@GSquared:

Sorry to be thick-headed (read: slow-witted) but I have to ask: why did you SELECT TOP (8000) ROW_NUMBER... when it [seems] to work with TOP (10). Since we're using only the numbers 0-9, I would have figured using a generic "number generator" like SELECTING ROW_NUMBER() ... from a "known" source that would have at least 10 records (like sys.objects), you could skinny down the code and maybe processing as well:

DECLARE @String VARCHAR(8000) = 'ABC12D34E56';

SELECT (
SELECT SUBSTRING(@String, n.[Number], 1)
FROM (
SELECT TOP (10) ROW_NUMBER()
OVER (ORDER BY [object_id]) AS [Number]
FROM sys.objects) n
WHERE n.[Number] <= LEN(@String)
AND SUBSTRING(@String, n.[Number], 1) LIKE '[0-9]'
ORDER BY n.[Number]
FOR XML PATH(''), TYPE).[value]('.[1]', 'VARCHAR(8000)');

Factoring in inflation, health care, taxes and cost of living, my two cents isn't worth much so I apologize if I missed something. I'll blame the lack of coffee for any oversight on my part.

Cheers,
Ken


Try it on a much larger string and see why the 8000 becomes important.


--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 #1403021
Posted Friday, January 4, 2013 11:45 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, November 13, 2014 10:04 AM
Points: 141, Visits: 641


I get it now. Thanks!
Post #1403040
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse