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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

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 am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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

12 Experts available now in Live!

Get 1:1 Help Now