Import Tab Delimited Text File with bcp


  
 USE [myDB]
GO
 
CREATE TABLE [dbo].[mySourceTable](
	[col1] [nvarchar](max) NULL,
	[Zip] [nvarchar](max) NULL,
	[col3] [nvarchar](max) NULL,
	[col4] [nvarchar](max) NULL,
	[col5] [nvarchar](max) NULL,
	[col6] [nvarchar](max) NULL,
	[col7] [nvarchar](max) NULL,
	[col8] [nvarchar](max) NULL,
	[col9] [nvarchar](max) NULL,
	[Latitude] [nvarchar](max) NULL,
	[Logitude] [nvarchar](max) NULL,
	[col12] [nvarchar](max) NULL
)  
GO

 
  

 
 --1.Generate XML format file 
 exec master..xp_cmdshell  'bcp  [myDB].[dbo].[mySourceTable] format nul -c -x -f  C:\temp\myFormatFileZip.xml -T  -t\t -r0x0A -S MC0555\SQL2014DEV';
 --Tab delimited and Row terminator -r0x0A

---2. bcp in with all data 
exec master..xp_cmdshell  'bcp  [myDB].[dbo].[mySourceTable] IN "C:\temp\US.txt" -f "C:\temp\myFormatFileZip.xml" -T -S MC0555\SQL2014DEV';

go


  
Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s