You are here: Re: Get files in different folder using sql « MsSQL Server « IT news, forums, messages
Re: Get files in different folder using sql

Posted by Erland Sommarskog on 08/09/06 22:05

(ntuyen01@yahoo.com) writes:
> I have a multiple files, but they are store in different directory on
> the server. I want open those files and insert it into the database
> using bcp.
>
> Example files structure dir:
> \\xyz\123\abc\text1.txt
> \\xyz\123\abc\text2.txt
> \\zyz\123\999\text2.txt
>
> bcp "dabase" in \\xyz\123\abc\text1.txt -c -S"servername' -Usa
> -Ppassword -T".
>
> is there away to loop througth each dir, get the files, excecute the
> bcp, then go to next folder.

You could do

INSERT #tmp(files)
EXEC master..xp_cmdshell 'DIR /B \\xyz\123\abc\*.tmp'

Then run a cursor of #tmp.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация