我希望将列数据类型从'VarChar'更改为'DataType'从源表中插入另一个表
我可以在T-SQL
中完成Declare @DateTime As DateTime
Declare @Date As NVARCHAR(20)
Set @Date = '120901'
Set @DateTime = CONVERT(Date,'20'+SUBSTRING(@Date,1,2)+'-'+SUBSTRING(@Date,3,2)+'-'+SUBSTRING(@Date,5,2))
Print @DateTime
如何在insert Statement
中实现它Insert Into AxisReportMain
Select (Column1,Column2,Column3)
From ReportMain
Column2包含Date为'VarChar'。在AxisReportMain
表中Column2 DataType是“Date”
答案 0 :(得分:1)
尝试:
Insert Into AxisReportMain
Select Column1,
CONVERT(Date,'20'+SUBSTRING(Column2,1,2)+'-'+SUBSTRING(Column2,3,2)+'-'+SUBSTRING(Column2,5,2)) as Column2,
Column3
From ReportMain
Where Column2 <> '000000'