数据库中日期格式与字符串的转换

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

 

posted @ 2017-04-07 14:36  话说当初  阅读(6926)  评论(0编辑  收藏  举报