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.
Everything before '<style>' should be retrieved.
Please suggest with syntax.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can use
select substring(columnname,0,cha rindex('<s cript>',co lumnname)) 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,cha rindex('<s cript>',co lumnname))
when '' then columnname
else substring(columnname,0,cha rindex('<s cript>',co lumnname)) end
from tablename
select substring(columnname,0,cha
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,cha
when '' then columnname
else substring(columnname,0,cha
from tablename
ASKER
perfect
or something similar to this