August 30, 2017 at 4:05 am
Hi,
I have got a number of records that begin with 044, I need to replace that with 0. I am using this replace(cli,'044','0'), however some records are 044123044 and so it replaces the end of the record with 0 also. How can I get it to just replace the first three characters.
I've tried using a left function but that just updates all the records to 0.
Thanks,
Gwyn
August 30, 2017 at 4:24 am
Something like this will do
select '044123044' as OrginialValue, STUFF('044123044', 1,3,'0') as AdjustedValue
August 30, 2017 at 4:38 am
twin.devil - Wednesday, August 30, 2017 4:24 AMSomething like this will do
select '044123044' as OrginialValue, STUFF('044123044', 1,3,'0') as AdjustedValue
with a WHERE clause, of course.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
August 30, 2017 at 4:43 am
ChrisM@Work - Wednesday, August 30, 2017 4:38 AMtwin.devil - Wednesday, August 30, 2017 4:24 AMSomething like this will do
select '044123044' as OrginialValue, STUFF('044123044', 1,3,'0') as AdjustedValuewith a WHERE clause, of course.
Of course If there would a table, not for static values
August 30, 2017 at 4:45 am
Brilliant - I've never heard of STUFF before!
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply