Fulltext search with MS SQL

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2006
Posts: 1
Reputation: pub00515 is an unknown quantity at this point 
Solved Threads: 0
pub00515 pub00515 is offline Offline
Newbie Poster

Fulltext search with MS SQL

 
0
  #1
Aug 31st, 2006
Hello,
I am trying to implement a fulltext search on a MS SQL database. While I can query each table independently for a specific word, I didn't find a method to query the entire collection of tables for my search key. Is there a way to do this (using the fulltext catalog for example)?
Thanks!
Mark
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 26
Reputation: chmonalisa is an unknown quantity at this point 
Solved Threads: 1
chmonalisa chmonalisa is offline Offline
Light Poster

Re: Fulltext search with MS SQL

 
0
  #2
Sep 14th, 2006
Hi Mark,


Here is the code. I never tried this before as I didn't need it till now.
But as I have seen ur query I thought I should do this.

See the code
Just copy and paste and see whether it is running.

Make sure you write
use 'database name'
at the start and also specify the search string you need in the code.

here it is............

declare @tablenames varchar(200)
declare @columnames varchar(500)

drop table b#
select col.name 'columnname',obj.name 'tablename',obj.id into b#
from sysobjects obj
inner join syscolumns col on obj.id=col.id where obj.xtype='U'
select * from b#
declare @lstrquery1 nvarchar(4000)
declare @lstrquery2 nvarchar(4000)
declare @tname varchar(50)
declare @cname varchar(50)
declare @searchstring varchar(10)
set @searchstring='cha'
set @lstrquery1=''
set @lstrquery2=''
---declaration of 1st cursor
declare cur1 scroll cursor for
select distinct tablename from b# where tablename<>'b#'
open cur1

fetch first from cur1 into @tname
while @@fetch_status=0
begin

set @lstrquery1= @lstrquery1 + ' select * from ' + @tname + ' where '
--declaration of 2nd cursor
set @lstrquery2=''
declare cur2 scroll cursor for
select columnname from b# where tablename=@tname
open cur2

fetch first from cur2 into @cname
while @@fetch_status=0
begin

if @lstrquery2=''
set @lstrquery2=@lstrquery2 + @cname + ' like ' + char(39) + '%' + @searchstring + '%' + char(39)
else
set @lstrquery2=@lstrquery2 + ' or ' + @cname + ' like ' + char(39) + '%' + @searchstring + '%' + char(39)

fetch next from cur2 into @cname
end

close cur2
deallocate cur2
--end of 2nd cursor

set @lstrquery1 = @lstrquery1 + @lstrquery2
fetch next from cur1 into @tname
end
close cur1
deallocate cur1
select @lstrquery1
exec sp_executesql @lstrquery1
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC