|
-
Feb 7th, 2008, 11:58 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Replacing Left of a character
Hi,
MSSQL 2000 question:
I need an SQL statement that would take e.g. "TAG/ 123456" and delete everything left of the forward slash giving me a result of "123456". I can not give a count as there are many values that may vary.
Select Replace(partname????????) from orders
Thanks
If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.
"I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
Do illiterate people get the full effect of Alphabet Soup?
ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool
-
Feb 7th, 2008, 12:27 PM
#2
Addicted Member
Re: Replacing Left of a character
-
Feb 7th, 2008, 12:43 PM
#3
Re: Replacing Left of a character
MSSQL has a Right() function you could use.
It goes as follows: RIGHT ( character_expression , integer_expression )
So something like right(TAG/123456, 6) would work.
Again, depending on which language you're using, you could use a function to get the location of the /, and use the right function to grab anything before that character.
Or you could use a split function to split on "/" and grab the second index.
-
Feb 7th, 2008, 01:43 PM
#4
Thread Starter
Hyperactive Member
Re: Replacing Left of a character
Like I said, I can not set a count. Too many variables in the size of the string right of the forward slash. Same goes for the left side also.
If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.
"I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
Do illiterate people get the full effect of Alphabet Soup?
ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool
-
Feb 7th, 2008, 01:59 PM
#5
Re: Replacing Left of a character
Execute this code in the database you are using. It will create a function that will remove everything from the string except numbers.
sql Code:
CREATE FUNCTION [dbo].[fn_GetNumbers](@Str NVARCHAR(MAX))
RETURNS NVARCHAR(MAX)
AS
BEGIN
-- SELECT dbo.fn_GetNumbers('testing.\.234...77..116/ghj (&(*&()((')
DECLARE @RetVal NVARCHAR(MAX)
DECLARE @I INT
SET @RetVal = @Str
SET @I = 1
WHILE @I <= LEN(@RetVal) BEGIN
IF CHARINDEX(SUBSTRING(@RetVal, @I, 1), '0123456789') = 0 BEGIN
SET @RetVal = REPLACE(@RetVal, SUBSTRING(@RetVal, @I, 1), '')
SET @I = @I - 1
END
SET @I = @I +1
END
RETURN @RetVal
END
-
Feb 7th, 2008, 02:17 PM
#6
Thread Starter
Hyperactive Member
Re: Replacing Left of a character
I need everything to the left of the forward slash and the slash it self. I will not rule out the the string may be TAG/ 123AB23 or TAG/ WE4051 or AB422/ 1234567890
If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.
"I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
Do illiterate people get the full effect of Alphabet Soup?
ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool
-
Feb 7th, 2008, 02:45 PM
#7
Re: Replacing Left of a character
You are contradicting yourself, in the first post you said you need the numbers, now you say you want everything to the left of slash....
But I think you mean everything AFTER the slash ? right ?
Something like this maybe ?
sql Code:
SELECT LTRIM(SUBSTRING('AB422/ 1234567890', CHARINDEX('/', 'AB422/ 1234567890') + 1, 1000))
-
Feb 7th, 2008, 03:17 PM
#8
Thread Starter
Hyperactive Member
Re: Replacing Left of a character
That it!!!!!
Thank you!!!!
If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.
"I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
Do illiterate people get the full effect of Alphabet Soup?
ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|