I'm new to SQL and have inherited a database which uses nvarchar(50) as the data type for the "Date" column. I want to convert this column into datetime format but I cannot figure out how to do so as I am using SQL CE 4.0 and can only find solutions for SQL.
This is an example in SQL of what I would like to do:
SET DATEFORMAT dmy
alter TABLE [dbo].[tablename]
ALTER COLUMN columnname datetime
I know I will probably need to create a new column and copy/convert the data from the old column into the new one using a query. I just need some guidance on how to do this.
Currently the Date column is in the format "dd/MM/yyyy hh:mm:ss tt".
I have been using Microsoft WebMatrix if that is helpful at all.
Thanks!
I agree with you: the best solution is to create a new column
ALTER TABLE yourTable ADD COLUMN newColumn DATETIME
(the SET DATEFORMAT statement doesn't exist in SQL Server Compact)
and copy data converting the format
UPDATE yourTable SET newColumn = CONVERT(datetime, oldColumn, 103)
For an in depth description of the SQL Server Compact commands look at http://technet.microsoft.com/en-us/library/ms173372.aspx