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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Full text indexing - Too many CONTAINs?

Author  Topic 

MaverickUK
Yak Posting Veteran

89 Posts

Posted - 2005-08-03 : 08:54:13
Greetings all

I am attempting to search a full text indexes table, with optional search fields. However my query doesn't appear to be working.

I'm searching an address database, which has the house number, street name and postcode queried. I want any of these fields to be searched, but they are all optional.
So the postcode can be searched, without specifying a house number or street name.

The following is my current SQL


CREATE PROCEDURE sppb_AddressPoint_AddressCompletion

@HouseNumber VARCHAR( 50 ),
@StreetName VARCHAR( 150 ),
@Postcode VARCHAR( 8 )

/****************************************************************************************
16 September 2004 - Created - Peter Bridger
Complete an address, based on the data passed in
***************************************************************************************/

AS

SET NOCOUNT ON

SELECT TOP 50 -- Only retrieve top 50 records
X,
Y,
ORGANISATION_NAME 'OrganisationName',
BUILD_NUMBER 'HouseNumber',
THOROUGHFARE_NAME 'StreetName',
PostTown_Name 'PostTown',
DDEP,
Postcode 'Postcode'
FROM
AddressPoint
WHERE
( -- Postcode
LEN( @PostCode ) = 0
OR
CONTAINS
( Postcode, @Postcode )
)
AND
( -- Building number
LEN( @HouseNumber ) = 0
OR
CONTAINS
( BUILD_NUMBER, @HouseNumber )

)
AND
( -- Street name
LEN( @StreetName ) = 0
OR
CONTAINS
( THOROUGHFARE_NAME, @StreetName )
)



I thought my use of
LEN( @StreetName ) = 0 
would mean that if an empty parameter was passed in, a search wouldn't be performed. But when I do a search with optional parameters, it seems to just hang.

What am I doing wrong?

MaverickUK
Yak Posting Veteran

89 Posts

Posted - 2005-08-04 : 05:03:37
Does nobody see what I'm doing wrong here?

If I'm doing something stupid, please point it out.
Go to Top of Page
   

- Advertisement -