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

x
?
Solved

Search for a decimal and then remove it from string

Posted on 2012-04-06
3
Medium Priority
?
523 Views
Last Modified: 2012-04-13
Hello,
I need a T-SQL Statement to search a string variable for a decimal and
then remove it.

@string = '1234.5'

I want @string to equal '12345'

If I do it this way:
Set @string = replace(@string, '.', '')

I would assume it would remove the decimal in the string.

What if @string = '12345', with no decimal?

Would it not work and set @string = NULL, due to not finding a decimal within the
replace statement?

Thanks.
0
Comment
Question by:Machinegunner
[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 3

Accepted Solution

by:
Chris__W earned 1000 total points
ID: 37817743
Hello,

No, it will work as you listed and will NOT nullify the string just because the searched for item is not there.

If @string is null it can still cause other issues, so if you haven't already accounted for that elsewhere here's the line:

Set @string = ISNULL(replace(@string, '.', ''),'');

Thanks,
Chris
0
 
LVL 43

Assisted Solution

by:Eugene Z
Eugene Z earned 1000 total points
ID: 37821212
<What if @string = '12345', with no decimal?>
it will keep the same number: if it has something replace - it will replace

<Would it not work and set @string = NULL, due to not finding a decimal within the
replace statement?>
No, unless you wish -- it is extra code
0
 

Author Closing Comment

by:Machinegunner
ID: 37844031
thanks for the information and decided to leave it as it is and it took out the decimal, as stated, thanks
0

Featured Post

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

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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 extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

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