CREATE FUNCTION [dbo].[get_number_of_workers] 
(
     @number_of_workers varchar(10)
 
)
RETURNS int
AS
BEGIN
 
 
set @number_of_workers = replace(replace(replace(replace(LTRIM(RTRIM(@number_of_workers)), char(9), ''), char(10), ''), char(13),''), char(13)+char(10), '')
 
DECLARE @temp varchar(10)
 
SELECT
    @temp = number_of_workers 
FROM
    (SELECT LTRIM(RTRIM(@number_of_workers)) as number_of_workers) as temp
WHERE
       number_of_workers like  '[0-9]'
    or number_of_workers like  '[0-9][0-9]'
    or number_of_workers like  '[0-9][0-9][0-9]'
    or number_of_workers like  '[0-9][0-9][0-9][0-9]'
    or number_of_workers like  '[0-9][0-9][0-9][0-9][0-9]'
    or number_of_workers like  '[0-9][0-9][0-9][0-9][0-9][0-9]'
    or number_of_workers like  '[0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
    or number_of_workers like  '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
    or number_of_workers like  '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
    or number_of_workers like  '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
    or number_of_workers like  '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
     
     
RETURN CONVERT(INT, @temp)
 
END
By Anonymous, 2015-07-22 14:59:09