Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Page History: PadLeft Function - SQL Server

Compare Page Revisions



« Older Revision - Back to Page History - Current Revision


Page Revision: Fri, Dec 10, 2010, 8:48 AM


{copytext|src}
create function dbo.PadLeft
    (
     @input     int 
    ,@width     int 
    ,@pad       char(1) 
    ) returns varchar as begin
/*
declare
     @input int = 10000
    ,@width int = 5 
    ,@pad char(1) = '0'   
*/    
return REPLICATE(@pad, @width - ceiling(LOG10(@input+1))) + CONVERT(varchar(20), @input)

end

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.