Hello all,
I have a current stored procedure that I believe I need to change so that one of the parameters are optional. It currently takes inputs from a webform: company, client id, phone, and status, etc.
There are multiple companies to choose from, and so we want to enable the possibility of searching all companies, not just one specific one. So, I've created a select box / dropdown box menu option to search in all the companies. When I did that though, the report no longer works because the stored procedure is expecting that company input, not a Null value. I tried changing the stored procedure to check for a null value like so:
Now the page gives the following error:
Error Type:
Microsoft OLE DB Provider for SQL Server (0x80040E14)
Cannot use empty object or column names. Use a single space if necessary.
Can anyone tell me how to make the company paramter an optional one...Or what I should do in a situation like this?
-Ovatvvon :-Q
I have a current stored procedure that I believe I need to change so that one of the parameters are optional. It currently takes inputs from a webform: company, client id, phone, and status, etc.
There are multiple companies to choose from, and so we want to enable the possibility of searching all companies, not just one specific one. So, I've created a select box / dropdown box menu option to search in all the companies. When I did that though, the report no longer works because the stored procedure is expecting that company input, not a Null value. I tried changing the stored procedure to check for a null value like so:
Code:
CREATE PROCEDURE [dbo].[sql_searchClientPhone]
@company varchar(10),
@id varchar(7),
@name varchar(50),
@status varchar(1),
@phone varchar(16)
AS
IF @company = Null
SELECT dba_name, id FROM client
WHERE id LIKE @id AND dba_name LIKE @name AND phone LIKE @phone AND client_status = @status
ORDER BY dba_name
ELSE
SELECT dba_name, id FROM client
WHERE id LIKE @id AND company = @company AND dba_name LIKE @name AND phone LIKE @phone AND client_status = @status
ORDER BY dba_name
GO
Now the page gives the following error:
Error Type:
Microsoft OLE DB Provider for SQL Server (0x80040E14)
Cannot use empty object or column names. Use a single space if necessary.
Can anyone tell me how to make the company paramter an optional one...Or what I should do in a situation like this?
-Ovatvvon :-Q