Link to home
Start Free TrialLog in
Avatar of nirisan
nirisan

asked on

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

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.

Avatar of 3abqari
3abqari

substring(column, 0, charindex(column, '<style>'))

or something similar to this
ASKER CERTIFIED SOLUTION
Avatar of varungd
varungd

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of nirisan

ASKER

perfect