Hello there...
I am trying to write a function where I can pass a string and it returns the numbers only based on the asci codes but I am getting an error.
The function so far is as below.
Can anyone help with what could be wrong.
SQL server says.... Incorrect syntax near the keyword 'Asc'. but am just not sure what the prob is.
Cheers in advance.
nimi
I am trying to write a function where I can pass a string and it returns the numbers only based on the asci codes but I am getting an error.
The function so far is as below.
Can anyone help with what could be wrong.
Code:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[ExtractInteger](@String VARCHAR(2000))
RETURNS VARCHAR(1000)
AS
BEGIN
DECLARE @Count INT
DECLARE @IntNumbers VARCHAR(1000)
SET @Count = 0
SET @IntNumbers = ''
WHILE @Count <= LEN(@String)
BEGIN
If Asc(substring(@String, @Count, 1,)) < 48
or Asc(substring(@String, @Count, 1)) > 57
BEGIN
SET @IntNumbers = Left(@String, @Count - 1) & substring(@String, @Count + 1,1)
END
SET @Count = @Count + 1
END
RETURN @IntNumbers
END
SQL server says.... Incorrect syntax near the keyword 'Asc'. but am just not sure what the prob is.
Cheers in advance.
nimi