0

从源表插入另一个表时,我想将列数据类型从“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 Into AxisReportMain 
Select (Column1,Column2,Column3)
From ReportMain

Column2 包含日期为“VarChar”。在AxisReportMain表 Column2 数据类型为“日期”

4

1 回答 1

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'
于 2012-09-08T11:11:44.273 回答