Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Search Freetext Multiple Columns SQL2000

Posted on 2007-11-29
7
Medium Priority
?
457 Views
Last Modified: 2008-02-01
I am trying to query multiple columns in multiple tables.   I need to weigh certain columns in the results.  My current code looks as follows:
"select Key_Tbl.[key], tblBlogThreads.BlogThreadNum,  tblBlogThreads.Body,tblBlogThreads.PublishDate, tblBlogThreads.Title, tblBlogThreads.Teaser, tblBlogThreads.MetaKeywords,  [rank] from freetexttable(tblBlogThreads, body, '" & tstr & "' ) AS Key_Tbl  INNER JOIN tblBlogThreads ON tblBlogThreads.BlogthreadID = Key_Tbl.[key] order by [rank] desc"

The problem is i need to search in columns tblBlogThreads.Title,  tblBlogThreads, Keywords, and tblBlogThreads.Body, and weigh them in that order.    
0
Comment
Question by:DidiahProd
  • 4
  • 3
7 Comments
 
LVL 25

Expert Comment

by:imitchie
ID: 20379581
select
Key_Tbl.[key], tblBlogThreads.BlogThreadNum,  
tblBlogThreads.Body,tblBlogThreads.PublishDate,
tblBlogThreads.Title,
tblBlogThreads.Teaser,
tblBlogThreads.MetaKeywords,  
[rank]
from
(select [key], rank + 2000 as rank from freetexttable(tblBlogThreads, title, '" & tstr & "' )
 union all
 select [key], rank + 1000 from freetexttable(tblBlogThreads, keywords, '" & tstr & "' )
 union all
 select [key], rank from freetexttable(tblBlogThreads, body, '" & tstr & "' )
) AS Key_Tbl
INNER JOIN tblBlogThreads ON tblBlogThreads.BlogthreadID = Key_Tbl.[key]
order by [rank] desc
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20379590
The ranks returned are 1-1000, therefore match by title will have high rank, then keywords, then body.  I forgot to trim duplicates. this one fixes it

select
Key_Tbl.[key], tblBlogThreads.BlogThreadNum,  
tblBlogThreads.Body,tblBlogThreads.PublishDate,
tblBlogThreads.Title,
tblBlogThreads.Teaser,
tblBlogThreads.MetaKeywords,  
[rank]
from
(select [key], max(rank) as rank from
(select [key], rank + 2000 as rank from freetexttable(tblBlogThreads, title, '" & tstr & "' )
 union all
 select [key], rank + 1000 from freetexttable(tblBlogThreads, keywords, '" & tstr & "' )
 union all
 select [key], rank from freetexttable(tblBlogThreads, body, '" & tstr & "' )
) tbl1
group by [key]) AS Key_Tbl
INNER JOIN tblBlogThreads ON tblBlogThreads.BlogthreadID = Key_Tbl.[key]
order by [rank] desc
0
 

Author Comment

by:DidiahProd
ID: 20379703
Thanks!

these look good but there's a syntax error in there somewhere- getting error near a space, near a space and near a ).
Looking into it...
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 25

Expert Comment

by:imitchie
ID: 20379706
That was meant to include a start " and an end " to be assigned to a string from ASP.NET.  That's why there are two
" & tstr & "
bits in the middle

It does not run as is and will cause an error from Query Analyzer!
But I think you get the idea.

0
 

Author Comment

by:DidiahProd
ID: 20379752
yah thanks- it runs in the QA but won't run in sql- looking more into it.  i can't get it to go in an SP either
0
 

Author Comment

by:DidiahProd
ID: 20379939
How would this be represented as a stored procedure where tsq is the parameter (@tsq)

select 
Key_Tbl.[key], tblBlogThreads.BlogThreadNum,  
tblBlogThreads.Body,tblBlogThreads.PublishDate, 
tblBlogThreads.Title, 
tblBlogThreads.Teaser, 
tblBlogThreads.MetaKeywords,  
[rank] 
from
(select [key], max(rank) as rank from
(select [key], rank + 2000 as rank from freetexttable(tblBlogThreads, title, '" & tstr & "' )
 union all
 select [key], rank + 1000 from freetexttable(tblBlogThreads, keywords, '" & tstr & "' )
 union all
 select [key], rank from freetexttable(tblBlogThreads, body, '" & tstr & "' )
) tbl1
group by [key]) AS Key_Tbl
INNER JOIN tblBlogThreads ON tblBlogThreads.BlogthreadID = Key_Tbl.[key] 
order by [rank] desc

Open in new window

0
 
LVL 25

Accepted Solution

by:
imitchie earned 1300 total points
ID: 20379997
create procedure myproc ( @tsq varchar(100) )
as
select
Key_Tbl.[key], tblBlogThreads.BlogThreadNum,  
tblBlogThreads.Body,tblBlogThreads.PublishDate,
tblBlogThreads.Title,
tblBlogThreads.Teaser,
tblBlogThreads.MetaKeywords,  
[rank]
from
(select [key], max(rank) as rank from
(select [key], rank + 2000 as rank from freetexttable(tblBlogThreads, title, @tsq )
 union all
 select [key], rank + 1000 from freetexttable(tblBlogThreads, keywords, @tsq )
 union all
 select [key], rank from freetexttable(tblBlogThreads, body, @tsq )
) tbl1
group by [key]) AS Key_Tbl
INNER JOIN tblBlogThreads ON tblBlogThreads.BlogthreadID = Key_Tbl.[key]
order by [rank] desc
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question