Monday, 20 February 2012

Decimal to Integer


CREATE FUNCTION [dbo].[Decimal_To_Integer_F] (
@InputValue nvarchar(max)
)
RETURNS BIGINT
AS
BEGIN

DECLARE @DecimalStartPosition int

SET @InputValue = LTRIM(RTRIM(REPLACE(@InputValue,',','')))
SET @DecimalStartPosition = CHARINDEX('.',@InputValue)
SET @InputValue = SUBSTRING(@InputValue,1,@decimalstartposition-1)
SET @InputValue = CAST(@InputValue as BIGINT)

RETURN @InputValue

END

No comments:

Post a Comment