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 |
scelamko
Constraint Violating Yak Guru
309 Posts |
Posted - 2007-06-13 : 09:59:09
|
GUys,I have the following stored proc which I use to export the data to excel spreadsheet.I need to develop a stored proc to import from 'csv' file, can anyone help me to do so.CREATE procedure spExport (@date1 varchar(30), @date2 varchar(30)) asset nocount onbegininsert into OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=\\ai-dc1\Project Management I\ADC Customer Central\Cook County IL COK\Excel Export Files\Output.xls;','SELECT alpha_doc_num, index_code_id, recorded_date, executiondate, amount FROM [DocumentDetails$]') select alpha_doc_num, index_code_id, recorded_date, executiondate, amountfrom vdocumentsource where recorded_date between @date1 and @date2insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=\\ai-dc1\Project Management I\ADC Customer Central\Cook County IL COK\Excel Export Files\Output.xls;','SELECT alpha_doc_num, name_last, party_type FROM [GrantorGrantees$]') select alpha_doc_num, name_last, party_typefrom ventitysource where seq_key in (select seq_key from vdocumentsource where recorded_date between @date1 and @date2)insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=\\ai-dc1\Project Management I\ADC Customer Central\Cook County IL COK\Excel Export Files\Output.xls;','SELECT alpha_doc_num, prop_id FROM [LegalDescription$]') select alpha_doc_num, prop_idfrom vlegalsource where seq_key in (select seq_key from vdocumentsource where recorded_date between @date1 and @date2)endset nocount offGOAlso the folder structure has many csv files, I want to be able to import all the csv files. Is there any way to write to a log within the stored proc.Any suggestions/inputs would help.Thanks |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-06-13 : 10:05:29
|
Why do you want to do this from Stored Proc? This can be better handled by creating DTS package.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-06-13 : 10:31:31
|
Have a look athttp://www.nigelrivett.net/SQLTsql/s_ProcessAllFilesInDir.htmlIt will call an sp for each file in a folder passing the filename and path and using a file mask.You should move the file to an archive folder after processing.This one does it for text files and calls an SP to just process the imported datahttp://www.nigelrivett.net/SQLTsql/ImportTextFiles.htmlYou could probably use bits of each.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|
|