Sql Server 2000 minimum DateTime versus C# minimum DateTime

So I have this stored procedure that is taking serialized xml from a C# application, and posting the data to some 12 different tables. Oddly enough, when setting the dates in the C# application, some are null and get replaced with DateTime.Minimum(). Which of course the minimum in C# is different than the minimum date in SQL Server 2000. The strange bit is that I have the xpath queries first populating a table variable, then updating the real table with the contents of the table variable, but the SP does not choke on stuffing the C# minimum date time into the table variable, but when placing the date from the table variable into the real table it dies like a bugblater beast reading Vogon poetry. Don't ask me why. So my next adventure will be to figure out how to replace the bogus min dates in the SP with real min dates.

Comments

  1. After careful study, I realize that I'm an idiot. The table varible field that the date time is getting stuffed with from the xpath query is of type varchar! So it's no wonder that it had no thoughts about accepting junk as the date.

    ReplyDelete
  2. I think this will work:

    DECLARE @Applicant table (
    [Idx] [int] IDENTITY (1, 1),
    t_APBirthDate varchar(50) null)

    insert into @Applicant select '0001-01-01T00:00:00.0000000-06:00' as [t_APBirthDate]

    update @Applicant set t_APBirthDate = convert(varchar,convert(datetime,substring(replace([t_APBirthDate],'0001-','1901-'),1,19),126),126)

    select * from @Applicant

    ReplyDelete

Post a Comment

Popular Posts