BUG: Stored Procedures Cannot Process NULL Parameters from VB (177187)
The information in this article applies to:
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
This article was previously published under Q177187 SYMPTOMS A SQL stored procedure produces unexpected results if a
NULL parameter is passed from a Visual Basic application using RDO. This
behavior also occurs if the SQL stored procedure declares an optional parameter
whose default value is NULL and no parameters are passed. RESOLUTION The workaround is to modify the SELECT statement in the
stored procedure. If a stored procedure is declared as:
CREATE PROC Test_SP
@Param VARCHAR (20) = NULL
AS
SELECT * FROM Test_Table WHERE Field = @Param
GO
replace it with:
CREATE PROC Test_SP
@Param VARCHAR (20) = NULL
AS
IF @Param = NULL
SELECT * FROM Test_Table WHERE Field = NULL
ELSE
SELECT * FROM Test_Table WHERE Field = @Param
GO
The following can also be used:
CREATE PROC Test_SP
@Param VARCHAR (20) = NULL
AS
SELECT * FROM Test_Table WHERE (Field = NULL and @Param = NULL) OR
(Field = @Param)
GO
STATUS Microsoft has confirmed this to be a bug in the Microsoft
products listed at the beginning of this article. We are researching this bug
and will post new information here in the Microsoft Knowledge Base as it
becomes available.
Modification Type: | Major | Last Reviewed: | 11/5/2003 |
---|
Keywords: | kbbug KB177187 |
---|
|