I am trying to stop input of negative values to process in any of the ranges, rather if they are negative they should drop down to the end of the 1st case statement as 'Invalid'. This is not working as when I run a test against the input of (-1000) i get a row for <=50K. I am afraid my syntax is wrong, but not sure why.
ALTER FUNCTION [dbo].[FN_1ST_UPB_Bands]
(
@FN_1ST_UPB_Band int
)
RETURNS varchar(16)
AS
BEGIN
declare @Return varchar (16)
select @Return =
Case
When ISNUMERIC(@FN_1ST_UPB_Band)= 1 then
case
When @FN_1ST_UPB_Band is NULL then ' Missing'
When @FN_1ST_UPB_Band = 0 then ' 0'
When @FN_1ST_UPB_Band < = 50000 then ' <=50K'
When @FN_1ST_UPB_Band between 50000 and 100000 then ' 50-100'
When @FN_1ST_UPB_Band between 100000 and 150000 then '100-150'
When @FN_1ST_UPB_Band between 150000 and 200000 then '150-200'
When @FN_1ST_UPB_Band between 200000 and 250000 then '200-250'
When @FN_1ST_UPB_Band between 250000 and 300000 then '250-300'
When @FN_1ST_UPB_Band between 300000 and 350000 then '300-350'
When @FN_1ST_UPB_Band between 350000 and 400000 then '350-400'
When @FN_1ST_UPB_Band between 400000 and 450000 then '400-450'
When @FN_1ST_UPB_Band between 450000 and 500000 then '450-500'
When @FN_1ST_UPB_Band > 500000 then '500K+'
else null End
else 'Invalid' End
RETURN @return
End