Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 28th, 2006, 11:52 PM
Registered User
 
Join Date: Nov 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to maulik77 Send a message via Yahoo to maulik77
Default Fulltext Search Stored Procedure.

CREATE PROCEDURE freetext_rank_proc
(
    @select_list nvarchar(1000), -- Desire field e.g. "ID,sSubject,KEY_TBL.RANK"
    @from_table nvarchar(517), -- Table name e.g. "tbl_Content"
    @freetext_column sysname, -- Column name e.g. "sBody"
    @freetext_search nvarchar(1000), -- Search text
    @additional_predicates nvarchar(500) = '', -- Additional if any e.g. "KEY_TBL.RANK >= 10"
    @order_by_list nvarchar(500) = '' -- Orderby List e.g. "KEY_TBL.RANK DESC"
)
AS
BEGIN
    DECLARE @table_id integer,
        @unique_key_col_name sysname,
        @add_pred_var nvarchar(510),
        @order_by_var nvarchar(510)
    -- Get the name of the unique key column for this table.
    SET @table_id = Object_Id(@from_table)
    SET @unique_key_col_name =
    Col_Name( @table_id, ObjectProperty(@table_id, 'TableFullTextKeyColumn') )

    -- If there is an additional_predicate, put AND() around it.
    IF @additional_predicates <> ''
        SET @add_pred_var = 'AND (' + @additional_predicates + ')'
    ELSE
        SET @add_pred_var = ''

    -- Insert ORDER BY, if needed.
    IF @order_by_list <> ''
        SET @order_by_var = 'ORDER BY ' + @order_by_list
    ELSE
        SET @order_by_var = ''

    -- Execute the SELECT statement.

--print 'SELECT ' + @select_list + ' FROM ' + @from_table + ' AS FT_TBL, FreetextTable(' + @from_table + ',' + @freetext_column + ',''' + @freetext_search + ''') AS KEY_TBL ' + 'WHERE FT_TBL.' + @unique_key_col_name + ' = KEY_TBL.[KEY] ' + @add_pred_var + ' ' + @order_by_var

    EXECUTE ( 'SELECT '
    + @select_list
    + ' FROM '
    + @from_table
    + ' AS FT_TBL, FreetextTable('
    + @from_table
    + ','
    + @freetext_column
    + ','''
    + @freetext_search
    + ''') AS KEY_TBL '
    + 'WHERE FT_TBL.'
    + @unique_key_col_name
    + ' = KEY_TBL.[KEY] '
    + @add_pred_var
    + ' '
    + @order_by_var
    )
END



GO


Cheer!

Maulik Pandya





Similar Threads
Thread Thread Starter Forum Replies Last Post
Bugbase Search Stored Procedure johncross912 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 5 August 22nd, 2007 12:51 AM
Stored Procedure Help BukovanJ SQL Language 2 October 10th, 2006 08:02 AM
advance search with stored procedure harpua Classic ASP Databases 1 December 29th, 2004 04:02 AM
stored procedure kvanchi ADO.NET 1 December 9th, 2004 07:27 AM
Stored Procedure... babloo81 SQL Server 2000 2 May 1st, 2004 11:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.