0

我正在尝试制作一个包含单个命令行输出的 txt 文件。但是由于某种原因,它不想将文本和测试名称添加到其中。这是我的代码:

    declare @command AS varchar(200)
declare @cmd AS varchar(200)
declare @input AS varchar(200)
declare @timeinput AS varchar(200)
declare @test AS varchar(1000)
declare @failureid as int

select @timeinput = (select time from inserted)
select @input = (select action from inserted)
select @failureid = (select failureId from inserted)

select @test = (select name from dbo.Alert where FailureId = @failureid)


if (@input = 'start')
BEGIN
set @command = ('EnableTest' + @test)
END

if (@input = 'stop')
BEGIN
set @command = ('DisableTest' + @test)
END

if (@input = 'pauze')
set @command = ('PauseTest' + @test + @timeinput)
END

SET @cmd = 'echo ' + @command + ' > F:\commandfolder\testing.HMS'
EXECUTE Master.dbo.xp_CmdShell @cmd

HMS 文件中的输出是: DisableTest (with the testname missing) @test 没有添加到文件中。

据我所知,我的表格中的数据是正确的有什么想法吗?

在此先感谢和亲切的问候,

戴夫

4

2 回答 2

0

它现在似乎正在工作,没有任何调整。我不知道为什么它没有,但代码是正确的。

于 2013-10-30T10:35:30.123 回答
0

怎么样:

 declare @command AS varchar(200)
 declare @cmd AS varchar(200)
 declare @input AS varchar(200)
 declare @timeinput AS varchar(200)
 declare @test AS varchar(1000)
 declare @failureid as int
 select @timeinput = (select time from inserted) 
 select @input = (select action from inserted)
 select @failureid = (select failureId from inserted)
 select @test = (select name from dbo.Alert where FailureId = @failureid)
 if (@input = 'start')
 BEGIN
 set @failureid = (select failureId from inserted where action= @input)
 set @test = (select name from dbo.Alert where FailureId = @failureid)
 set @command = ('EnableTest' + @test)
 END

 if (@input = 'stop')
 BEGIN
 set @failureid = (select failureId from inserted where action= @input)
 set @test = (select name from dbo.Alert where FailureId = @failureid)
 set @command = ('DisableTest' + @test)
 END

 if (@input = 'pauze')
 begin
 set @failureid = (select failureId from inserted where action= @input)
 set @test = (select name from dbo.Alert where FailureId = @failureid)
 set @command = ('PauseTest' + @test + @timeinput)
 END

 SET @cmd = 'echo ' + @command + ' > F:\commandfolder\testing.HMS'
 EXECUTE Master.dbo.xp_CmdShell @cmd

基本上,我的猜测是您必须为每个案例设置变量,否则它保持不变。

于 2013-10-29T15:15:20.523 回答