Load TXT File using OPENROWSET functionFebruary 23, 2006
>>Script Language and Platform: T-SQL/ SQL SERVER
emp_id Width 9 fname Width 8 minit Width 1 lname Width 9 job_id Width 2 job_lvl Width 3 pub_id Width 4 hire_date Width 10To load this file in SQL Database we need to create Schema.ini file in The same subdirectory : C:STUDIESsql_serveropenrowset_txt_to_sql. Detailed description of Schema.ini file you can find in SQL SERVER book online. Schema.ini file for dts_2_11012005.txt should look like : [dts_2_11012005.txt] ColNameHeader=True Format=TabDelimited MaxScanRows=0 CharacterSet=ANSI Col1=emp_id Text Width 9 Col2=fname Text Width 8 Col3=minit Text Width 1 Col4=lname Text Width 9 Col5=job_id Text Width 2 Col6=job_lvl Text Width 3 Col7=pub_id Text Width 4 Col8=hire_date date Width 10Now we can run from Query Analyzer the code below: Author: Boris Bondar
Use pubs
SELECT * INTO txtmport FROM
OPENROWSET(''Microsoft.Jet.OLEDB.4.0'',
''Text;Database=C:STUDIESsql_serveropenrowset_txt_to_sql'',
''SELECT * FROM dts_2_11012005.txt'')
Disclaimer: We hope that the information on these script pages is
valuable to you. Your use of the information contained in these pages,
however, is at your sole risk. All information on these pages is provided
"as -is", without any warranty, whether express or implied, of its accuracy,
completeness, or fitness for a particular purpose...
Disclaimer Continued
Back to Database Journal Home |