Solved

remove special character from column

Posted on 2013-12-06
7
606 Views
Last Modified: 2013-12-27
I have a question.

There is a column named: Shipping Time, and it has a data type of varchar(32)
but when I run a select to see the values of this column, I see that the value is stored as:

sshot

I would like to learn if possible through asking this question,  how to convert, or replace that special character that I have not seen before.

For your help, thank you very much.
0
Comment
Question by:metropia
[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
7 Comments
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 39701238
Will the returned good characters always be a single digit or could they be larger integers?
0
 

Author Comment

by:metropia
ID: 39701285
the largest number would not pass the two digits
0
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 39701297
The the largest possible value would be 9?
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 15

Accepted Solution

by:
David L. Hansen earned 300 total points
ID: 39701310
If so,
SUBSTRING(colName, 1, 1)
will do the job.
0
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 39706203
Did that work?
0
 
LVL 69

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 100 total points
ID: 39706520
To be safe, I suggest keeping all valid leading digits, and removing all characters after the last valid digit:


UPDATE dbo.tablename
SET [Shipping Time] = SUBSTRING([Shipping Time], PATINDEX('%[^0-9]%', [Shipping Time]) - 1, 100)
WHERE
    [Shipping Time] LIKE '%[^0-9]%'
0
 
LVL 5

Assisted Solution

by:rk_india1
rk_india1 earned 100 total points
ID: 39706713
If you have multiple special character the use the following

Using a series of REPLACE() functions

Here each REPLACE is used to change one unwanted character to a blank space or SPACE(0). The nesting of REPLACE function in recent version of the SQL Server product can go to hundreds of levels.

SELECT REPLACE( REPLACE( REPLACE( REPLACE( @str, '!', '' ), '#', '' ), '$', '' ), '&', '' );

If you have single special character the use the following

Using a REPLACE() function

Here each REPLACE is used to change one unwanted character to a blank space or SPACE(0). The nesting of REPLACE function in recent version of the SQL Server product can go to hundreds of levels.

SELECT REPLACE(@str, '#', '' )
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

617 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