Hi,
I am currently creating an ASP page that returns a recordset of search
result based on multiple keywords. The where string is dynamically
built on the server page and that part work quite well. However I want
to also return the number of records in the recordset and I can not
manage to get any output parameter working. Even if I assign SELECT
@mycount=100 (or SET @mycount=100) in the SP the only value set in
mycount is always NULL. I tested various theories (e.g. early exit,
order & naming of parameters etc. but I can not make the SP set the
output parameters - has it anything to do with the execute?). @mycount
also returns NULL if I test it in SQL QA.
What's wrong with this SP (as regards mycount):
CREATE PROCEDURE dbo.spFindProdu cts
@mycount integer OUTPUT,
@whereString varchar (1000)
AS
--SET NOCOUNT ON
--Set a Default value for the Wherestring which will return all records
if the Wherestring is blank
IF @whereString is Null
SELECT @whereString = 'AND TblProduct.Prod uctID is not null'
--Declare a variable to hold the concatenated SQL string
DECLARE @SQL varchar(2500)
-- AND (((UPPER([TblProduct].[ProductName] + [ProductGroupCod e] +
[AttributeValue1] +
-- [SearchWords] + [tblSupplier].[SupplierCode] + [SupplierDesc]))
Like '%screw%'))
SELECT @SQL = 'SELECT TblProduct.Prod uctID, TblProduct.Prod uctName,
TblProduct.Chap terCode, tblProduct.Prod uctGroupCode' +
' FROM (TblProduct LEFT JOIN TblStockItem ON TblProduct.Prod uctID =
TblStockItem.Pr oductID) ' +
' LEFT JOIN tblSupplier ON TblProduct.Supp lierCode =
tblSupplier.Sup plierCode' +
' WHERE 1=1 ' + @whereString +
' GROUP BY TblProduct.Prod uctID, TblProduct.Prod uctName,
TblProduct.Chap terCode, TblProduct.Prod uctGroupCode'
SELECT @mycount = 200; -- test
execute (@SQL);
-- next line seems to be ignored ?
SELECT @mycount = @@rowcount;
GO
tia
Axel
I am currently creating an ASP page that returns a recordset of search
result based on multiple keywords. The where string is dynamically
built on the server page and that part work quite well. However I want
to also return the number of records in the recordset and I can not
manage to get any output parameter working. Even if I assign SELECT
@mycount=100 (or SET @mycount=100) in the SP the only value set in
mycount is always NULL. I tested various theories (e.g. early exit,
order & naming of parameters etc. but I can not make the SP set the
output parameters - has it anything to do with the execute?). @mycount
also returns NULL if I test it in SQL QA.
What's wrong with this SP (as regards mycount):
CREATE PROCEDURE dbo.spFindProdu cts
@mycount integer OUTPUT,
@whereString varchar (1000)
AS
--SET NOCOUNT ON
--Set a Default value for the Wherestring which will return all records
if the Wherestring is blank
IF @whereString is Null
SELECT @whereString = 'AND TblProduct.Prod uctID is not null'
--Declare a variable to hold the concatenated SQL string
DECLARE @SQL varchar(2500)
-- AND (((UPPER([TblProduct].[ProductName] + [ProductGroupCod e] +
[AttributeValue1] +
-- [SearchWords] + [tblSupplier].[SupplierCode] + [SupplierDesc]))
Like '%screw%'))
SELECT @SQL = 'SELECT TblProduct.Prod uctID, TblProduct.Prod uctName,
TblProduct.Chap terCode, tblProduct.Prod uctGroupCode' +
' FROM (TblProduct LEFT JOIN TblStockItem ON TblProduct.Prod uctID =
TblStockItem.Pr oductID) ' +
' LEFT JOIN tblSupplier ON TblProduct.Supp lierCode =
tblSupplier.Sup plierCode' +
' WHERE 1=1 ' + @whereString +
' GROUP BY TblProduct.Prod uctID, TblProduct.Prod uctName,
TblProduct.Chap terCode, TblProduct.Prod uctGroupCode'
SELECT @mycount = 200; -- test
execute (@SQL);
-- next line seems to be ignored ?
SELECT @mycount = @@rowcount;
GO
tia
Axel
Comment