开发者

SQL Server 2005 -> Excel export doesn't keep data types?

Trying (and largely succeeding) to export the results of a query from SQL Server to Excel, like so:

insert into OPENROWSET('Microsoft.开发者_StackOverflow中文版Jet.OLEDB.4.0',
    'Excel 8.0;Database=c:\exported excel files\exported_data.xls;',
    'SELECT * FROM [Query$]') SELECT dbo.blabbityblah FROM dbo.the_table

It works! Sort of. It does export the data to the excel file, but it puts it all in there as text, even though some of the columns are datetime and most of them are numbers. None of them are being convert()-ed in the query itself. I've tried preformatting the cells in the actual Excel file before running the query, but it ignores the existing formating and spits it all out as text again.

There's got to be a way to do this, right?


excel dont have data type, its text based and preformat not work becus it replace existing file. if u want datatype try MS Access.


Look into using a schema.ini file to define the datatypes in a csv or txt. when you open either in excel you may achieve what you want

[sample_out.csv]
Format=CSVDelimited
DecimalSymbol=.
Col1=DATE datetime
Col2=FName Text


Another approach you may want to look at depending on your needs is to use the import and export wizard. You can customize a query for the data and specify the data type in the wizard. If you are using a SKU other than Express you can the run it right away or save the SSIS package is generated for further manipulation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜