Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Stored procedures 需要帮助:为批量插入创建存储过程_Stored Procedures_Batch File_Bulkinsert - Fatal编程技术网

Stored procedures 需要帮助:为批量插入创建存储过程

Stored procedures 需要帮助:为批量插入创建存储过程,stored-procedures,batch-file,bulkinsert,Stored Procedures,Batch File,Bulkinsert,首先,我是新来的。我使用的是SQLServer2008R2。我有一个大容量插入脚本。我试图创建一个存储过程,然后将其另存为storedprocedure.sql。最后,我需要一个.bat文件来启动批量插入。我有另一个可以运行外部程序的程序,但它只能看到.bat或.exe 下面是我的批量插入脚本: Bulk Insert MyDatabase.dbo.cust_adj From 'C:\path\importformat.txt' With ( FieldTerminator= '|',

首先,我是新来的。我使用的是SQLServer2008R2。我有一个大容量插入脚本。我试图创建一个存储过程,然后将其另存为
storedprocedure.sql
。最后,我需要一个
.bat
文件来启动批量插入。我有另一个可以运行外部程序的程序,但它只能看到
.bat
.exe

下面是我的批量插入脚本:

Bulk Insert MyDatabase.dbo.cust_adj
From 'C:\path\importformat.txt' 
With 
(
   FieldTerminator= '|', 
   Rowterminator= '\n' 
) 
Go

(this works)
然后,我尝试创建存储过程:

Create Procedure LoadDailyAdjReport
AS
    Bulk Insert MyDatabase.dbo.cust_adj 
    From 'C:\path\importformat.txt' 
    With 
    ( 
       FieldTerminator= '|', 
       Rowterminator= '\n' 
    ) 
Go 
它说它成功了。。。但我不知道怎么检查

然后我尝试制作一个.bat文件并尝试:

@echo off
sqlcmd -S MyServer\MyDataBase -i C:\mypath\Load_Daily_Adjustment.sql
它不起作用。起初我以为这是我的.bat指令(可能不正确),但后来我怀疑我的存储过程是否正确。问题是我真的不知道如何解决这个问题。有没有人能提供一些建议或指点这应该是什么样的

非常感谢你

好的,在SQL Server上,此.bat文件可以工作:

sqlcmd-S MyServerName-E-d MyDatabase-Q“EXEC mystoredprocesdure”

服务器是:\Server1\ 我运行bat文件的程序在另一台服务器上。文件是共享的,用户对SQL、文件夹、程序等具有安全性

如何将.bat文件更改为程序服务器上的文件


因此,在Server2上,我希望有一个bat文件来访问并打开Server1上的.bat。为此,是否需要将.bat文件更改为\Server1\PathName\file.bat的路径?

执行SP LoadDailyAdjReport的SQL将是
EXEC LoadDailyAdjReport
-请在ypur批处理文件SQLCMD中尝试以下操作:

sqlcmd -S YourServerName -E -d YourDataBaseName -Q "EXEC LoadDailyAdjReport"
(-E使用可信连接(Windows登录)更多详细信息,请参见此处
)

如果您想尝试将.txt文件名作为参数传入,请参见

非常好。bat文件工作正常,现在我只需确保我的其他程序将成功运行该文件。非常感谢你!好的,我现在还有一个问题。。。我需要从其他服务器运行bat文件。。。我编辑了我的原始问题,但这里是:无论sqlcmd中指定了什么服务器,它都将在该服务器上执行该SP。当我运行.bat文件时,我在命令提示窗口中得到以下信息:“sqlcmd”不被识别为内部或外部命令、可操作程序或批处理文件。请参阅