I am writing a scalar function in T-SQL. The function should insert leading zeros into an input field of numbers the length of the input can vary in length, i,e,. 123, 1234567, 9876543210 and so forth.
I am not certain that I have defined the fields correctly as I am trying include both an Input variable and an output variable which is new to me. I am trying in insert leading zeros in front of input field and return the value input with leading zeros.
ALTER FUNCTION dbo.FN_ZeroPad
(
@FN_Input_No varchar(13)
)
RETURNS varchar(13)
AS
BEGIN
declare @FN_PadZero varchar (13),
@Return varchar (13)
Set @FN_PadZero = '0000000000000'
select @Return =
Case
When @FN_Input_No is null then 'Missing'
When @FN_Input_No < = 0 then '0000000000000'
When @FN_Input_No > 0 then (@FN_PadZero + @FN_Input_No)
else null End
RETURN @return
End