|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
search in only non tagged wordsI want to search from table for rows where value should be part of text , but search should omit values from tag. like create table #t (data varchar(8000)) insert into #t values('<div> this is a div text </div>') insert into #t values('<div> this is a text </div>') insert into #t values('<div> this is < div </div>') now when i search for 'div' it should omit the words in tag < ...> and search in non tag words only so for query select * from #t where data like '%div%' so result should be <div> this is a div text </div> <div> this is < div </div> because here div is also out of tags<....> but result should not be <div> this is a text </div> because here div is only in tags<...> Try this:
select * from #t where data like '%[^<]%div%[^>]%' Let me know how you get on. Damien Show quote "shahdha***@gmail.com" wrote: > Hi > > I want to search from table for rows where value should be part of > text , but search should omit values from tag. > > like > create table #t (data varchar(8000)) > > insert into #t values('<div> this is a div text </div>') > insert into #t values('<div> this is a text </div>') > insert into #t values('<div> this is < div </div>') > > now when i search for 'div' it should omit the words in tag < ...> and > search in non tag words only > > so for query > > select * from #t where data like '%div%' > > so result should be > > <div> this is a div text </div> > <div> this is < div </div> > > because here div is also out of tags<....> > > but result should not be > > <div> this is a text </div> > > because here div is only in tags<...> > > Damien wrote:
Show quote > Try this: your query returns also rows> > select * from #t where data like '%[^<]%div%[^>]%' > > > Let me know how you get on. > > Damien > > "shahdha***@gmail.com" wrote: > > > Hi > > > > I want to search from table for rows where value should be part of > > text , but search should omit values from tag. > > > > like > > create table #t (data varchar(8000)) > > > > insert into #t values('<div> this is a div text </div>') > > insert into #t values('<div> this is a text </div>') > > insert into #t values('<div> this is < div </div>') > > > > now when i search for 'div' it should omit the words in tag < ...> and > > search in non tag words only > > > > so for query > > > > select * from #t where data like '%div%' > > > > so result should be > > > > <div> this is a div text </div> > > <div> this is < div </div> > > > > because here div is also out of tags<....> > > > > but result should not be > > > > <div> this is a text </div> > > > > because here div is only in tags<...> > > > > like <abc div> this is </abc> or <abc div dev> this is </abc> this should not be return for div. On 23 Jun 2006 05:26:51 -0700, shahdha***@gmail.com wrote:
Show quote >Hi Hi shahdharti,> >I want to search from table for rows where value should be part of >text , but search should omit values from tag. > >like >create table #t (data varchar(8000)) > >insert into #t values('<div> this is a div text </div>') >insert into #t values('<div> this is a text </div>') >insert into #t values('<div> this is < div </div>') > >now when i search for 'div' it should omit the words in tag < ...> and >search in non tag words only > >so for query > >select * from #t where data like '%div%' > >so result should be > ><div> this is a div text </div> ><div> this is < div </div> > >because here div is also out of tags<....> > >but result should not be > ><div> this is a text </div> > >because here div is only in tags<...> If you're on SQL Server 2005, consider using the xml datatype and an xquery expression. Otherwise, try if this works: SELECT data FROM #t WHERE REPLACE(REPLACE(data, '</div>', ''), '<div>', '') LIKE '%div%' -- Hugo Kornelis, SQL Server MVP Hugo Kornelis wrote:
Show quote > On 23 Jun 2006 05:26:51 -0700, shahdha***@gmail.com wrote: This query also not works.> > >Hi > > > >I want to search from table for rows where value should be part of > >text , but search should omit values from tag. > > > >like > >create table #t (data varchar(8000)) > > > >insert into #t values('<div> this is a div text </div>') > >insert into #t values('<div> this is a text </div>') > >insert into #t values('<div> this is < div </div>') > > > >now when i search for 'div' it should omit the words in tag < ...> and > >search in non tag words only > > > >so for query > > > >select * from #t where data like '%div%' > > > >so result should be > > > ><div> this is a div text </div> > ><div> this is < div </div> > > > >because here div is also out of tags<....> > > > >but result should not be > > > ><div> this is a text </div> > > > >because here div is only in tags<...> > > Hi shahdharti, > > If you're on SQL Server 2005, consider using the xml datatype and an > xquery expression. > > Otherwise, try if this works: > SELECT data > FROM #t > WHERE REPLACE(REPLACE(data, '</div>', ''), '<div>', '') LIKE '%div%' > > > -- > Hugo Kornelis, SQL Server MVP Actually the string will be most possible HTML Strings. Can I use xquery for html strings? (shahdha***@gmail.com) writes:
> Actually the string will be most possible HTML Strings. Can I use Only if you can convert them to XML. Since XML is stricter than HTML> xquery for html strings? on closing tags etc, I'm skeptic that this will work out well. A better on alternative on SQL 2005 would be to write a user-defined function in C# or VB .Net that strips values of HTML tages and returns the meat so you search on that text. If you are on SQL 2000, you may be better of running it all client-side. A joker here is full-text. I don't know full-text, but maybe it has some built-in support for searching outside HTML tags. -- Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx On 24 Jun 2006 04:05:22 -0700, shahdha***@gmail.com wrote:
> Hi shahdharti,>Hugo Kornelis wrote: (snip) >> Otherwise, try if this works: >> SELECT data >> FROM #t >> WHERE REPLACE(REPLACE(data, '</div>', ''), '<div>', '') LIKE '%div%' (snip) >This query also not works. Define: not works. With the test data you supplied, the query produced the expected results. So maybe there's some extra requirement that you forgot to sppecify? -- Hugo Kornelis, SQL Server MVP |
|||||||||||||||||||||||