Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-08-25 : 10:33:40
|
| Jon writes "I need help selecting the contents of a file. This is what I am trying to achieve.SELECT @filename = 'C:\filename.txt'In the following code snippet, I need for the parameter @filename be equal to the filename contents.DECLARE @filename varchar(8000)SELECT @filename = "string"-- Read the text file into the temp tableBULK INSERT Words FROM 'C:\filename.txt'...SELECT @filename = 'INSERT INTO Words(word) SELECT A="' + REPLACE(@filename, ' ', '"UNION ALL SELECT"') + '"'EXECUTE(@filename);..." |
|
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2006-08-25 : 11:59:00
|
| I'm not sure I understand your code, but if what you want to do is a bulk insert from a file that is passed as a parameter, then create a stored procedure with the file name as a parameter, and in the stored procedure create a dynamic SQL statement using the parameter, something like this:CREATE PROC LoadFile (@filename varchar(100))ASDECLARE @sql varchar(8000)SET @sql = 'BULK INSERT Northwind.dbo.[Order Details] FROM ''' + @filename + ''' WITH ( FIELDTERMINATOR = ''|'', ROWTERMINATOR = ''|\n'' )'EXEC sp_executesql @sql |
 |
|
|
|
|
|