在查询分析器中运行
exec master..xp_cmdshell 'bcp eMobile.dbo.TB1 out c:\temp1.xls -c -q -s"eMobile" -u"sa" -p"elibome"'
数据库:eMobile
用户:sa
密码:elibome
表:TB1
运行总出现bcp 未知选项s
用法:......不知道是怎么回事?

解决方案 »

  1.   


    SQL SERVER使用OpenRowset,、OpenDataSource函数导入、导出数据到Excel 的几种方法
    一、如我在D盘下有D:\物件编码.xls文件,有工作表名Sheet是中文命名为‘办公用品编码’,‘零件编码’。
    select * into #temp  from opendatasource('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=D:\物件编码.xls')...[办公用品编码$]
    select * into #temp  from opendatasource('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=D:\物件编码.xls')...[零件编码$]二、如你的Excel文件是工作表是默认的Sheet命名为Sheet1,Sheet2等。
    select * into #temp  from opendatasource('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=D:\物件编码.xls')...[Sheet1$]
    select * into #temp  from opendatasource('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=D:\物件编码.xls')...[Sheet2$]三、引用 Limpire 以下方法,也行
          OpenRowSet和OpenDataSource都能用读取用数字命名的Sheet,只不过要加单引号界定,其它不规则命名的Sheet也一样。
    假设C:\Text.xls有个Sheet名字是“”:
    select * from opendatasource('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:\Test.xls')...['3$']
    --OR
    select * from openrowset('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:\Test.xls',['3$'])
    --OR
    select * from openrowset('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:\Test.xls','select * from [''3$'']')
    --OpenRowSet(,,'query')可以不加单引号界定:
    select * from openrowset('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:\Test.xls','select * from [3$]')四、本人的方法:
    导出EXCEL时,对应字段数类型都要相同,EXCEL字段的名称stano,sname 和数据库的要一样,才能导出成功。
    insert into openrowset('MICROSOFT.JET.OLEDB.4.0','excel 8.0;
    HDR=YES;database=D:\FName.xls',sheet1$)
    select stano,sname from stainfoSQL Server 2005 使用SQL命令开启openrowset的办法 
    --show advanced options
    sp_configure 'show advanced options',1
    go--Enable create ole auotmation
    sp_configure 'Ole Automation Procedures',1
    reconfigure with override
    Go--Enable extend stored procedure xp_cmdshell
    sp_configure 'xp_cmdshell',1
    reconfigure with override
    Go--Enable AWE model.Use over 4GB memory
    sp_configure 'awe enabled',1
    reconfigure with override
    Go--Configure how many memory server will used
    Sp_configure ‘max server memory’,14336 --14G
    Reconfigure with override
    Go --Enable distributed query/transaction in AD HOC query like opendatasource/operquery/OPENROWSET
    sp_configure 'Ad Hoc Distributed Queries',1
    reconfigure with override
    Go
      

  2.   

    select * into #temp  from opendatasource('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=D:\物件编码.xls')...[办公用品编码$]这个的数据库表参数是那个啊??除了EXCEL 我还想将记录集插入TXT和ACCESS我上面这个问题到底出在哪里啊?
      

  3.   

    exec master..xp_cmdshell 'bcp eMobile.dbo.TB1 out c:\temp1.xls -c -q -S"服务器名" -U"sa" -P"elibome"'