数据库中日期格式与字符串的转换
insert into WE_VIP (openid,cardno,name,viptype_code,mobile,birthday,gender, OPENSTORECODE,OPENGUIDECODE,points,CREATIONDATETIME) select top(1) i.openid,i.VipID,i.nickname,i.VIPType,i.linkMobileTel, CONVERT(char(8),CAST(i.Birthday AS datetime),112) as Birthday,CASE i.Sexs WHEN '男' THEN '1' WHEN '女' THEN '0' ELSE '2' END as Sexs, i.CreateStoreID,i.createOperatorID,i.Credits7,CONVERT(char(8),i.CreateDate,112) as CreateDate from dbo.VIPInfo i where i.linkMobileTel = '13901395296'
日期格式的转换:
CONVERT(char(8),i.CreateDate,112) as CreateDate
char(8):转换后的格式的占位
i.CreateDate :要转换的字段
112:要转换的格式的编号
字符串转化为日期格式:
CONVERT(char(8),CAST(i.Birthday AS datetime),112) as Birthday