Oct 29, 2011

Sql Function for padding text to field output


create function ULPAD(@vInput varchar(max), @iLenght smallint,@cPadChar char(1))
   returns varchar(max)
as
begin
   if @vInput is not null
   begin
      if LEN(@vInput) <= @iLenght
      begin
         set @vInput = RIGHT (REPLICATE(@cPadChar, @iLenght)+ CAST (@vInput AS varchar), @iLenght)
      end
   end
   return @vInput
end

Ex:
SELECT @NewEmpNo =dbo.ULPAD((Select com_empsrno +1  from Mcompany  where com_code=@Emp_Org_srno) , 5,'0')             

No comments:

Post a Comment

What is the use of n-tier architecture and 3-tier architecture?

how to implement 3-tier architecture in asp.net using c#. 3-Tier architecture is also called layered architecture. Some people called it ...