zoukankan      html  css  js  c++  java
  • BCP xp_cmdshell

    ---------------------- 从现有表导出结果 ----------------------
    -- 将AdventureWorks.HumanResources.Employee表的数据导出到C:\test.xls
    EXEC master..xp_cmdshell ' BCP "select * from AdventureWorks.HumanResources.Employee" queryout C:\test.xls -c  -SCN110075 -Usa -Pchang' 

    -- 删除C:\test.xls
    EXEC master..xp_cmdshell 'del C:\test.xls '

    ---------------------- 从全局临时表表导出结果 ----------------------
    -- 建立临时表
    select row_number() over(order by employeeId) as rowNumber, * into ##tmp from AdventureWorks.HumanResources.Employee

    -- 从临时表导出数据
    EXEC master..xp_cmdshell ' BCP "select * from tempdb..##tmp " queryout C:\test.xls -c  -SCN110075 -Usa -Pchang' 

    -- 删除临时表
    drop table ##tmp

    -- 删除C:\test.xls
    EXEC master..xp_cmdshell 'del C:\test.xls '

    ---------------------- 这样写有错,还为找到原因 ----------------------
    EXEC master..xp_cmdshell ' BCP "HumanResources.Employee " out C:\test.xls -c  -SCN110075 -Usa -Pchang' 

    -- 错误信息
    /*
    output
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    An error occurred while processing the command line.
    NULL
    */

    ---------------------- union 好像双引号与查询语句之间不能有空格 ----------------------
    EXEC master..xp_cmdshell 'BCP " select
    "''ForeCastType''" as ForeCastType, "''OrderNumber''" as OrderNumber,
    "''HHPN''" as HHPN, "''Plant''" as Plant, "''Quantity''" as Quantity, "''DueDate''" as DueDate
    union
    select "''LSF''" as ForeCastType, "''FCST2006''" as OrderNumber, HHPN,  Plant,
    convert(varchar(10),Quantity) as Quantity, convert(char(10), DueDate, 20) as DueDate 
    from Converter.dbo.detail
    where pid=1 order by plant, HHPN, DueDate "
    queryout c:\output.xls -c -SCN110075 -Usa -Pchang'

  • 相关阅读:
    R: 聚类分析
    R: 主成分分析 ~ PCA(Principal Component Analysis)
    R: 关于 ggplot2 的初探
    R: 字符串处理包:stringr
    R: 用 R 查看、管理文件(夹)
    R: 关于文件 文件夹的处理:file.show() dir.create().....
    R: 绘图 pie & hist
    R: 绘图 barplot
    R: 对向量中的每个元素,检查其是否包含某个“单词”
    R: 一页显示多张图的方法
  • 原文地址:https://www.cnblogs.com/aspsmile/p/1260782.html
Copyright © 2011-2022 走看看