CREATE PROCEDURE [dbo].[USP_PT_Convert_Integer]
(
@InputString
VARCHAR(10)
)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @InputValue INT, @DotIndex TINYINT
IF ISNUMERIC(@InputString) = 1
BEGIN
SET @DotIndex = CHARINDEX('.', @InputString)
IF @DotIndex = 0
SET @DotIndex = LEN(@InputString)
ELSE
SET @DotIndex =
@DotIndex - 1
SET @InputValue = CONVERT(INT,SUBSTRING(@InputString,1, @DotIndex))
END
RETURN @InputValue
SET NOCOUNT OFF;
END
GO
CREATE PROCEDURE [dbo].[USP_PT_Convert_Integer_Caller]
(
@InputString
VARCHAR(10)
)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @InputValue INT
EXEC @InputValue =
dbo.[USP_PT_Convert_Integer] @InputString
SELECT @InputValue
SET NOCOUNT OFF;
END
GO
----------------------------------------------
EXEC [dbo].[USP_PT_Convert_Integer_Caller] '23456.89088'
RESULT: 23456
EXEC [dbo].[USP_PT_Convert_Integer_Caller] '23456a.89088'
RESULT: 0
No comments:
Post a Comment