简体   繁体   English

BCP SQL 服务器成表

[英]BCP SQL Server into a table

I am trying to BCP a file into a table that has the same columns as the file being brought in我正在尝试将一个文件 BCP 到一个表中,该表与被引入的文件具有相同的列

BCP command BCP 命令

EXEC xp_cmdshell 'BCP [CMS_Data].[dat].[SNP_2019_02_Special Needs Plan Report_RAW] in "\\FileShare\datafeeds\CMS_ResearchStatistics\Temp\SNP-2019-02\SNP_2019_02_Special Needs Plan Report.csv" -t"|" -T -c -F2 -S MSSQLSERVER'

I am getting this error我收到此错误

Copy direction must be either 'in', 'out' or 'format'.复制方向必须是“in”、“out”或“format”。

I am using F2 to skip the header row the error states I need a in, out or format but the in is clearly there.我正在使用 F2 跳过 header 行错误状态我需要输入、输出或格式,但输入显然存在。 This must be some other issue I am not seeing.这一定是我没有看到的其他问题。 This code worked prior.此代码之前有效。 I changed the F2 to F18 since that is where the data started on the file.我将 F2 更改为 F18,因为这是文件上数据的开始位置。 Since that seemed like an issue I moved data to line 2 but now it does not work there either.由于这似乎是一个问题,我将数据移动到第 2 行,但现在它也不起作用。

I downloaded the data set from https://www.cms.gov/Research-Statistics-Data-and-Systems/Statistics-Trends-and-Reports/MCRAdvPartDEnrolData/Downloads/2019/Feb/SNP-2019-02.zip我从https://www.cms.gov/Research-Statistics-Data-and-Systems/Statistics-Trends-and-Reports/MCRAdvPartDEnrolData/Downloads/2019/Feb/SNP-2019-02.ZADCDBD79A8D84175C229B1下载了数据集

I converted the xls to csv and deleted the first 16 rows to get to the "main table"我将 xls 转换为 csv 并删除前 16 行以进入“主表”

I replaced the, with |我用 | 替换了to match your file setup匹配您的文件设置

I created your table in my DBA database in the dbo schema我在我的 DBA 数据库中的 dbo 模式中创建了您的表

CREATE TABLE [dbo].[SNP_2019_02_Special Needs Plan Report_RAW]( [Contract Number] [varchar](max) NULL, [Contract Name] [varchar](max) NULL, [Organization Type] [varchar](max) NULL, [Plan ID] [varchar](max) NULL, [Segment ID] [varchar](max) NULL, [Plan Name] [varchar](max) NULL, [Plan Type] [varchar](max) NULL, [Plan Geographic Name] [varchar](max) NULL, [State(s)] [varchar](max) NULL, [Plan Enrollment] [varchar](max) NULL, [Special Needs Plan Type] [varchar](max) NULL, [Specialty Diseases] [varchar](max) NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO

I ran BCP to copy the data from the csv I created from the zip contents and it successfully imported the data to the table created in DBA我运行 BCP 以复制从 zip 内容创建的 csv 中的数据,它成功地将数据导入到 DBA 中创建的表中

bcp "[DBA].[dbo].[SNP_2019_02_Special Needs Plan Report_RAW]" in  "C:\Users\someuser\Desktop\SNP_2019_02.csv" -c -t"|" -T -S "bi-server"

bcp 结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM