Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

formatting cell to 10 digits in excel

Posted on 2016-08-08
5
Medium Priority
?
37 Views
Last Modified: 2016-08-08
I have a column that is a text .  It needs preceeding zero's for identification.
when i copy this data out of a sqy query result and paste it in to excel, it will take out the leading zeros.
I can custom format the column with 0000000000  (ten zeros)  and it works fine visibly.  when i then take the newly formatted column
of data and paste it to another column, it will revert back and take out the leading zeros.  This is paste values.
I can also paste with formatting and that seems to work fine.

My problem is this... when i import that data back into sql, it reverts back to truncating the preceeding zeros.

there are 4 columns that show my process

i can't use the & function or concatenate function to add just one zero because some of the accounts have 2 preceeding zeros...
ten-digit-help.xlsx
0
Comment
Question by:jamesmetcalf74
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 2000 total points
ID: 41747377
>it will take out the leading zeros.
That's a very common issue, as Excel interprets the data type as numeric and formats accordingly, and all numeric data types do not support leading zeros.

Couple of options:
  • Add a single tick mark ' to the left of any export to Excel, which will interpret it as text and not numeric.  Then in any import from Excel to SQL Server remove the tick mark.
  • Edit your 'import that data back into sql' process to specifically ensure the leading zeros are there plus insert into a char/varchar column.
0
 

Author Comment

by:jamesmetcalf74
ID: 41747386
trying to add a single quote to output of sql query and am unable to.... i can add just about anything else but am having trouble with single quote
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 41747400
Show us the T-SQL, as adding a quote mark within a string usually means two quote marks, For example..
SELECT 'My name is Radar O''Reilly.  Choppers!!!'

Open in new window

0
 

Author Comment

by:jamesmetcalf74
ID: 41747410
no success.  i have tried with and without parenthesis and with and without the '+'
USE Test
 GO
SELECT  ('' + f.designatornumber)
0
 

Author Closing Comment

by:jamesmetcalf74
ID: 41747416
just got it
thanks ST. Jimbo
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question