create table #a (a varchar(8000))
insert #a EXEC xp_cmdshell 'dir *.exe'
select * from #adrop table #a

解决方案 »

  1.   

    create table #a (a varchar(8000))
    insert #a EXEC xp_cmdshell 'dir *.exe'
    select * from #adrop table #a
      

  2.   

    可以直接接收xp_cmdshell 输出的结果集呀
      

  3.   

    PRINT 'Success'
    ELSE
    PRINT 'Failure'
    是显示在消息里的你可以在前台程序中接收xp_cmdshell 的结果集
      

  4.   

    Select Space(500) as A into #tmp
    Insert #tmp exec XP_CmdShell 'Dir D:\'
    Select * from #tmp
      

  5.   

    存储过程的返回结构,可以返回到表中.--创建一个临时表,用来保存执行结果:
    create table #tb(re varchar(8000))--得到结果:
    insert #tb EXEC xp_cmdshell 'dir *.exe'--显示结果
    select * from #tb--删除临时表
    drop table #tb
      

  6.   

    但是如下语句@b得出结果不全。(我需要把结果付值给一变量,之后程序可对结果进行处理)--创建一个临时表,用来保存执行结果:
    create table #tb(re varchar(8000))
    --得到结果:
    insert #tb EXEC xp_cmdshell 'dir *.exe'
    --显示结果
    declare @b varchar(8000)
    select @b=re from #tb
    --删除临时表
    print @b
    drop table #tb
      

  7.   

    create table #tb(re varchar(8000))insert #tb EXEC xp_cmdshell 'dir *.exe'declare @i varchar(8000)declare  cursor_insert cursor for select * from #tb
    open cursor_insert
    fetch cursor_insert into @i
    while @@fetch_status=0
    begin  print @i  fetch cursor_insert into @i
    end
    close cursor_insert
    deallocate cursor_insert
    drop table #tb
      

  8.   

    但是如下语句@b得出结果不全。(我需要把结果付值给一变量,之后程序可对结果进行处理)那是因为你只取了第一条记录的数,改用游标逐条读取处理就行了.
    --创建一个临时表,用来保存执行结果:
    create table #tb(re varchar(8000))
    --得到结果:
    insert #tb EXEC xp_cmdshell 'dir *.exe'
    --处理结果
    declare @b varchar(8000)
    declare #pr cursor for select re from #tb  --定义游标
    open #pr  --打开游标
    fetch next from #pr into @b  --从游标中取数进行处理
    while @@fetch_status=0
    begin
      print @b  --此处换为你的处理语句
      fetch next from #pr into @b  --从游标中取数进行处理
    end
    close #pr
    deallocate #pr
    --删除临时表
    drop table #tb
      

  9.   

    create table #table(id int identity,txt varchar(1000))
    insert into #table(txt) exec master..xp_cmdshell 'dir c:\*.'
    select * from #table