sql中如何把整型转换成日期

来源:百度知道 编辑:UC知道 时间:2024/06/16 19:08:03
我有3个整型的数据 2007 7 1
怎么才能在sql中转成日期型的 2007-7-1

在oracle中:

select to_date(to_char(2007)||'-'||to_char(7)||'-'||to_char(1),'yyyy-mm-dd') from dual;

在sql server中:

convert(datetime,convert(varchar(4),2007)+'-'+convert(varchar(1),7)+'-'+convert(varchar(1),1))

对不起,sql中没有这种格式!

顺便让你看看:sqlserver中的时间格式

declare @count tinyint
select @count=1
while @count<=13 --最多只能为13,否则出现错误
begin
select @count=@count+1
print convert(varchar(12),getdate(),@count)
end