Results 1 to 5 of 5

Thread: how 2 pass NULL to Date DataType ?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    203

    how 2 pass NULL to Date DataType ?

    I'm Importing, exporting data to a text file using the Write/Input method.
    when the app. writes 2 a textfile, if the value in the date field is Null, it putz #NULL# in place of the field. When reading frm the same textfile, it givz an error as the variable tt Im using to recieve the value is of date type. How do I go around this problem?

    and, how exactly can I pass NULL 2 a Date type variable ?

    dim dtest as Date
    dtest= NULL

    givz error

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    the value 0 (zero) works like null. It assigns no date.

  3. #3
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    You can't assign a null to a date. The only datatype that accepts null is a variant. So this is the datatype to use when working with nulls.

    If you assign a value of zero, you are actually assigning the date 30/12/1899 12:00:00 AM:
    Code:
    Dim d As Date
    d = 0
    Debug.Print Format(d, "dd/mm/yyyy hh:mm:ss AM/PM")

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    203
    well since I cant change the data type of the field in the database
    (its smalldatetime), I change the datatype of the parameter tt I pass 2 the stored proc.But there is no option for advariant, so I passed adVarchar using a variable of variant datatye. Now, this works fine when there is a Null value, but I cant get it 2 work, when there is a date present in the datefield.
    givz error
    "Application uses a value of the wrong type for the current operation"

    dim xtest as variant


    cmd.Parameters.Append .CreateParameter("@TrainingStartDate", adVarChar, adParamInput, 4, xtest)



    CREATE PROCEDURE i_EmployeeDetails

    @TrainingStartDate varchar,

    AS

    INSERT INTO EmployeeInfo VALUES(


    Convert ( smalldatetime(4) ,@TrainingStartDate ,1 ) ,

  5. #5
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    You can create a default value for your parameter. So if the parameter is not passed then it will use a default value:
    Code:
    CREATE PROCEDURE i_EmployeeDetails 
    
    @TrainingStartDate smalldatetime = NULL, 
    
    AS 
    BEGIN
        INSERT INTO EmployeeInfo VALUES(@TrainingStartDate)
    END

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