Share via

How to map Numeric Data Type Columns with DateTime2?

Ramana Kopparapu 306 Reputation points
2024-02-07T03:44:11.84+00:00

Hi, This is the issue i have been facing. There are two Numeric Columns (A, B) in my table. I have to map these columns to C column in other table whose data type is Datetime2 using Stored Procedure. A - Numeric B - Numeric C - Datetime2 Getting error like'Int is not compatible with datetime2' column. Could anyone please resolve the issue?

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories


3 answers

Sort by: Most helpful
  1. Erland Sommarskog 134.7K Reputation points MVP Volunteer Moderator
    2024-02-07T23:03:44.0633333+00:00

    You need to ask someone who knows the data how to do the mapping. What you are asking for is nonsensical without further information. Once we know what the rules are, we might be able to write the SQL.

    Was this answer helpful?

    0 comments No comments

  2. LiHongMSFT-4306 31,621 Reputation points
    2024-02-07T09:20:37.2333333+00:00

    Hi @Ramana Kopparapu

    Could you post a sample to reproduce this issue, so that we’ll get a right direction and make some test.

    Regarding this error, here are some possible solutions:

    • Convert the numeric columns to Datetime value before being used in the query.
    • Use ISNULL(``Datetime2_column``, '01/01/1900 23:59:59.999')

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    0 comments No comments

  3. Olaf Helper 47,621 Reputation points
    2024-02-07T07:14:17.4333333+00:00

    Getting error like'Int is not compatible with datetime2'

    As the message already says, a numeric isn't a date value per se.

    Could anyone please resolve the issue?

    Not with that less informations. How does the numeric look like / present a may valid date time?

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.