日期转换为yyyyMMdd方式(本来数据库是用日期型的,但是由于各种原因要把日期型改成字符型并且以yyyyMMdd方式保存的话,可以用下面的方法更新数据库)
select cast(year(datetime) as varchar(4))+
cast(replicate('0',2-len(month(datetime))) as varchar(1))+cast(month(datetime) as varchar(2))+
cast(replicate('0',2-len(day(datetime))) as varchar(2)) +
cast(day(cycle) as varchar(2)) from table