FIX: Fail to Pass NULLs as Char/Varchar When Invoking a SProc

Last reviewed: May 1, 1997
Article ID: Q136655

The information in this article applies to:
  • Microsoft SQL Server, version 6.0
BUG#: 11312 (6.00)

SYMPTOMS

When a stored procedure is invoked with ODBC procedure syntax, passing NULLs as char or varchar parameters into this stored procedure will raise the following error:

   szSqlState = "22005", *pfNativeError = 257, *pcbErrorMsg = 160
   szErrorMsg="[Microsoft][ODBC SQL Server Driver][SQL Server] Implicit
   conversion from datatype 'money' to 'char' is not allowed.  Use the
   CONVERT function to run this query."

WORKAROUND

There are two ways to avoid this problem:

  1. Use the EXECUTE keyword to invoke stored procedures. Using this method, a stored procedure is treated as a language event rather than a Remote Procedure Call, and the application will suffer some performance loss.

  2. Replace NULLs with two single quotation marks (''). This is a temporary workaround only for this version of the SQL Server Driver.

STATUS

Microsoft has confirmed this to be a problem in SQL Server Driver version 2.50.0121. This problem has been corrected in SQL Server 6.0 Service Pack 2. For more information, contact your primary support provider.

MORE INFORMATION

Here are the steps to reproduce the error using ODBC Test:

  1. SQLExecuteDirect: create table test(col1 char(10), col2 varchar(10))

  2. SQLExecuteDirect: create proc stest @p1 char(10), @p2 varchar(10) as insert into test values(@p1, @p2)

  3. SQLExecuteDirect: {call stest(NULL, NULL)}


Additional query words: ODBC NULL RPC EXECUTE
Keywords : kbbug2.50.0121 kbbug6.00 kbfix6.00.sp1 kbprg SSrvProg SSrvStProc
Version : 2.5.0121 6.0
Platform : WINDOWS
Issue type : kberrmsg


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 1, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.