| Author |
Topic |
|
asm
Posting Yak Master
140 Posts |
Posted - 2010-02-12 : 06:37:12
|
| hi,how to insert the data in sql 2008 from .txt fileexample01,2,20100211,174624,1009,A000101,2,20100211,174631,1020,A000101,2,20100211,174635,1210,A000101,2,20100211,174648,1011,A000101,2,20100211,174651,1018,A0001 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-12 : 07:32:12
|
| Read about Bulk insert in SQL Server help fileMadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
asm
Posting Yak Master
140 Posts |
Posted - 2010-02-12 : 07:57:39
|
| Thanks... bulk insert is workingBULK INSERT Atten FROM 'C:\Temp2005\11.txt' WITH (FIELDTERMINATOR = ',',ROWTERMINATOR = '\n')pls guide what is error in this procedure--alter Procedure spInsertFromTextFile (@TextFile varchar(200))asBegin -- BULK INSERT Atten FROM 'C:\Temp2005\11.txt' WITH (FIELDTERMINATOR = ',',ROWTERMINATOR = '\n') BULK INSERT Atten FROM @TextFile WITH (FIELDTERMINATOR = ',',ROWTERMINATOR = '\n') --select * from AttenEnd |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-12 : 08:00:24
|
| you need to use dynamic EXEC ('BULK INSERT Atten FROM ' + @TextFile + 'WITH (FIELDTERMINATOR = ',',ROWTERMINATOR = '\n')')------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-12 : 08:33:53
|
quote: Originally posted by visakh16 you need to use dynamic EXEC ('BULK INSERT Atten FROM ' + @TextFile + 'WITH (FIELDTERMINATOR = ',',ROWTERMINATOR = '\n')')------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Dont forget about single quotes around the file nameMadhivananFailing to plan is Planning to fail |
 |
|
|
asm
Posting Yak Master
140 Posts |
Posted - 2010-02-13 : 05:00:28
|
| Alter Procedure spInsertFromTextFile (@TextFile varchar(200))asBegin Truncate Table Atten EXEC ('BULK INSERT Atten FROM ' + @TextFile + 'WITH (FIELDTERMINATOR = ',' ,ROWTERMINATOR = '\n')') select * from AttenEndshow an error message:Msg 102, Level 15, State 1, Procedure spInsertFromTextFile, Line 9Incorrect syntax near '\'. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-13 : 10:21:15
|
quote: Originally posted by asm Alter Procedure spInsertFromTextFile (@TextFile varchar(200))asBegin Truncate Table Atten EXEC ('BULK INSERT Atten FROM ' + @TextFile + 'WITH (FIELDTERMINATOR = ',' ,ROWTERMINATOR = ''\n'')') select * from AttenEndshow an error message:Msg 102, Level 15, State 1, Procedure spInsertFromTextFile, Line 9Incorrect syntax near '\'.
wat about the above------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
asm
Posting Yak Master
140 Posts |
Posted - 2010-02-14 : 02:23:41
|
| ALTER Procedure [dbo].[spInsertFromTextFile] (@TextFile varchar(200))asBegin EXEC ('BULK INSERT Atten FROM ' + @TextFile + 'WITH (FIELDTERMINATOR = ',' ,ROWTERMINATOR = ''\n'')')Endstill error show-Msg 102, Level 15, State 3, Procedure spInsertFromTextFile, Line 5Incorrect syntax near ')'. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-14 : 03:28:58
|
quote: Originally posted by asm ALTER Procedure [dbo].[spInsertFromTextFile] (@TextFile varchar(200))asBegin EXEC ('BULK INSERT Atten FROM ' + @TextFile + 'WITH (FIELDTERMINATOR = '','' ,ROWTERMINATOR = ''\n'')')Endstill error show-Msg 102, Level 15, State 3, Procedure spInsertFromTextFile, Line 5Incorrect syntax near ')'.
try this too------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
asm
Posting Yak Master
140 Posts |
Posted - 2010-02-14 : 03:45:06
|
| thanks.. its working... |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-14 : 03:47:58
|
welcome ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|