convert type sql 2008

  • hi,

    I want to know is it is possible to convert an int to date in a table.

    When I run ALTER TABLE dbo.nomtable ALTER COLUMN datefield DATE

    I have an error message:

    Operand clash: int is incompatible with time

  • Not directly, because there's no implicit conversion possible from INT to DATE.

    What you can do is to add a new column with a DATE type, update it with the converted form of the INT then drop the old INT column and rename the new one.

    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
  • I still got the same problem, when i try to update the new field , i got the same message

    ALTER TABLE DBOOKING ADD TAMPON DATE NULL

    UPDATE DBOOKING SET TAMPON=DATEDELETE

    Msg 206, Level 16, State 2, Line 1

    Operand type clash: int is incompatible with date

  • If your int looks like 20141022 (for today's date), you need to convert it to char(8) and then to date. If it's a numeric value representing the date as 41932 (in SQL Server) or 41934 (in Excel), you need to find out the correct way to convert it.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 4 posts - 1 through 3 (of 3 total)

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