Hello, I have a table where I am trying to select the data using this function dbo.numeric_to_date(Created_Date,Created_Time) from table ....
The created_Date(int) and Created_Time ( smallint) are integer values.
And it stores the data as Created_Date: 20080519
Created_Time: 1660
The problem is where I noticed that whenever the Created_Time column has last two numbers with 60(seconds) it throws an error. I think it shuold automatically round it to 1700 but it doesnot.
My function is like this:
CREATE function [dbo].[numeric_to_date](@numeric_date numeric(9), @smallint_time smallint)
returns datetime
as
begin
declare @return_value datetime
---------------------------------------------
Note: I added this piece of code later to fix the problem. but this did not fix I think since there are many records in the table and this only fixes one record at a time.. i am not sure..
if @smallint_time like '%60'
begin
set @smallint_time = round(@smallint_time, -2)
end
----------------------------------------------
if @numeric_date = 0
begin
select @return_value = null
end
else
begin
if @smallint_time = 0 or @smallint_time = null
begin
select @return_value = convert(datetime,substring(convert(varchar(8),convert(numeric(9),@numeric_date)),5,2) + '/'
+ substring(convert(varchar(8),convert(numeric(9),@numeric_date)),7,2) + '/'
+ substring(convert(varchar(8),convert(numeric(9),@numeric_date)),1,4))
end
else
begin
select @return_value = convert(datetime,ltrim(rtrim(substring(convert(varchar(8),convert(numeric(9),@numeric_date)),5,2) + '/'
+ substring(convert(varchar(8),convert(numeric(9),@numeric_date)),7,2) + '/'
+ substring(convert(varchar(8),convert(numeric(9),@numeric_date)),1,4)) + ' '
+ substring(convert(varchar(4),right('0000' + convert(varchar(4),@smallint_time),4)),1,2) + ':'
+ substring(convert(varchar(4),right('0000' + convert(varchar(4),@smallint_time),4)),3,2)))
end
end
return(@return_value)
end
How Can I fix this function so that it rounds if created_time is 1660 or when it has 60 seconds then round it otherwise Dont.. Please Help
Thanks
The created_Date(int) and Created_Time ( smallint) are integer values.
And it stores the data as Created_Date: 20080519
Created_Time: 1660
The problem is where I noticed that whenever the Created_Time column has last two numbers with 60(seconds) it throws an error. I think it shuold automatically round it to 1700 but it doesnot.
My function is like this:
CREATE function [dbo].[numeric_to_date](@numeric_date numeric(9), @smallint_time smallint)
returns datetime
as
begin
declare @return_value datetime
---------------------------------------------
Note: I added this piece of code later to fix the problem. but this did not fix I think since there are many records in the table and this only fixes one record at a time.. i am not sure..
if @smallint_time like '%60'
begin
set @smallint_time = round(@smallint_time, -2)
end
----------------------------------------------
if @numeric_date = 0
begin
select @return_value = null
end
else
begin
if @smallint_time = 0 or @smallint_time = null
begin
select @return_value = convert(datetime,substring(convert(varchar(8),convert(numeric(9),@numeric_date)),5,2) + '/'
+ substring(convert(varchar(8),convert(numeric(9),@numeric_date)),7,2) + '/'
+ substring(convert(varchar(8),convert(numeric(9),@numeric_date)),1,4))
end
else
begin
select @return_value = convert(datetime,ltrim(rtrim(substring(convert(varchar(8),convert(numeric(9),@numeric_date)),5,2) + '/'
+ substring(convert(varchar(8),convert(numeric(9),@numeric_date)),7,2) + '/'
+ substring(convert(varchar(8),convert(numeric(9),@numeric_date)),1,4)) + ' '
+ substring(convert(varchar(4),right('0000' + convert(varchar(4),@smallint_time),4)),1,2) + ':'
+ substring(convert(varchar(4),right('0000' + convert(varchar(4),@smallint_time),4)),3,2)))
end
end
return(@return_value)
end
How Can I fix this function so that it rounds if created_time is 1660 or when it has 60 seconds then round it otherwise Dont.. Please Help
Thanks