SQL Server 2005: How do i get the value from a field till i reach a particular string like <style>?

Posted on 2008-10-10
Last Modified: 2012-05-05
i would like to retreive part of a string which is in a column of data type ntext. The column has a lot of html. I would like to retrieve the part till i reach '<style>'.

Everything  before '<style>' should be retrieved.

Please suggest with syntax.

Question by:nirisan

Expert Comment

ID: 22692202
substring(column, 0, charindex(column, '<style>'))

or something similar to this

Accepted Solution

varungd earned 500 total points
ID: 22692616
select substring(columnName, 0, charindex('<style>', columnName))from tablename

Expert Comment

ID: 22693351
You can use
select substring(columnname,0,charindex('<script>',columnname)) from tablename.

But it will return null if the the column doesnot contain '<script'>. If u want those result to u can use the following code
select case substring(columnname,0,charindex('<script>',columnname))
when '' then columnname
else substring(columnname,0,charindex('<script>',columnname)) end
 from tablename

Author Comment

ID: 22727356

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

19 Experts available now in Live!

Get 1:1 Help Now