On Nov 29, 12:19 am, Erland Sommarskog <
esq...@sommarskog.se> wrote:
> (
and...@webmail.co.za) writes:
>
> That's the blank line you would get before (10 row affected).
>
> SQLCMD is not intended to be an export tool.
>
True!
My MSSQL 2008 R2 table structure is:
CREATE TABLE [dbo].[myusertable](
[id] [bigint] IDENTITY(1,1) NOT NULL,
[username] [nvarchar](100) NOT NULL,
[idnumber] [nvarchar](255) NOT NULL,
[firstname] [nvarchar](100) NOT NULL,
[surtname] [nvarchar](100) NOT NULL,
CONSTRAINT [myusertable_id_pk] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
I've created a BCP solution which seems to do what I want. With this BCP command:
BCP "SELECT id, username, idnumber, firstname, surname + '~' FROM mydatabase.dbo.myusertable" queryout myusers.csv -f bcp.fmt -U dbuser -P dbpass -S dbserver
and this bcp.fmt format file:
10.0
5
1 SQLCHAR 0 1 "~" 1 id ""
2 SQLCHAR 0 100 "~" 2 username SQL_Latin1_General_CP1_CI_AS
3 SQLCHAR 0 100 "~" 3 idnumber SQL_Latin1_General_CP1_CI_AS
4 SQLCHAR 0 100 "~" 4 firstname SQL_Latin1_General_CP1_CI_AS
5 SQLCHAR 0 100 "\r\n" 5 surname SQL_Latin1_General_CP1_CI_AS
I get the following .csv file:
1~0~abc1212~7813424323082~Adam~Josef~
2~0~efg1234~6702034345548~Andrew~Smith~
3~0~zyx9876~753534544543~Fiona~Freeda~
3~0~ppx1289~6656565646085~Peter~Pan~
That .csv file "looks" perfect - when I open it in Windows Notepad (WinXP SP3) it displays correctly. But when I open it in a real text editor (UltraEdit) it opens as a hex file. What is causing this? Other "normal" .txt files open correctly in UltraEdit.