March 29, 2011 at 5:45 pm
A quick and dirty solution is to do this:
RIGHT( REVERSE( cola), CHARINDEX( '-', REVERSE( cola) ) - 1 )
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
March 29, 2011 at 5:53 pm
Maybe I should have been more specific or more detailed. Thanks for the reply though.
This is what worked and returned me what I needed.
select code,
(substring(code,
charindex('-',Code)+1 ,
len(Code)))
from accountmain
Data returned is:
code (No column name)
10001-1001010010
10001-2000120001
10001-2000720007
10001-2010420104
March 29, 2011 at 6:10 pm
tschuler-738392 (3/29/2011)
Maybe I should have been more specific or more detailed. Thanks for the reply though.This is what worked and returned me what I needed.
Nah, no test data so I offered an idea off the cuff. This is what I meant (I had an extra reverse):
IF OBJECT_ID('tempdb..#tmp') IS NOT NULL
DROP TABLE #tmp
CREATE TABLE #tmp (sometext VARCHAR(30))
INSERT INTO #tmp
SELECT '10001asd-10010' UNION ALL
SELECT '10001-20001dfs' UNION ALL
SELECT '10001-adsfa20007' UNION ALL
SELECT '10001-104'
SELECT
RIGHT( sometext, CHARINDEX( '-', REVERSE( sometext))-1)
FROM
#tmp
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
March 29, 2011 at 6:58 pm
Thank you.
Viewing 4 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply