Solved

IF Statement then remove first 4 characters

Posted on 2013-11-07
2
187 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 22

Assisted Solution

by:Steve Wales
Steve Wales earned 200 total points
Comment Utility
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 31

Accepted Solution

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

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
C# SQL BULK INSERT CLASS 5 33
How to query date ranges with SQL 6 22
Complex SQL 10 32
SQL Transaction logs 8 6
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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
Via a live example, show how to shrink a transaction log file down to a reasonable size.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now