Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Keep data type as text after convert to Excel

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2009-02-24 : 15:16:16
There is column as "OrderNumber" as varchar data type.
After convert to Excel, lost "0" in the front of "OrderNumber"
For example, if OrderNumber = 000123 will become "123" in Excel file.
How to solve this problem in SQL select statement?

mfemenel
Professor Frink

1421 Posts

Posted - 2009-02-24 : 16:01:58
Try adding a ' to your string '00002

Mike
"oh, that monkey is going to pay"
Go to Top of Page

eevans
Starting Member

48 Posts

Posted - 2009-02-24 : 16:30:49
When I export to Excel, I first excute the query in 'Results to Text' mode. I copy the results and paste them in Notepad, saving it as a .txt file. I open the file in Excel. This brings up the Text Import Wizard. On the last screen of the Text Import Wizard you can specify what data type each column should be. Hope this helps.
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-24 : 16:30:56
Add Data Conversion task in between and use UNICODE STRING[DT_WSTR) in it.
Go to Top of Page
   

- Advertisement -