Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 T-SQL LIKE keyword problem

Author  Topic 

sinbad
Starting Member

1 Post

Posted - 2011-01-31 : 04:04:51
If there is at least one "insert" that is not followed by a "#" it must be selected or if there is at least one "insert into" not followed by a "#", it must be selected.

Due to the use of an older version of Sybase, I cannot use SIMLAR TO or REGEX or REGEXP. I can only use LIKE.

I tried:

WHERE text LIKE '%insert%' AND NOT LIKE '%insert into #%' AND NOT LIKE '%insert #%'


But what if I have "insert into tablename insert #". This will do the wrong thing by not selecting the text.

I tried:

WHERE text LIKE '%insert [^#(into)]%' OR text LIKE '%insert into [^#]%'


This also does not work.

Some examples for clarification:

I must select:
insert tablename insert # insert into #
insert # insert tablename insert #
insert # insert into # insert tablename
insert into tablename insert into #
insert into tablename insert tablename insert into #
insert # insert into # insert into tablename insert tablename

I must not select:
insert #
insert # insert into #
insert into #
insert # insert #

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-01-31 : 06:46:52
WHERE REPLACE(REPLACE(text,'insert #',''),'insert into #','') LIKE '%insert %'


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -