CREATE procedure ProductSearch
(
@pagesize int,
@pageindex int,
@Keywords varchar(50),
@Address varchar(50),
@docount bit
)
as
BEGIN TRAN
DECLARE @COUNT INT
DECLARE @SID INT
set nocount on
if(@docount=1)
if(@Address <> ' ')
begin
IF((select count(ProductID) from Products as Product1 inner join Company on Product1.BusinesseID=Company.BusinesseID inner join FREETEXTTABLE(Products,Title,@Keywords) as Product2
on Product1.ProductID=Product2.[KEY] where Company.Address LIKE '% '[email protected]+ '% ') <21)
SET @COUNT=(select count(ProductID) from Products as Product1 inner join Company on Product1.BusinesseID=Company.BusinesseID inner join FREETEXTTABLE(Products,Title,@Keywords) as Product2
on Product1.ProductID=Product2.[KEY] where Company.Address LIKE '% '[email protected]+ '% ')
ELSE
SET @COUNT=20
select count(ProductID)[email protected] from Products as Product1 inner join Company on Product1.BusinesseID=Company.BusinesseID inner join containstable(Products,Title,@Keywords) as Product2
on Product1.ProductID=Product2.[KEY]
where Company.Address LIKE '% '[email protected]+ '% '
end
else
begin
IF((select count(ProductID) from Products as Product1 inner join Company on Product1.BusinesseID=Company.BusinesseID inner join FREETEXTTABLE(Products,Title,@Keywords) as Product2
on Product1.ProductID=Product2.[KEY]) <21)
SET @COUNT=(select count(ProductID) from Products as Product1 inner join Company on Product1.BusinesseID=Company.BusinesseID inner join FREETEXTTABLE(Products,Title,@Keywords) as Product2
on Product1.ProductID=Product2.[KEY])
ELSE
SET @COUNT=20
select count(ProductID)[email protected] from Products as Product1 inner join Company on Product1.BusinesseID=Company.BusinesseID inner join containstable(Products,Title,@Keywords) as Product2
on Product1.ProductID=Product2.[KEY]
end
else
begin
declare @indextable table(id int identity(1,1),nid int)
declare @PageLowerBound int
declare @PageUpperBound int
set @PageLowerBound=(@pageindex-1)[email protected]
set @[email protected][email protected]
set rowcount @PageUpperBound
if(@Address <> ' ')
begin
BEGIN
insert into @indextable(nid) select top 20 ProductID from Products as Product1 inner join Company on Product1.BusinesseID=Company.BusinesseID
inner join containstable(Products,Title,@Keywords) as Product2 on Product1.ProductID=Product2.[KEY] inner join Businesses on Product1.BusinesseID=Businesses.BusinesseID
where Businesses.Grade= '2 ' and Company.Address LIKE '% '[email protected]+ '% '