locked
DT_DBTIMESTAMP type casting return inconsistent value. RRS feed

  • Question

  • In SQL 2008 SP2 enterprise, using SSIS to do derived column converting data,

    type casting with DT_DBTIMESTAMP return inconsistent value when query with ANALYSIS QUERY under MS SQL Management Studio.

    for example, (DT_DBTIMESTAMP) (1753-1-1) would result, '1904-10-16 00:00:00.000'.

    Does this make any sense?

    Thanks.

    Sunday, August 7, 2011 3:39 AM

Answers

  • Hello Activex88,

    your issue is you hardcoded a numeric value, now explaining:

    this conversion looks to me like you want to convert a string value to DT_DBTIMESTAMP, so your expression must look like:

    (DT_DBTIMESTAMP) ("1753-1-1")


    if you try it, 1/1/1753 12:00:00 AM will be produced.

    So if you drop the " (double quotes) it will operate on a 1753-1-1 algebraical representation which result in value 1751 and produce that strange result.


    Arthur My Blog
    By: TwitterButtons.com
    Sunday, August 7, 2011 5:05 AM

All replies

  • Hello Activex88,

    your issue is you hardcoded a numeric value, now explaining:

    this conversion looks to me like you want to convert a string value to DT_DBTIMESTAMP, so your expression must look like:

    (DT_DBTIMESTAMP) ("1753-1-1")


    if you try it, 1/1/1753 12:00:00 AM will be produced.

    So if you drop the " (double quotes) it will operate on a 1753-1-1 algebraical representation which result in value 1751 and produce that strange result.


    Arthur My Blog
    By: TwitterButtons.com
    Sunday, August 7, 2011 5:05 AM
  • Thanks, ArthurZ.

    I forgot put double quote on date string.

    It works now. :)


    HL
    Sunday, August 7, 2011 7:13 AM