怎么用存储过程得到e:\aaa\下面所有后缀名为.log的文件名称?

解决方案 »

  1.   

    这个是导入的.你稍微改改即可.--将某个目录上的Excel表,导入到数据库中--将所有的Excel文件放到一个目录中,假设为c:\test\,然后用下面的方法来做create table #t(fname varchar(260),depth int,isf bit)
    insert into #t exec master..xp_dirtree 'c:\test',1,1
    declare tb cursor for select fn='c:\test'+fname from #t
    where isf=1 and fname like '%.xls'  --取.xls文件(EXCEL)
    declare @fn varchar(8000)
    open tb
    fetch next from tb into @fn
    while @@fetch_status=0
    begin
    --下面是查询语句,需要根据你的情况改为插入语句
        --插入已有的表用:insert into 表 selct * from ...
        --创建表用:select * into 表 from ...
    set @fn='select * from 
    OPENROWSET(''MICROSOFT.JET.OLEDB.4.0'',''Excel 5.0;HDR=YES;DATABASE='+@fn+''',全部客户$)'
    exec(@fn)
    fetch next from tb into @fn
    end
    close tb
    deallocate tb
    drop table #t
      

  2.   

    EXEC MASTER..xp_cmdshell ' dir e:\aaa\*.LOG'以文本文件显示结果,这样应该可以
      

  3.   


    EXEC MASTER..xp_cmdshell ' dir e:\aaa\*.LOG'-------------------------------------------------------------------------ODBC: 消息 0,级别 16,状态 1
    无法装载 DLL xp_cmdshell.dll 或该 DLL 所引用的某一 DLL。原因: 126(找不到指定的模块。)。
    这是什么意思?
      

  4.   


    --开启xp_cmdshell
    --SQL Server blocked access to procedure 'xp_cmdshell'
    sp_configure 'show advanced options', 1
    go
    reconfigure
    go
    sp_configure 'xp_cmdshell', 1
    go
    reconfigure
    go
      

  5.   

    --开启xp_cmdshell
    --SQL Server blocked access to procedure 'xp_cmdshell'
    sp_configure 'show advanced options', 1
    go
    reconfigure
    go
    sp_configure 'xp_cmdshell', 1
    go
    reconfigure
    go
    EXEC MASTER..xp_cmdshell ' dir e:\aaa\*.LOG' 
    -----------------------------------------------------------我在客户机上通过查询分析器登录到数据库服务器执行以上语句:但是还是提示:ODBC: 消息 0,级别 16,状态 1
    无法装载 DLL xp_cmdshell.dll 或该 DLL 所引用的某一 DLL。原因: 126(找不到指定的模块。)。
    奇怪的是我在本地的客户机上执行就没有问题,存储过程返回了结果集
    这是什么原因呢?
      

  6.   

    本地开了xp_cmdshell,服务器没有开启xp_cmdshell