[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

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.

0
nirisan
Asked:
nirisan
1 Solution
 
3abqariCommented:
substring(column, 0, charindex(column, '<style>'))

or something similar to this
0
 
varungdCommented:
select substring(columnName, 0, charindex('<style>', columnName))from tablename
0
 
Saji_klmCommented:
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
 
nirisanAuthor Commented:
perfect
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now