【求助】写了一个时间转换函数有错误求改之
函数内容: 
 CREATE   FUNCTION   comm_GetDatime( 
 	@ReportYear   varchar(4), 
 	@ReportMonth   varchar(2), 
 	@ReportDay   varchar(2) 
 ) 
 RETURNS   VARCHAR(15) 
 AS 
 BEGIN 
 	DECLARE   @Datetime   Varchar(15)  	 
 	SET   @Datetime=@ReportYear   +    '- '   +   @ReportMonth   +    '- '   +   @ReportDay  	 
 	RETURN   @Datetime 
 END 
 函数功能:根据传进来的三个参数:年,月,日()均为整型变量,经过处理后返回一个日期型输出。 
 如:输入变量:2007      8      3 
 输出形式:2007-08-03   或   2007-8-3   均可 
 在线等着送分! 
------解决方案--------------------  --函数名要加dbo. 
 CREATE FUNCTION dbo.comm_GetDatime( 
 	@ReportYear varchar(4), 
 	@ReportMonth varchar(2), 
 	@ReportDay varchar(2) 
 ) 
 RETURNS VARCHAR(15) 
 AS 
 BEGIN 
 	DECLARE @Datetime Varchar(15)  	 
 	SET @Datetime=@ReportYear +  '- ' + @ReportMonth +  '- ' + @ReportDay  	 
 	RETURN @Datetime 
 END 
 go     
 --调用时,也要加dbo. 
 select dbo.comm_GetDatime(2007,8,3) 
------解决方案--------------------2007-08-03格式:     
 SET @Datetime = @ReportYear +  '- ' + replicate(0, 2 - len(@ReportMonth)) + @ReportMonth +  '- ' + + replicate(0, 2 - len(@ReportDay)) + @ReportDay
------解决方案----------------------創建函數 
 CREATE FUNCTION dbo.comm_GetDatime( 
 	@ReportYear varchar(4), 
 	@ReportMonth varchar(2), 
 	@ReportDay varchar(2) 
 ) 
 RETURNS VARCHAR(15) 
 AS 
 BEGIN 
 	DECLARE @Datetime Varchar(15)  	 
 	SET @Datetime=@ReportYear +  '- ' + Right(100 + @ReportMonth, 2) +  '- ' + Right(100 + @ReportDay, 2)  	 
 	RETURN @Datetime 
 END 
 GO 
 --調用 
 Select dbo.comm_GetDatime( '2007 ',  '8 ',  '3 ') 
 Select dbo.comm_GetDatime( '2007 ',  '08 ',  '3 ') 
 --結果 
 /* 
 2007-08-03 
 */