April 29, 2008 at 11:49 am
HI All,
I had this question asked to me today and still working on it.
If you have a table, with one col called RefNum
How do you return the the following:
Refnum
,(First non-numeric character in Refnum)
Ideally I'd like some set based code on this instead of some hectic loops etc.
Thanks
Chris
----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley
:w00t:
Posting Best Practices[/url]
Numbers / Tally Tables[/url]
April 29, 2008 at 11:56 am
Assuming you mean "not 0 through 9" when you say non-numeric (i.e. not trying to figure out decimal points, signs, etc...), then
substring(refnum,patindex('%[^1-9]%',Refnum),1)
should do the trick.
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
April 29, 2008 at 9:29 pm
Matt... shouldn't that be 0-9?
--Jeff Moden
Change is inevitable... Change for the better is not.
April 29, 2008 at 9:30 pm
Jeff Moden (4/29/2008)
Matt... shouldn't that be 0-9?
I knew there was something missing there......:blush:
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
April 30, 2008 at 3:22 am
Hi Stobbs,
Try this one.
DECLARE @refnum VARCHAR(128)
SET @refnum = '2143345345345345345345345342100712n3456789090987766544332211m'
SELECT SUBSTRING(@refnum,PATINDEX('%[a-z]%',@refnum),1)
---:)
April 30, 2008 at 4:17 am
hi Guys,
Thanks all for the reply 🙂
I feel like an idiot, I totally forgot about the PatIndex function he he he
Thanks again
Chris
----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley
:w00t:
Posting Best Practices[/url]
Numbers / Tally Tables[/url]
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply