Results 1 to 6 of 6

Thread: Stored Procedure Null Vlaues

  1. #1

    Thread Starter
    Lively Member G.U.R.U Africa's Avatar
    Join Date
    Mar 2002
    Location
    South Africa (SOWETO)
    Posts
    76

    Stored Procedure Null Vlaues

    Hi!

    I get an error when a send a null datetime and integer values to a stored procedure.


    Error:
    Application uses a value of the wrong type for the current operation.



    cmdNP_AQUA.Parameters.Append cmdNP_AQUA.CreateParameter("@effective_to", adDate + adEmpty, adParamInput, 8, rsNP_ESERVER("effective_to")))

    cmdNP_AQUA.Execute


    Is there a way to send null values to a stored procedure?
    REBEL - G.U.R.U Africa

  2. #2
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    it's best not to have null values in a database. Put blank times in for datetime such as "00:00:00" and may be 0's for integers.
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Is there a way to send null values to a stored procedure?
    Absolutely. I do it all the time. The only possible problem that I see with the code you posted is the datatype paramter. Note the size parameter is only required for variable length columns.

    Change adDate + adEmpty to just adDBTimeStamp

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    The value for a "NULL" date (which a contradiction as you can't have a non date) is to use "12/31/1899". SQL Server will treat that value as similarto NULL.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Any variable in SQL Server, which is what we are talking about here, can be set to Null. Even dates. In fact all variables are initialzed to Null when they are declared.

  6. #6
    Junior Member
    Join Date
    Sep 2002
    Location
    Boston
    Posts
    26

    Response

    Not sure why you would want a date nullable. Have you thought about setting the date as a default value, i.e getdate(). Or just use the other strategies provided in this thread. Also if you want to add null or if a user doesn't enter a value this is how it's done

    @DummyVar AS VARCHAR(10) = NULL /* This makes the parameter value optional */

    Just throw an If condition such as

    IF @DummyVar IS NOT NULL
    BEGIN
    IF RTRIM(@SQL) <> '' SET @SQL = @SQL + ',' + RTRIM (@DummyVar) + ' FROM TBLSample '
    END

    Hope this helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width