integer表示日期的格式

时间:2014-11-14 14:04:50

标签: sql sql-server

我的任务是创建一个函数,该函数采用表示Manager招聘日期格式的整数,并以此格式显示部门名称,经理名称和招聘日期。

我试过这个但它也失败了

alter function FormatOfManagerHireDate(@hireDate int)
returns @t table(DeptName nvarchar(50),ManagerName nvarchar(50),HiringDate nvarchar(50) )
as 
begin 
  set @hireDate=FORMAT(SYSDATETIME(), 'MM/dd/yy'); 
  insert into @t
  select Department.Dept_Name,Instructor.Ins_Name,Department.Manager_hiredate
  from Department inner join Instructor on Instructor.Ins_Id=Department.Dept_Manager
  where Department.Manager_hiredate =@hireDate  
return
end 

错误是:

  

消息206,级别16,状态2,过程FormatOfManagerHireDate,第7行操作数类型冲突:日期与int不兼容

1 个答案:

答案 0 :(得分:0)

我误解了你的问题,但至少我的回答帮助你找到答案。因此,这是您的任务的实际解决方案(摘自下面的评论):

alter function FormatOfManagerHireDate(@hireDateFormat int)
returns @t table(DeptName nvarchar(50), ManagerName nvarchar(50), HiringDate nvarchar(50)) as
begin
    insert into @t
    select Department.Dept_Name, Instructor.Ins_Name, convert(nvarchar(50), Department.Manager_hiredate, @hireDateFormat)
    from Department
    inner join Instructor on Instructor.Ins_Id = Department.Dept_Manager
return
end