DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
 
 
SITE SEARCH SQLUSA.com VIDEOS
 
 
SQL E/BOOKS   WORLD, USA & SQL NEWS   FORMAT
SCRIPTS SQL 2005 SQL 2008 ARTICLES
How to import filenames in a folder into a table?

Execute the following Microsoft SQL Server 2008 T-SQL script in SSMS Query Editor create a stored procedure which reads a file folder to get the filenames.

Warning article:

What are the security risks using cmdexec?

-- Create stored procedure with one input parameter

 

use AdventureWorks

go

create procedure procReadFolder @path sysname

as

begin

set nocount on

 

declare @dirContent table(

id int identity(1,1),

FileName sysname NULL

)

declare  @cmd nvarchar(512)

set @cmd = 'DIR /b ' + @path

 

insert into @dirContent

exec master..xp_cmdshell @cmd

 

select * from @dirContent

end

go

 

-- Execute stored procedure

declare @path sysname

set @path = 'F:\data\export\'

exec procReadFolder @path

go

Related article:

Import multiple Files to SQL Server using T-SQL 

 

Exam Prep 70-461
SQL 2016 DESIGN & PROGRAMMING
 
 
 
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE