【发布时间】:2017-11-21 17:36:02
【问题描述】:
我有以下代码,但现在需要在销售数据文件上有一个唯一的文件名(日期在末尾)
USE [KevinMayhewLive]
GO
/****** Object: StoredProcedure [dbo].[toFileSalesData] Script Date: 06/19/2017 13:36:27 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[toFileSalesData]
as
--xp_cmdshell will shell out to the command line to run bcp
--the user account that runs this procedure should have file access to create and write files
--bcp does not append to files, all data will be overwritten each time this procedure runs
EXEC KevinMayhewLive..xp_cmdshell 'bcp "SELECT * FROM KevinMayhewLive.dbo.KM_CUSTOMER_DATA" queryout \\SERVER3\Docs\Emarsys_Sync\Customer_data\CUSTOMER_DATA.csv -c -t, -T -S'
EXEC KevinMayhewLive..xp_cmdshell 'bcp "SELECT * FROM KevinMayhewLive.dbo.KM_SALES_DATA" queryout \\SERVER3\Docs\Emarsys_Sync\Sales_Data\sales_items.csv -c -t, -T -S'
【问题讨论】:
-
唯一文件名是什么意思?无论如何,您的查询有两个不同的文件名输出
-
您好,欢迎来到 SO。目前尚不清楚您想从这个问题中得到什么。似乎您希望每次执行时都为 SalesData 文件指定一个唯一名称?对这个名字的结构有什么想法吗?在 ALTER 之前的那个 select 语句有什么意义???
-
啊忘了删除那个(以前的一些坏建议)
-
您真的在使用 SQL Server 2005 吗?我希望您能尽快升级到受支持的版本。
-
要是这么简单就好了....
标签: sql sql-server csv stored-procedures sql-server-2005