如何从Sql Server 2005将数据导出到多个工作表中 [英] How to export data into multiple worksheets from the Sql server 2005

查看:96
本文介绍了如何从Sql Server 2005将数据导出到多个工作表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库中,我有1000行,而一列具有不同的Status.我需要根据状态将来自sql server 2005的数据导出到不同的工作表中.
即,我需要动态创建10个工作表,并将所选的列连续插入与该状态相关的工作表中.如果有任何想法,请指导我...


在此先感谢,

In my Database, i have 1000 rows and one column have different Status.I need to export the data from the sql server 2005 as per the status into the different worksheets.
ie, I need to create 10 worksheets dynamically and insert the selected columns in a row into the workseets related to that status .please guide me if any Idea''s ...


Thanks in Advance,

推荐答案

使用以下查询:
Use below query:
DECLARE @myfile varchar(255)
DECLARE @stat int

SET @myfile = 'C:\template.xls'
SET @stat = 1

EXEC ('INSERT INTO
OPENROWSET(''Microsoft.Jet.OLEDB.4.0'',''Excel 8.0;Database=' + @myfile + ';'',
''SELECT * FROM [Sheet1


'') SELECT * FROM myTable WHERE [status] =' + @ stat + ' ')
'') SELECT * FROM myTable WHERE [status]=' + @stat + '')


请参见

动态创建Excel文件
see

Dynamically creating Excel File


这篇关于如何从Sql Server 2005将数据导出到多个工作表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆