In my earlier article, I had discussed about the omitted leading zeros in excel and I received a very nice solution from Mr. Harsh, one of my blog readers. (This solution works in Excel 2010 and above).
Let me explain his solution step by step.
Step A :
Let me create a sample to demonstrate the error.
USE tempdb GO CREATE TABLE [dbo].[tbl_Employee]( [Employee ID] [varchar](5) NULL, [Employee Name] [varchar](50) NOT NULL ) ON [PRIMARY] GO INSERT [dbo].[tbl_Employee] ([Employee ID], [Employee Name]) VALUES (N'00001', N'A. Scott') INSERT [dbo].[tbl_Employee] ([Employee ID], [Employee Name]) VALUES (N'00002', N'Alan') INSERT [dbo].[tbl_Employee] ([Employee ID], [Employee Name]) VALUES (N'00003', N'Alejandro') INSERT [dbo].[tbl_Employee] ([Employee ID], [Employee Name]) VALUES (N'00004', N'Alex') INSERT [dbo].[tbl_Employee] ([Employee ID], [Employee Name]) VALUES (N'00005', N'Alice') GO SELECT [Employee ID], [Employee Name] FROM [tbl_Employee] GO --OUTPUT
Step B :
Copy the data from SQL Server, open an excel sheet, click on Paste Button and select Use Text Import Wizard (as shown in the picture below).
Step C :
It then takes you to 3 steps of Text Import Wizard. Under Text Import Wizard – Step 1 of 3, you need to determine the data type. Select Delimited and press Next (as shown in the picture below).
Step D :
Text Import Wizard – Step 2 of 3 lets you to set the delimiters your data contains. Select Tab and press Next (as shown in the picture below).
Step E :
Text Import Wizard – Step 3 of 3 lets you set the column data format. Select Text and press Finish (as shown in the picture below).
Step F :
Once finished, the data would be pasted in the required format, meaning along with the zeros as shown in the picture below.
Let me know if you know any better solution.
Leave a Reply