请教,sql语句如何写?

来源:百度知道 编辑:UC知道 时间:2024/06/05 09:13:27
请教,sql语句如何写?
数据库名 yonghu ,字段是 csrq

字段现在有三种情况,:1980-1-1
1980-1-12
1980-11-2 要更新成19800101,19800112,19801102.
请教如何写啊。

update yonghu set csrq ------ where------- and
在sql查询分析器中用的语句! 1980-1-1 1980-1-12 1980-11-2 是举例,csrq有上万条数据,要变成YYMMDD格式

最准确答案:(字段类型要为字符型才行)
update yonghu set csrq=convert(varchar(8),csrq,112)
或者:
update yonghu set new_field=convert(varchar(8),csrq,112)
其中new_field的数据类型为字符型

如果时间类型的字段,不需要更新,在用户显示时,用formatdateTime格式化时间就可以了,
ASP中,这里得到你要的结果。

dim strYear, strMonth, strDay

'...
'...
'查询得到csrq字段值
'...
'..
'组合结果
strYear=year(rs("rsrq"))
strMonth=month(rs("rsrq"))
strDay=day(rs("rsrq"))

'月或日为10以下,前面加0
if strMonth<10 then strMonth="0" & strMonth
if strDay<10 then strDay="0" & strDay

response.write "字段处理结果:" & strYear & strMonth & strDay

update yonghu
set csrq=convert(char(8),cast(csrq as datetime),112)
where csrq in('1980-1-1','1980-1-12',1980-11-2')

update yonghu set csrq csrq
=19800101 where csrq=1980-1-1
以此类推!

直接修改字段的数据类型就行