At any point of time getdate() function can yield wrong data or null ?

  • Hi all ,

    Its big question to me .. In our production server in some sp's to insert modified date and inserted date am using getdate() function .

    Question is for very few records modifieddate is null even thoe it is inserted.

    And for yeterday for one insetion operation inserted date is '20011-11-11' .

    In both case am using getdate() function to use. I assigned that date to one variable and am using that while inserting .

    Am very much sure about the code .

    Still am not getting why it happened and how .. its big problem to fecth live reports with out proper date .

    Please can body answere this ?

    Thanks,

    Ravi@sql

  • Post the code.

    Only way you can get a value like that is if you have dates stored as strings, which is not recommended.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • No its a DateTime field only .

  • ravi@sql (10/18/2011)


    And for yeterday for one insetion operation inserted date is '20011-11-11' .

    You cannot in any way put 20011-11-11 into a datetime field. It'll fail with a conversion error.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Would you mind posting the code. That would help us to look at further.

    Whats the variable datatype?

  • example of code

    INSERT INTO CourseFeedback (Courseid,UserID,Feedbackxml,CreatedDate)

    VALUES (@CourseId,@UserID,@Feedbackxml,GETDATE())

  • ravi@sql (10/18/2011)


    example of code

    INSERT INTO CourseFeedback (Courseid,UserID,Feedbackxml,CreatedDate)

    VALUES (@CourseId,@UserID,@Feedbackxml,GETDATE())

    In both case am using getdate() function to use. I assigned that date to one variable and am using that while inserting .

    This is contrdictory. Where is the assignment of the variable here in the code? Or Am I missing something here?

  • example of code

    declare @date datetime

    set @date=getdate()

    INSERT INTO CourseFeedback (Courseid,UserID,Feedbackxml,CreatedDate)

    VALUES (@CourseId,@UserID,@Feedbackxml,@date)

  • example of code

    INSERT INTO CarFeedback(Carid,UserID,Feedback,CreatedDate)

    VALUES (@Carid,@UserID,@Feedback,getdate())

  • No clues on this. However let me ask you something out of box whats the SQL server version you installed?

  • Microsoft SQL Server 2005 - 9.00.1399.06

  • Ok, its worth looking at the below MSDN. I am not sure as long as I dont have any idea about your complete code.

    http://support.microsoft.com/kb/958547

    Meanwhile, we exepect our experts will have something to guide....

  • ravi@sql (10/18/2011)


    example of code

    declare @date datetime

    set @date=getdate()

    INSERT INTO CourseFeedback (Courseid,UserID,Feedbackxml,CreatedDate)

    VALUES (@CourseId,@UserID,@Feedbackxml,@date)

    The only way that can return anything other than the correct date is if the server's date is set wrong. And it can't return anything like you described in your initial post (20011-11-11)

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 13 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply