Solved

remove special character from column

Posted on 2013-12-06
7
600 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
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to shrink a transaction log file down to a reasonable size.

679 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