求SQL语句,急急急!!!在线等 我在SQL Server数据库中有一字段csrq,其内容有1/12/1988;10/11/1986;1/8/1986等表示日/月/年,我想用一个SQL语句将其格式全都修改为1986-12-01;1986-11-10格式,请问Sql语句该怎么写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 declare @m varchar(10)set @m='10/11/1986'select cast(substring(@m,7,4)+'-'+substring(@m,1,2)+'-'+substring(@m,4,2) as datetime) select convert(datetime,'1/12/1988',120)/* ------------------------------------------------------ 1988-01-12 00:00:00.000*/ declare @t table([date] varchar(10))insert @t select '1/12/1988'insert @t select '10/11/1986'select right([date],4)+'-'+substring([date],charindex('/',[date])+1,charindex('/',[date],charindex('/',[date])+1)-charindex('/',[date])-1)+'-'+left([date],charindex('/',[date])-1) from @t/* ------------------------------ 1988-12-11986-11-10*/ update tb set csrq=convert(datetime,csrq,120) select convert(varchar(10),convert(datetime,'1/12/1988',120),120)---------- 1988-01-12(所影响的行数为 1 行) select csrq=convert(datetime,csrq,20) from tb 我将数据按您的程序转换过来了,发现我先前理解错了,格式定义是:月/日/年,现在转换成的数据变为了:年-日-月了,我想写个SQL语句将它改为:年-月-日,请教啊!急! select right(RTRIM(csrq),4)+'-'+left(ltrim(a),CHARINDEX('/', csrq, 1)-1)+'-'+substring(RTRIM(STUFF(csrq, 1, CHARINDEX('/', csrq, 1), '')),0,3) from table 这个还不简单 SELECT CONVERT(datetime,'11/1/2003',103)保证正确. 这个还不简单 SELECT CONVERT(datetime,'11/1/2008',103)保证正确. SQL2008安装问题。我只需要最简单的数据库功能请问安装的时候怎么选。在线等,急!!! 求一解决方法 查询表里某字段重复记录,只选出一条的语句为什么不起作用? 存储过程中的参数问题? 求助:一个简单的两表关联的查询语句,请大家帮忙 2005到2000数据库迁移 难度超大 的列变行 怎样得到正确的ID号? a,b得到表c!!!!!!!!!!!!!!! SQL Server 2000的表的最大记录容量是多少? SQL多表查询求助!急!请各位高手帮忙! 字段合计的问题???
set @m='10/11/1986'select cast(substring(@m,7,4)+'-'+substring(@m,1,2)+'-'+substring(@m,4,2) as datetime)
/*
------------------------------------------------------
1988-01-12 00:00:00.000*/
insert @t select '1/12/1988'
insert @t select '10/11/1986'
select
right([date],4)+'-'+substring([date],charindex('/',[date])+1,charindex('/',[date],charindex('/',[date])+1)-charindex('/',[date])-1)
+'-'+left([date],charindex('/',[date])-1) from @t
/*
------------------------------
1988-12-1
1986-11-10*/
select convert(varchar(10),convert(datetime,'1/12/1988',120),120)----------
1988-01-12(所影响的行数为 1 行)
select right(RTRIM(csrq),4)+'-'+left(ltrim(a),CHARINDEX('/', csrq, 1)-1)+'-'+substring(RTRIM(STUFF(csrq, 1, CHARINDEX('/', csrq, 1), '')),0,3) from table
SELECT CONVERT(datetime,'11/1/2003',103)
保证正确.
SELECT CONVERT(datetime,'11/1/2008',103)
保证正确.