0

我想从 txt 文件中读取行并在过程 TESTSP 中进行一些处理。但我确实有一些错误。我应该如何重写我的查询?此致。

代码:


DECLARE @i int
set @i =0
WHILE(@i<85)
begin
@i=@i+1;
if(@i<10)
begin
    exec TESTSP'C:\dosya\X_20130208_0'+@i+'.txt'
end
else
begin
    exec TESTSP 'C:\dosya\X_20130208_'+convert(@i as varchar(2))+'.txt'
end
end

错误:

Msg 102, Level 15, State 1, Line 5
Incorrect syntax near '@i'.

Msg 102, Level 15, State 1, Line 8
Incorrect syntax near '+'.

Msg 102, Level 15, State 1, Line 12
Incorrect syntax near '+'.
4

1 回答 1

3

你需要convert or cast @i (int) to varchar string concatenation. 另请注意syntax of Convert,您已使用强制转换语法进行转换。

declare @i int = 0, @path varchar(500)

while(@i<85)
begin

    --You can simplify (or remove if condition) using right() function as below

    --Assign @path here before calling stored procedure
    select @i = @i + 1, 
           @path = 'C:\dosya\X_20130208_' + right(100 + @i, 2) + '.txt'

    --Execute stored procedure here
    exec TESTSP @path

end
于 2013-02-26T10:50:48.477 回答