Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to replace the strings? Expand / Collapse
Author
Message
Posted Tuesday, September 04, 2012 5:53 AM


Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Monday, February 18, 2013 2:08 AM
Points: 672, Visits: 725
Hi Friends,

I have a column called Description which contains values like

"Qty: 1 | Desc: 1991 LOADRITE BOAT TRAILER | Value: .00 | Recovered Value: .00 | NCIC#: "
"Qty: 1 | Desc: PROTUFF FLAT TRAILER GREY IN COLOR | Value: 1500.00 | Recovered Value: .00| NCIC#: "

In here you can see values like .00 ...i want to replace those values like 0.00

This is the kinda output that i need, so please give your ideas friends...

"Qty: 1 | Desc: 1991 LOADRITE BOAT TRAILER | Value: 0.00 | Recovered Value: 0.00| NCIC#: "
"Qty: 1 | Desc: PROTUFF FLAT TRAILER GREY IN COLOR | Value: 1500.00 | Recovered Value: 0.00| NCIC#: "


Thanks,
Charmer
Post #1353834
Posted Tuesday, September 04, 2012 6:15 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 10:47 PM
Points: 2,023, Visits: 4,948
Do you always have space before the decimal point? If the answer is true you can use the replace function to replace ' .0' with ' 0.0'. Using your example the code would look like this:
select replace('"Qty: 1 | Desc: 1991 LOADRITE BOAT TRAILER | Value: .00 | Recovered Value: .00 | NCIC#: "', ' .0', ' 0.0')

select replace('"Qty: 1 | Desc: PROTUFF FLAT TRAILER GREY IN COLOR | Value: 1500.00 | Recovered Value: .00| NCIC#: "', ' .0', ' 0.0')


Adi


--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1353841
Posted Tuesday, September 04, 2012 6:25 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Today @ 5:56 AM
Points: 82, Visits: 350
If you need this added to a query where you don't always know the value, try this:

select replace(YourColumnNameHere, '.00', '0.00')

This worked when I tested it using this code:

with cteTable(TextString)
as
(
select 'Qty: 1 | Desc: 1991 LOADRITE BOAT TRAILER | Value: .00 | Recovered Value: .00 | NCIC#: '
)

select replace(TextString, '.00', '0.00') as TextString from cteTable

Mark



Post #1353845
Posted Tuesday, September 04, 2012 6:29 AM


Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Monday, February 18, 2013 2:08 AM
Points: 672, Visits: 725
Adi Cohn-120898 (9/4/2012)
Do you always have space before the decimal point? If the answer is true you can use the replace function to replace ' .0' with ' 0.0'. Using your example the code would look like this:
select replace('"Qty: 1 | Desc: 1991 LOADRITE BOAT TRAILER | Value: .00 | Recovered Value: .00 | NCIC#: "', ' .0', ' 0.0')

select replace('"Qty: 1 | Desc: PROTUFF FLAT TRAILER GREY IN COLOR | Value: 1500.00 | Recovered Value: .00| NCIC#: "', ' .0', ' 0.0')


Adi


Yes Adi, there is always a space between the decimals...


Thanks,
Charmer
Post #1353847
Posted Tuesday, September 04, 2012 6:33 AM


Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Monday, February 18, 2013 2:08 AM
Points: 672, Visits: 725
Mark Eckeard (9/4/2012)
If you need this added to a query where you don't always know the value, try this:

select replace(YourColumnNameHere, '.00', '0.00')

This worked when I tested it using this code:

with cteTable(TextString)
as
(
select 'Qty: 1 | Desc: 1991 LOADRITE BOAT TRAILER | Value: .00 | Recovered Value: .00 | NCIC#: '
)

select replace(TextString, '.00', '0.00') as TextString from cteTable

Mark


I have already tried with this...but it did not work for me...I don't know why....it seems we need to leave a space before decimal point like Adi said...Since the column always has space in front of decimal point....


Thanks,
Charmer
Post #1353850
Posted Tuesday, September 04, 2012 8:43 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Today @ 12:25 PM
Points: 8,973, Visits: 8,532
Charmer (9/4/2012)
Mark Eckeard (9/4/2012)
If you need this added to a query where you don't always know the value, try this:

select replace(YourColumnNameHere, '.00', '0.00')

This worked when I tested it using this code:

with cteTable(TextString)
as
(
select 'Qty: 1 | Desc: 1991 LOADRITE BOAT TRAILER | Value: .00 | Recovered Value: .00 | NCIC#: '
)

select replace(TextString, '.00', '0.00') as TextString from cteTable

Mark


I have already tried with this...but it did not work for me...I don't know why....it seems we need to leave a space before decimal point like Adi said...Since the column always has space in front of decimal point....


You have been around here long enough to know that this doesn't help. What do you mean it doesn't work? Unexpected results? Syntax error? How about you toss up some details and we can help.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Post #1353948
Posted Wednesday, September 05, 2012 2:54 AM


Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Monday, February 18, 2013 2:08 AM
Points: 672, Visits: 725
Sean Lange (9/4/2012)
Charmer (9/4/2012)
Mark Eckeard (9/4/2012)
If you need this added to a query where you don't always know the value, try this:

select replace(YourColumnNameHere, '.00', '0.00')

This worked when I tested it using this code:

with cteTable(TextString)
as
(
select 'Qty: 1 | Desc: 1991 LOADRITE BOAT TRAILER | Value: .00 | Recovered Value: .00 | NCIC#: '
)

select replace(TextString, '.00', '0.00') as TextString from cteTable

Mark


I have already tried with this...but it did not work for me...I don't know why....it seems we need to leave a space before decimal point like Adi said...Since the column always has space in front of decimal point....


You have been around here long enough to know that this doesn't help. What do you mean it doesn't work? Unexpected results? Syntax error? How about you toss up some details and we can help.



Sorry Sean....The issue has been fixed. Adi's idea worked for me...


Thanks,
Charmer
Post #1354386
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse