[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

REPLACE or RTRIM to remove characters from a value

Posted on 2010-11-11
3
Medium Priority
?
344 Views
Last Modified: 2012-05-10
I have a column with a few thousand rows that all begin with some sort of name but then end with a '#' and then a 5 or 6 digit number.

my desired result is to extract only those numbers into another column.

examples:

Doe, John and Jane #123456
Royal blue restaurant, LLC #12345

0
Comment
Question by:RustyZ32
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 34113798
update urTable
set urNewColumn = RIGHT ('urColumnName', len('urColumnName')-charindex('#', 'urColumnName') )
where charindex('#', urColumnName ) > 0
0
 
LVL 11

Expert Comment

by:David Kroll
ID: 34113805
select substring(fieldname, charindex('#', fieldname', 0), len(fieldname))
0
 
LVL 18

Expert Comment

by:lludden
ID: 34113809
I use this function for stuff like that.

Then
SELECT dbo.Strpiece('Doe, John and Jane #123456','#',1)

CREATE FUNCTION [dbo].[StrPiece] (@String varchar(500), @Delimiter char, @Position int)  
RETURNS varchar(100) AS  
BEGIN
Declare @CurrentSection int
Declare @CurrentPosition int
Declare @SubString varchar(100)
Set @CurrentSection = 0
Set @CurrentPosition = 1
Set @Substring = ''
While @CurrentPosition <= Len(@String)
    Begin
      If Substring(@String,@CurrentPosition,1) = @Delimiter
            Set @CurrentSection = @CurrentSection + 1
      Else
             if @CurrentSection = @Position
                  Set @SubString = @Substring + Substring(@String, @CurrentPosition, 1)
      Set @CurrentPosition = @CurrentPosition + 1
    End

Return ( @Substring)
END
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question