?
Solved

IF Statement then remove first 4 characters

Posted on 2013-11-07
2
Medium Priority
?
198 Views
Last Modified: 2013-11-08
I have a description field that has  the following:

<!A>Description of Product
<!B>Description of Next Product
DSC-Free Shipping
<!C>Description of Third Product

I'm wanting to put in a formula where if the description field contains "<" then I want to trim the first 4 characters. If there is no "<" at the beginning then do nothing. So in essence I want to just remove the "<!A>","<!B>","<!C>"
0
Comment
Question by:Southern_Gentleman
2 Comments
 
LVL 23

Assisted Solution

by:Steve Wales
Steve Wales earned 800 total points
ID: 39632694
Something like this:

select case 
         when substring(COL1,1,1) = '<' then substring(col1,5,len(col1)-4)
         else col1
       end
from
(select '<!A>Line 1' as COL1
union 
select 'Line 2'
union
select '<!B>Line 3') as a

Open in new window


Returns this:

Line 1
Line 2
Line 3
0
 
LVL 32

Accepted Solution

by:
awking00 earned 1200 total points
ID: 39633277
select case when charindex('<',description) = 1 then right(description, len(description) - 4) else description end as description
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

840 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