1.duanduan1122 说的select no,left(convert(datetime,date,112),6) from tablename 不对,应该是 select no,convert(varchar(6),date,112) from tablename2.如果要得到20056的效果: select no,convert(varchar(4),getdate(),112) + convert(varchar(2),month(getdate())) from tablename
--测试数据 if object_id('ta') is not null drop table ta go create table ta(no int, date datetime) insert ta select 1, '2005-6-24' union all select 2, '2005-7-8' union all select 3, '2005-11-1' --查询 select* from ta select no,yymm=convert(varchar(6), date, 112) from ta--扫尾 drop table ta
将某种数据类型的表达式显式转换为另一种数据类型。CAST 和 CONVERT 提供相似的功能。
返回从字符串左边开始指定个数的字符。
那你能不能告诉我
year(date) month(date)
2005 6
我想达到20056的效果应该怎么写?
year(date)+month(date)?
说的select no,left(convert(datetime,date,112),6) from tablename
不对,应该是
select no,convert(varchar(6),date,112) from tablename2.如果要得到20056的效果:
select no,convert(varchar(4),getdate(),112) + convert(varchar(2),month(getdate())) from tablename
if object_id('ta') is not null drop table ta
go
create table ta(no int, date datetime)
insert ta select 1, '2005-6-24'
union all select 2, '2005-7-8'
union all select 3, '2005-11-1'
--查询
select* from ta
select no,yymm=convert(varchar(6), date, 112) from ta--扫尾
drop table ta
你已经说得很明白了。是我多事了。