USE [test]
GO
/****** Object: UserDefinedFunction [dbo].[func_convertdouble_to_hoursint] Script Date: 08/31/2014 02:43:40 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <Description, ,>
-- =============================================
Create FUNCTION [func_convertdouble_to_hoursint]
(
-- Add the parameters for the function here
@hoursdecimal decimal(23, 10)
)
RETURNS decimal(23, 2)
AS
BEGIN
declare @minutesint int;
declare @hourpart int;
declare @minutepart int;
declare @ret decimal(23, 2);
-- convert double to hour int format
set @minutesint = convert(int, (@hoursdecimal * 60));
set @hourpart = @minutesint / 60;
set @minutepart = @minutesint % 60;
set @ret = @hourpart + (@minutepart / 100.00);
-- Return the result of the function
RETURN @ret;
END
go
declare @ret decimal(23, 2);
exec @ret = [func_convertdouble_to_hoursint] 6.5;
select @ret;
-- output = 6.30
GO
/****** Object: UserDefinedFunction [dbo].[func_convertdouble_to_hoursint] Script Date: 08/31/2014 02:43:40 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <Description, ,>
-- =============================================
Create FUNCTION [func_convertdouble_to_hoursint]
(
-- Add the parameters for the function here
@hoursdecimal decimal(23, 10)
)
RETURNS decimal(23, 2)
AS
BEGIN
declare @minutesint int;
declare @hourpart int;
declare @minutepart int;
declare @ret decimal(23, 2);
-- convert double to hour int format
set @minutesint = convert(int, (@hoursdecimal * 60));
set @hourpart = @minutesint / 60;
set @minutepart = @minutesint % 60;
set @ret = @hourpart + (@minutepart / 100.00);
-- Return the result of the function
RETURN @ret;
END
go
declare @ret decimal(23, 2);
exec @ret = [func_convertdouble_to_hoursint] 6.5;
select @ret;
-- output = 6.30
ไม่มีความคิดเห็น:
แสดงความคิดเห็น