Solved

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
4
161 Views
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.

0
Comment
Question by:nirisan
4 Comments
 
LVL 3

Expert Comment

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

or something similar to this
0
 
LVL 5

Accepted Solution

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

Expert Comment

by:Saji_klm
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
0
 

Author Comment

by:nirisan
ID: 22727356
perfect
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to enforce inte 8 59
How to import SQL 2000 database to SQL 2014 5 138
Analysis of table use 7 54
Addition to SQL for dynamic fields 6 47
This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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