Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query

StackOverflow https://stackoverflow.com/questions/12316734

  •  30-06-2021
  •  | 
  •  

Question

alter table Garantor alter column [Birth Date] int

Was it helpful?

Solution

Try something like this (you'll need to create a new column, update it with a conversion, drop the old one then rename the new one with old one's name)

ALTER TABLE dbo.Garantor
ADD newBirthDate int NOT NULL DEFAULT 0 -- NULL and DEFAULT as required
GO

UPDATE dbo.Garantor
SET newBirthDate = CAST([Birth Date] AS int) -- or CONVERT function, it will do the same
GO

ALTER TABLE dbo.Garantor
DROP COLUMN [Birth Date]
GO

SP_RENAME 'dbo.Garantor.newBirthDate', 'dbo.Garantor.[Birth Date]'
GO
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top