我想读一个带有一行的简单文本文件,所以我创建了这个过程,但是它找出了找不到错误信息的路径。
问题是什么?
ALTER PROCEDURE [dbo].[readFile]
(@Path VARCHAR(500))
AS
BEGIN
DECLARE @Command VARCHAR(255)
--SET @Path = ISNULL(@Path,'C:\Users\Maga\test.txt')
SET @Command = 'type ' + @Path
PRINT @Command
INSERT INTO SimpleText
EXEC xp_cmdshell @Command
IF @@ROWCOUNT <> 0
BEGIN
SELECT * FROM SimpleText;
END
END
答案 0 :(得分:0)
您正在传递文件路径而没有双引号。你需要以双引号传递它。
ALTER PROCEDURE [dbo].[readFile]
(@Path VARCHAR(500))
AS
BEGIN
DECLARE @Command VARCHAR(255)
--SET @Path = ISNULL(@Path,'C:\Users\Maga\test.txt')
SET @Command = 'type "' + @Path +'"'
PRINT @Command
INSERT INTO SimpleText
EXEC xp_cmdshell @Command
IF @@ROWCOUNT <> 0
BEGIN
SELECT * FROM SimpleText;
END
END