December 10, 2008 at 10:33 am
How do i select numeric values up to the first non-numeric char from a table column that contains alpha numeric strings? For example;
24K-20k to return 24
200-300 to return 200
5k to return 5 etc.
Thanks
December 10, 2008 at 3:28 pm
I would suggest looking into Regular expressions. I am not proficient in how to use them but I'm sure it will be able to do what you're looking for.
December 10, 2008 at 8:38 pm
I don't know how you'd do it in SSIS, but here's the T-SQL solution...
--===== Create a place to hold test data and populate it.
-- Note that this is NOT part of the solution.
DECLARE @DemoTable TABLE (Original VARCHAR(10))
INSERT INTO @DemoTable
SELECT '24K-20k' UNION ALL
SELECT '200-300' UNION ALL
SELECT '5k'
--===== Solve the problem
SELECT Original,
LEFT(Original, PATINDEX('%[^0-9]%',Original)-1) AS FirstNumeric
FROM @DemoTable
--Jeff Moden
Change is inevitable... Change for the better is not.
December 10, 2008 at 8:55 pm
Heh... I hate it when impatient people pull this crap... this is a double post... please, no more answers on this thread... go to the following, instead...
http://www.sqlservercentral.com/Forums/Post.aspx?SessionID=gjq2tn3letp4qj554vsxeizy
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply