I\'m trying to import data into a table. I\'m doing a bulk insert. I\'ve created the table using a CREATE statement where all fields are nvarchar(max). I cannot understand why w
I suggest that you define the number of zeros that do you want and then make an update. Here is an example with 10 zeros.
create table #leadingZeros(uglynumber nvarchar(max),handsomenumber nvarchar(max),nicenumber nvarchar(max))
INSERT INTO #leadingZeros VALUES(1000000,0000123,0500000)
SELECT * FROM #leadingZeros
--OUTPUT:
--uglynumber handsomenumber nicenumber
--1000000 123 500000
UPDATE #leadingZeros SET
uglynumber=RIGHT('0000000000'+uglynumber,10)
,handsomenumber=RIGHT('0000000000'+handsomenumber,10)
,nicenumber=RIGHT('0000000000'+nicenumber,10)
SELECT * FROM #leadingZeros
--OUTPUT
--uglynumber handsomenumber nicenumber
--0001000000 0000000123 0000500000