Here are two solutions by using SQL scripts or by using user-defined functions (UDFs).
- Solution 1:
SET NDC = RIGHT(REPLICATE('0', 11) + CONVERT(VARCHAR,NDC),11)
- Solution 2:
- Be careful that length of NULL string is NULL.
- CREATE FUNCTION dbo.PadLeft
(@str INT, @PadWidth INT, @PadChar CHAR(1))
RETURNS VARCHAR(255)
AS
BEGIN
RETURN RIGHT(REPLICATE(@PadChar, @PadWidth) + CONVERT(VARCHAR,@str),@PadWidth)
END
GO - After creating the function above, you can test it with "select dbo.PadLeft(12345, 11, '0')". The result should be "00000012345".
Awesome Post keep Learning Big Data Hadoop Online Training India
ReplyDelete