Simeon Simeon - 6 months ago 22
SQL Question

sp_sqlexec - To many arguments specified

I get the error 'Too many arguments specified' but cannot find the problem

Any help would be greatly appreciated

The 3 parameters are specified at the begin of the procedure

DECLARE
@WhereStatment nvarchar(500),
@ParamList nvarchar(500) = N'@p1 int, @p2 varchar(256), @p3 int'

SET @WhereStatment = ''

-- Check for Status Filter
IF @StatusFilter <> 'All'
SET @WhereStatment = @WhereStatment + ' EntryStatus = @StatusFilter'
ELSE
BEGIN
SET @StatusFilter = 'Invoiced (Complete)'
SET @WhereStatment = @WhereStatment + ' EntryStatus <> @StatusFilter'
END

-- Check for User Filter
IF @UserFilter > 0
SET @WhereStatment = @WhereStatment + ' AND EobID = @UserFilter'

-- Check for Warehouse Filter
IF @WarehouseFilter > 0
SET @WhereStatment = @WhereStatment + ' AND WarehouseNumber = @WarehouseFilter'

-- Add WhereStatement
Set @WhereStatment = '
SELECT
tblWCS_SQE_Entries.RowID, SaleNum, tblWCS_Company_UserAccounts.Fullname, Ets

FROM tblWCS_SQE_Entries

INNER JOIN tblWCS_Company_UserAccounts
ON tblWCS_SQE_Entries.EobID = tblWCS_Company_UserAccounts.RowID

WHERE
'
+ @WhereStatment;

EXEC sp_sqlexec @WhereStatment, @ParamList,
@p1 = @UserFilter,
@p2 = @StatusFilter,
@p3 = @WarehouseFilter

Answer

sp_sqlexec stored procedure indeed has only one parameter. Probably you want sp_executesql instead.