Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql query to remove prefix from field

Tags:

sql

sql-server

Given the following

Products_Joined.ProductName AS [stripHTML-TITLE],

How would I remove the first 5 characters when the field contain any of the following. Basically I want to strip out the characters between < and > and including <> as well. The returned field's length can vary.

<!01>AMSSSS
<!02>SSS
<!03>CMSS
<!04>DMSS
<!05>EMSDDDDD etc...

This gives me just the first characters after the > but I don't know how to get all characters after >

SUBSTRING(Products_Joined.ProductName, 6,1) AS [stripHTML-TITLE],

Was going to use Replace function for all the possible prefixes but that can get rather messy.

like image 634
user357034 Avatar asked Apr 24 '26 18:04

user357034


2 Answers

SUBSTRING(Products_Joined.ProductName, 6,LEN(Products_Joined.ProductName)) 
like image 130
Stuart Ainsworth Avatar answered Apr 27 '26 08:04

Stuart Ainsworth


You can use STUFF.

select stuff('<!01>AMSSSS', 1, 5, '')

http://msdn.microsoft.com/en-us/library/ms188043.aspx

like image 25
Mikael Eriksson Avatar answered Apr 27 '26 06:04

Mikael Eriksson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!