rapataa (dg@rapataa.frup) writes:
I'm building a simple search engine using keyword and title of a page:
select ID, content_ID, 3 as 'weight'
from tblPage
where keywords LIKE '%test%'
union
select ID, content_ID, 2
from tblPage
where title LIKE '%test%'
now I want to sum and order 'weight'
It's not exactly clear to me what you mean by sum and order. You
can always add an "ORDER BY weight" at the end of the query. Yes,
you can even do:
SELECT ID, content_ID, weight
FROM (select ID, content_ID, 3 as 'weight'
from tblPage
where keywords LIKE '%test%'
union
select ID, content_ID, 2
from tblPage
where title LIKE '%test%') x
ORDER BY weight
COMPUTE SUM(weight)
But the COMPUTE clause is non-relational, and use of it is deprecated.
I suggest that you post:
o CREATE TABLE statement your table.
o INSERT statements with sample data.
o The desired result from the sample data.
This can make it a little clearer what you are looking for.
--
Erland Sommarskog, SQL Server MVP,
es****@sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp