?
Solved

remove special character from column

Posted on 2013-12-06
7
Medium Priority
?
608 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 15

Accepted Solution

by:
David L. Hansen earned 1200 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 70

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 400 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 400 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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

718 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