批量错误 SQL Server BULK INSERT

批量错误 SQL Server BULK INSERT

我试图在批处理文件中编写一个运行 SQL Server 存储过程的脚本。存储过程将 .CSV 文件中的数据批量插入到 SQL Server 表中。当我在 SQL Server 上运行存储过程时,它运行正常。但是,当我尝试让它在我的批处理文件中工作时,它失败了

我的批处理脚本是

set STEP_NBR=STEP113
set SQL_Script_Name= CST_SN_ADD_SPS_CUSTOMER_ORDER_STG_TMP
set ERROR_MSG=%STEP_NBR% %SQL_Script_Name%
call "%DIR_BAT%\CreateLAFMessage.bat" "%~n0.bat-> %STEP_NBR% - Running %SQL_Script_Name%.sql" %_LAF_MSG_DETAILS%
SQLCMD.EXE %SQLCMD_VARS% -S%DB_SERVER_NAME% -d%DB_SP01_NAME% -w2048 -E -b -i"%DIR_SQL%\%SQL_Script_Name%.sql" -o"%DIR_LOG%\%SQL_Script_Name%.lst"
IF NOT %ERRORLEVEL%==0 GOTO ON_ERROR

SQL 脚本调用存储过程

DECLARE @return_value int
EXEC    @return_value = [dbo].[CST_SN_ADD_SPS_CUSTOMER_ORDER_STG_TMP]
SELECT  'Return Value' = @return_value
GO

存储过程

USE [LVSDB_DRP01]
GO
/****** Object:  StoredProcedure [dbo]. 
[CST_SN_ADD_SPS_CUSTOMER_ORDER_STG_TMP]    Script Date: 9/10/2018 10:28:30 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER Procedure [dbo].[CST_SN_ADD_SPS_CUSTOMER_ORDER_STG_TMP] 
as 
BEGIN

BEGIN TRANSACTION;

IF OBJECT_ID('staging.dbo.ADD_CUSTOMER_ORDER_STG_TMP', 'U') IS NULL
CREATE TABLE [staging].[dbo].[ADD_CUSTOMER_ORDER_STG_TMP](
[ITEM_INDX] [nvarchar](50) NOT NULL,
[LOC_INDX] [nvarchar](50) NOT NULL,
[CUST_ORD_INDX] [nvarchar](50) NOT NULL,
[CUST_ORD_LIN_NBR] [nvarchar](50) NOT NULL,
[CUST_ORD_ORD_DATE] [date] NOT NULL,
[CUST_ORD_QTY] [nvarchar](50) NULL,
[CUST_SHP_QTY] [nvarchar](50) NULL,
[SET_ITEM_INDX] [nvarchar](50) NOT NULL,
[HEADER_COMPONENT] [nvarchar](50) NOT NULL,
[BUCKET] [nvarchar](50) NOT NULL
)

IF OBJECT_ID('staging.dbo.ADD_CUSTOMER_ORDER_STG_TMP', 'U') IS NOT NULL
Truncate table staging.dbo.ADD_CUSTOMER_ORDER_STG_TMP;

IF OBJECT_ID('staging.dbo.ADD_CUSTOMER_ORDER_STG_TMP', 'U') IS NOT NULL
BULK INSERT staging.dbo.ADD_CUSTOMER_ORDER_STG_TMP
FROM '\\usashsmdbpcw02f\C$\SNI_Logility\ADD_CUSTOMER_ORDER_STG.csv'
WITH 
  (
    FIELDTERMINATOR = ',',
    FIRSTROW = 2
--    ROWTERMINATOR = '\r\n'
  );

COMMIT TRANSACTION;
END

存储过程在 SQL Server 上运行,因此我认为我的错误是在批处理脚本中,或者可能是文件路径的权限

相关内容