Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Other Technologies / Full-Text Search / March 2005

Tip: Looking for answers? Try searching our database.

NOT CONTAINS and LEFT OUTER JOIN

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mal - 16 Mar 2005 18:15 GMT
Hi Guys

SQL Server 2000 SP3
(WIN NT/2000/XP)

Can somebody please explain how I can overcome the
following (what looks to be) limitation in SQL Server's
FullText capabilities?

Consider the following query (table defs at bottom of
post):

select *
from a
left outer join b on b.b_id = a.b_id

Which returns:

a_id b_id b_id foo
---- ---- ---- ---
1    NULL NULL NULL
2    1    1    bar

Now, the column foo in table b is fulltext indexed.
So, the following query returns the following, correct
results:

select *
from a
left outer join b on b.b_id = a.b_id
where contains(b.*, '"bar"')

a_id b_id b_id foo
2    1    1    bar

However, if I want to return all of the rows that do not
contain the word "bar", I would execute the following:

select *
from a
left outer join b on b.b_id = a.b_id
where not contains(b.*, '"bar"')

But, this query does not return *any* rows. I was
expecting to see:

a_id b_id b_id foo
---- ---- ---- ---
1    NULL NULL NULL

It is as if my query has become an INNER JOIN, i.e. it
yields the same results as:

select *
from a
inner join b on b.b_id = a.b_id
where not contains(b.*, '"bar"')

...which I would expect.

Oddly, SET ANSI_NULLS OFF fixes the problem - but I
cannot see why this relates to CONTAINS searching and
besides. SET ANSI_NULLS OFF is definitely *not* an option
for me.

My questions are:

1. Is this the expected behaviour?
2. Is this a common problem?
3. What can I do to "fix" the problem?

Incidentally, executing the same NOT CONTAINS query in
SQL Server 2005 BETA2 does *not* exhibit the problem,
i.e. it works as we would like it to.

Many Thanks in advance.

create table a(a_id int not null constraint pk_a primary
key, b_id int)
insert into a values(1, null)
insert into a values(2, 1)

create table b(b_id int not null constraint pk_b primary
key, foo varchar(100))
insert into b values(1, 'bar')

sp_fulltext_catalog 'test', 'create'
sp_fulltext_table 'b', 'create', 'test', 'pk_b'
sp_fulltext_column 'b', 'foo', 'add'
sp_fulltext_table 'b', 'activate'
sp_fulltext_table 'b', 'start_full'
Hilary Cotter - 21 Mar 2005 16:59 GMT
setting ANSI nulls off has the effect of making a null=null.

set ansi_nulls off
declare @int int, @int1 int
set @int=null
set @int1=null

if @int=@int1
print 'null'
--you get null printed

set ansi_nulls on
declare @int int, @int1 int
set @int=null
set @int1=null

if @int=@int1
print 'null'
--you get nothing printed

Here is an example from the pubs database which I think illustrates how this
should work.

select * from titleauthor join
(select * from authors where not contains(*,'ringer')) as k on
k.au_id=titleauthor.au_id

Signature

Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html

Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com

> Hi Guys
>
[quoted text clipped - 87 lines]
> sp_fulltext_table 'b', 'activate'
> sp_fulltext_table 'b', 'start_full'
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.