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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Stored proc that exports to txt not working

Author  Topic 

sqlchiq
Posting Yak Master

133 Posts

Posted - 2008-08-12 : 16:59:44

I found this code online that exports a query to txt, but its not executing properly

CREATE Procedure BCP_Text_File
(
@table varchar(100),
@FileName varchar(100)
)
as
If exists(Select * from information_Schema.tables where table_name=@table)
Begin
Declare @str varchar(1000)
set @str='Exec Master..xp_Cmdshell ''bcp "Select * from '+db_name()+'..'+@table+'" queryout "'+@FileName+'" -c'''
Exec(@str)
end
else
Select 'The table '+@table+' does not exist in the database'



When I execute with this

EXEC BCP_Text_File 'greatwolfcleanedup','C:\emp.txt'


it results in...


User name not provided, either use -U to provide the user name or use -T for Trusted Connection
usage: bcp {dbtable | query} {in | out | queryout | format} datafile
[-m maxerrors] [-f formatfile] [-e errfile]
[-F firstrow] [-L lastrow] [-b batchsize]
[-n native type] [-c character type] [-w wide character type]
[-N keep non-text native] [-V file format version] [-q quoted identifier]
[-C code page specifier] [-t field terminator] [-r row terminator]
[-i inputfile] [-o outfile] [-a packetsize]
[-S server name] [-U username] [-P password]
[-T trusted connection] [-v version] [-R regional enable]
[-k keep null values] [-E keep identity values]
[-h "load hints"] [-x generate xml format file]
NULL



Not sure what that means, can anybody help?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-12 : 17:08:55
[code]DECLARE @Str VARCHAR(1000)

SET @Str = 'bcp "SELECT * FROM ' + QUOTENAME(DB_NAME()) + '..' + QUOTENAME(@Table) + '" queryout "' + @FileName + '" -c'

EXEC master..xp_CmdShell @Str[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-12 : 17:10:17
Are you also fuzzyip?
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=108431&whichpage=1

Tara?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-12 : 17:13:20
Not according to the IP addresses.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-12 : 17:15:02
What a coincidence they use same table/file work name "greatwolfcleanedup"!
Must be class mates then.


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

sqlchiq
Posting Yak Master

133 Posts

Posted - 2008-08-12 : 21:52:23
quote:
Originally posted by Peso

What a coincidence they use same table/file work name "greatwolfcleanedup"!
Must be class mates then.


E 12°55'05.25"
N 56°04'39.16"



this isn't homework, i know you guys dont like that. i changed names because i didnt like the other one


quote:
Originally posted by Peso

DECLARE	@Str VARCHAR(1000) 

SET @Str = 'bcp "SELECT * FROM ' + QUOTENAME(DB_NAME()) + '..' + QUOTENAME(@Table) + '" queryout "' + @FileName + '" -c'

EXEC master..xp_CmdShell @Str



E 12°55'05.25"
N 56°04'39.16"




I used this instead of the original code and executed with

EXEC BCP_Text_File 'greatwolfcleanedup','C:\emp.txt'



but it still returned with



User name not provided, either use -U to provide the user name or use -T for Trusted Connection
usage: bcp {dbtable | query} {in | out | queryout | format} datafile
[-m maxerrors] [-f formatfile] [-e errfile]
[-F firstrow] [-L lastrow] [-b batchsize]
[-n native type] [-c character type] [-w wide character type]
[-N keep non-text native] [-V file format version] [-q quoted identifier]
[-C code page specifier] [-t field terminator] [-r row terminator]
[-i inputfile] [-o outfile] [-a packetsize]
[-S server name] [-U username] [-P password]
[-T trusted connection] [-v version] [-R regional enable]
[-k keep null values] [-E keep identity values]
[-h "load hints"] [-x generate xml format file]
NULL




Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-13 : 00:54:01
Yes, you have to provide login information since bcp is an out-of-process application.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

sqlchiq
Posting Yak Master

133 Posts

Posted - 2008-08-13 : 11:02:20
quote:
Originally posted by Peso

Yes, you have to provide login information since bcp is an out-of-process application.



E 12°55'05.25"
N 56°04'39.16"




So like this...? trying now


DECLARE @Str VARCHAR(1000)

SET @Str = 'bcp "SELECT * FROM ' + QUOTENAME(DB_NAME()) + '..' + QUOTENAME(@Table) + '" queryout "' + @FileName + '" -c -U sqlchiq -P mypasswordhere'

EXEC master..xp_CmdShell @Str


if those were my login requirements of course :)
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-13 : 11:09:47
Also remember to supply server name!



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

sqlchiq
Posting Yak Master

133 Posts

Posted - 2008-08-13 : 11:10:34
It seemed like it worked...



EXEC BCP_Text_File 'greatwolfcleanedup','C:\emp.txt'


result was


NULL
Starting copy...
1000 rows successfully bulk-copied to host-file. Total received: 1000
1000 rows successfully bulk-copied to host-file. Total received: 2000
1000 rows successfully bulk-copied to host-file. Total received: 3000
1000 rows successfully bulk-copied to host-file. Total received: 4000
1000 rows successfully bulk-copied to host-file. Total received: 5000
1000 rows successfully bulk-copied to host-file. Total received: 6000
1000 rows successfully bulk-copied to host-file. Total received: 7000
1000 rows successfully bulk-copied to host-file. Total received: 8000
1000 rows successfully bulk-copied to host-file. Total received: 9000
1000 rows successfully bulk-copied to host-file. Total received: 10000
1000 rows successfully bulk-copied to host-file. Total received: 11000
1000 rows successfully bulk-copied to host-file. Total received: 12000
1000 rows successfully bulk-copied to host-file. Total received: 13000
1000 rows successfully bulk-copied to host-file. Total received: 14000
1000 rows successfully bulk-copied to host-file. Total received: 15000
1000 rows successfully bulk-copied to host-file. Total received: 16000
1000 rows successfully bulk-copied to host-file. Total received: 17000
1000 rows successfully bulk-copied to host-file. Total received: 18000
1000 rows successfully bulk-copied to host-file. Total received: 19000
1000 rows successfully bulk-copied to host-file. Total received: 20000
1000 rows successfully bulk-copied to host-file. Total received: 21000
1000 rows successfully bulk-copied to host-file. Total received: 22000
1000 rows successfully bulk-copied to host-file. Total received: 23000
1000 rows successfully bulk-copied to host-file. Total received: 24000
1000 rows successfully bulk-copied to host-file. Total received: 25000
1000 rows successfully bulk-copied to host-file. Total received: 26000
1000 rows successfully bulk-copied to host-file. Total received: 27000
1000 rows successfully bulk-copied to host-file. Total received: 28000
1000 rows successfully bulk-copied to host-file. Total received: 29000
1000 rows successfully bulk-copied to host-file. Total received: 30000
1000 rows successfully bulk-copied to host-file. Total received: 31000
1000 rows successfully bulk-copied to host-file. Total received: 32000
1000 rows successfully bulk-copied to host-file. Total received: 33000
1000 rows successfully bulk-copied to host-file. Total received: 34000
1000 rows successfully bulk-copied to host-file. Total received: 35000
1000 rows successfully bulk-copied to host-file. Total received: 36000
1000 rows successfully bulk-copied to host-file. Total received: 37000
1000 rows successfully bulk-copied to host-file. Total received: 38000
1000 rows successfully bulk-copied to host-file. Total received: 39000
1000 rows successfully bulk-copied to host-file. Total received: 40000
1000 rows successfully bulk-copied to host-file. Total received: 41000
1000 rows successfully bulk-copied to host-file. Total received: 42000
1000 rows successfully bulk-copied to host-file. Total received: 43000
1000 rows successfully bulk-copied to host-file. Total received: 44000
1000 rows successfully bulk-copied to host-file. Total received: 45000
1000 rows successfully bulk-copied to host-file. Total received: 46000
1000 rows successfully bulk-copied to host-file. Total received: 47000
1000 rows successfully bulk-copied to host-file. Total received: 48000
1000 rows successfully bulk-copied to host-file. Total received: 49000
1000 rows successfully bulk-copied to host-file. Total received: 50000
1000 rows successfully bulk-copied to host-file. Total received: 51000
1000 rows successfully bulk-copied to host-file. Total received: 52000
1000 rows successfully bulk-copied to host-file. Total received: 53000
1000 rows successfully bulk-copied to host-file. Total received: 54000
1000 rows successfully bulk-copied to host-file. Total received: 55000
1000 rows successfully bulk-copied to host-file. Total received: 56000
1000 rows successfully bulk-copied to host-file. Total received: 57000
1000 rows successfully bulk-copied to host-file. Total received: 58000
1000 rows successfully bulk-copied to host-file. Total received: 59000
1000 rows successfully bulk-copied to host-file. Total received: 60000
1000 rows successfully bulk-copied to host-file. Total received: 61000
1000 rows successfully bulk-copied to host-file. Total received: 62000
1000 rows successfully bulk-copied to host-file. Total received: 63000
1000 rows successfully bulk-copied to host-file. Total received: 64000
1000 rows successfully bulk-copied to host-file. Total received: 65000
1000 rows successfully bulk-copied to host-file. Total received: 66000
1000 rows successfully bulk-copied to host-file. Total received: 67000
1000 rows successfully bulk-copied to host-file. Total received: 68000
1000 rows successfully bulk-copied to host-file. Total received: 69000
1000 rows successfully bulk-copied to host-file. Total received: 70000
1000 rows successfully bulk-copied to host-file. Total received: 71000
1000 rows successfully bulk-copied to host-file. Total received: 72000
1000 rows successfully bulk-copied to host-file. Total received: 73000
1000 rows successfully bulk-copied to host-file. Total received: 74000
1000 rows successfully bulk-copied to host-file. Total received: 75000
1000 rows successfully bulk-copied to host-file. Total received: 76000
1000 rows successfully bulk-copied to host-file. Total received: 77000
1000 rows successfully bulk-copied to host-file. Total received: 78000
1000 rows successfully bulk-copied to host-file. Total received: 79000
1000 rows successfully bulk-copied to host-file. Total received: 80000
1000 rows successfully bulk-copied to host-file. Total received: 81000
1000 rows successfully bulk-copied to host-file. Total received: 82000
1000 rows successfully bulk-copied to host-file. Total received: 83000
1000 rows successfully bulk-copied to host-file. Total received: 84000
1000 rows successfully bulk-copied to host-file. Total received: 85000
1000 rows successfully bulk-copied to host-file. Total received: 86000
1000 rows successfully bulk-copied to host-file. Total received: 87000
1000 rows successfully bulk-copied to host-file. Total received: 88000
1000 rows successfully bulk-copied to host-file. Total received: 89000
1000 rows successfully bulk-copied to host-file. Total received: 90000
1000 rows successfully bulk-copied to host-file. Total received: 91000
1000 rows successfully bulk-copied to host-file. Total received: 92000
1000 rows successfully bulk-copied to host-file. Total received: 93000
1000 rows successfully bulk-copied to host-file. Total received: 94000
1000 rows successfully bulk-copied to host-file. Total received: 95000
1000 rows successfully bulk-copied to host-file. Total received: 96000
1000 rows successfully bulk-copied to host-file. Total received: 97000
1000 rows successfully bulk-copied to host-file. Total received: 98000
1000 rows successfully bulk-copied to host-file. Total received: 99000
1000 rows successfully bulk-copied to host-file. Total received: 100000
1000 rows successfully bulk-copied to host-file. Total received: 101000
1000 rows successfully bulk-copied to host-file. Total received: 102000
1000 rows successfully bulk-copied to host-file. Total received: 103000
1000 rows successfully bulk-copied to host-file. Total received: 104000
1000 rows successfully bulk-copied to host-file. Total received: 105000
1000 rows successfully bulk-copied to host-file. Total received: 106000
1000 rows successfully bulk-copied to host-file. Total received: 107000
1000 rows successfully bulk-copied to host-file. Total received: 108000
1000 rows successfully bulk-copied to host-file. Total received: 109000
1000 rows successfully bulk-copied to host-file. Total received: 110000
1000 rows successfully bulk-copied to host-file. Total received: 111000
1000 rows successfully bulk-copied to host-file. Total received: 112000
1000 rows successfully bulk-copied to host-file. Total received: 113000
1000 rows successfully bulk-copied to host-file. Total received: 114000
1000 rows successfully bulk-copied to host-file. Total received: 115000
1000 rows successfully bulk-copied to host-file. Total received: 116000
1000 rows successfully bulk-copied to host-file. Total received: 117000
1000 rows successfully bulk-copied to host-file. Total received: 118000
1000 rows successfully bulk-copied to host-file. Total received: 119000
1000 rows successfully bulk-copied to host-file. Total received: 120000
1000 rows successfully bulk-copied to host-file. Total received: 121000
1000 rows successfully bulk-copied to host-file. Total received: 122000
1000 rows successfully bulk-copied to host-file. Total received: 123000
1000 rows successfully bulk-copied to host-file. Total received: 124000
1000 rows successfully bulk-copied to host-file. Total received: 125000
1000 rows successfully bulk-copied to host-file. Total received: 126000
1000 rows successfully bulk-copied to host-file. Total received: 127000
1000 rows successfully bulk-copied to host-file. Total received: 128000
1000 rows successfully bulk-copied to host-file. Total received: 129000
1000 rows successfully bulk-copied to host-file. Total received: 130000
1000 rows successfully bulk-copied to host-file. Total received: 131000
1000 rows successfully bulk-copied to host-file. Total received: 132000
1000 rows successfully bulk-copied to host-file. Total received: 133000
1000 rows successfully bulk-copied to host-file. Total received: 134000
1000 rows successfully bulk-copied to host-file. Total received: 135000
1000 rows successfully bulk-copied to host-file. Total received: 136000
1000 rows successfully bulk-copied to host-file. Total received: 137000
1000 rows successfully bulk-copied to host-file. Total received: 138000
1000 rows successfully bulk-copied to host-file. Total received: 139000
1000 rows successfully bulk-copied to host-file. Total received: 140000
1000 rows successfully bulk-copied to host-file. Total received: 141000
1000 rows successfully bulk-copied to host-file. Total received: 142000
1000 rows successfully bulk-copied to host-file. Total received: 143000
1000 rows successfully bulk-copied to host-file. Total received: 144000
1000 rows successfully bulk-copied to host-file. Total received: 145000
1000 rows successfully bulk-copied to host-file. Total received: 146000
1000 rows successfully bulk-copied to host-file. Total received: 147000
1000 rows successfully bulk-copied to host-file. Total received: 148000
1000 rows successfully bulk-copied to host-file. Total received: 149000
1000 rows successfully bulk-copied to host-file. Total received: 150000
1000 rows successfully bulk-copied to host-file. Total received: 151000
1000 rows successfully bulk-copied to host-file. Total received: 152000
1000 rows successfully bulk-copied to host-file. Total received: 153000
1000 rows successfully bulk-copied to host-file. Total received: 154000
1000 rows successfully bulk-copied to host-file. Total received: 155000
1000 rows successfully bulk-copied to host-file. Total received: 156000
1000 rows successfully bulk-copied to host-file. Total received: 157000
1000 rows successfully bulk-copied to host-file. Total received: 158000
1000 rows successfully bulk-copied to host-file. Total received: 159000
1000 rows successfully bulk-copied to host-file. Total received: 160000
1000 rows successfully bulk-copied to host-file. Total received: 161000
1000 rows successfully bulk-copied to host-file. Total received: 162000
1000 rows successfully bulk-copied to host-file. Total received: 163000
1000 rows successfully bulk-copied to host-file. Total received: 164000
1000 rows successfully bulk-copied to host-file. Total received: 165000
1000 rows successfully bulk-copied to host-file. Total received: 166000
1000 rows successfully bulk-copied to host-file. Total received: 167000
1000 rows successfully bulk-copied to host-file. Total received: 168000
1000 rows successfully bulk-copied to host-file. Total received: 169000
1000 rows successfully bulk-copied to host-file. Total received: 170000
1000 rows successfully bulk-copied to host-file. Total received: 171000
1000 rows successfully bulk-copied to host-file. Total received: 172000
1000 rows successfully bulk-copied to host-file. Total received: 173000
1000 rows successfully bulk-copied to host-file. Total received: 174000
1000 rows successfully bulk-copied to host-file. Total received: 175000
1000 rows successfully bulk-copied to host-file. Total received: 176000
1000 rows successfully bulk-copied to host-file. Total received: 177000
1000 rows successfully bulk-copied to host-file. Total received: 178000
1000 rows successfully bulk-copied to host-file. Total received: 179000
1000 rows successfully bulk-copied to host-file. Total received: 180000
1000 rows successfully bulk-copied to host-file. Total received: 181000
1000 rows successfully bulk-copied to host-file. Total received: 182000
1000 rows successfully bulk-copied to host-file. Total received: 183000
1000 rows successfully bulk-copied to host-file. Total received: 184000
1000 rows successfully bulk-copied to host-file. Total received: 185000
1000 rows successfully bulk-copied to host-file. Total received: 186000
1000 rows successfully bulk-copied to host-file. Total received: 187000
1000 rows successfully bulk-copied to host-file. Total received: 188000
1000 rows successfully bulk-copied to host-file. Total received: 189000
1000 rows successfully bulk-copied to host-file. Total received: 190000
1000 rows successfully bulk-copied to host-file. Total received: 191000
1000 rows successfully bulk-copied to host-file. Total received: 192000
1000 rows successfully bulk-copied to host-file. Total received: 193000
1000 rows successfully bulk-copied to host-file. Total received: 194000
1000 rows successfully bulk-copied to host-file. Total received: 195000
1000 rows successfully bulk-copied to host-file. Total received: 196000
1000 rows successfully bulk-copied to host-file. Total received: 197000
1000 rows successfully bulk-copied to host-file. Total received: 198000
1000 rows successfully bulk-copied to host-file. Total received: 199000
1000 rows successfully bulk-copied to host-file. Total received: 200000
1000 rows successfully bulk-copied to host-file. Total received: 201000
1000 rows successfully bulk-copied to host-file. Total received: 202000
1000 rows successfully bulk-copied to host-file. Total received: 203000
1000 rows successfully bulk-copied to host-file. Total received: 204000
1000 rows successfully bulk-copied to host-file. Total received: 205000
1000 rows successfully bulk-copied to host-file. Total received: 206000
1000 rows successfully bulk-copied to host-file. Total received: 207000
1000 rows successfully bulk-copied to host-file. Total received: 208000
1000 rows successfully bulk-copied to host-file. Total received: 209000
1000 rows successfully bulk-copied to host-file. Total received: 210000
1000 rows successfully bulk-copied to host-file. Total received: 211000
1000 rows successfully bulk-copied to host-file. Total received: 212000
1000 rows successfully bulk-copied to host-file. Total received: 213000
1000 rows successfully bulk-copied to host-file. Total received: 214000
1000 rows successfully bulk-copied to host-file. Total received: 215000
1000 rows successfully bulk-copied to host-file. Total received: 216000
1000 rows successfully bulk-copied to host-file. Total received: 217000
1000 rows successfully bulk-copied to host-file. Total received: 218000
1000 rows successfully bulk-copied to host-file. Total received: 219000
1000 rows successfully bulk-copied to host-file. Total received: 220000
1000 rows successfully bulk-copied to host-file. Total received: 221000
1000 rows successfully bulk-copied to host-file. Total received: 222000
1000 rows successfully bulk-copied to host-file. Total received: 223000
1000 rows successfully bulk-copied to host-file. Total received: 224000
1000 rows successfully bulk-copied to host-file. Total received: 225000
1000 rows successfully bulk-copied to host-file. Total received: 226000
1000 rows successfully bulk-copied to host-file. Total received: 227000
1000 rows successfully bulk-copied to host-file. Total received: 228000
1000 rows successfully bulk-copied to host-file. Total received: 229000
1000 rows successfully bulk-copied to host-file. Total received: 230000
1000 rows successfully bulk-copied to host-file. Total received: 231000
1000 rows successfully bulk-copied to host-file. Total received: 232000
1000 rows successfully bulk-copied to host-file. Total received: 233000
1000 rows successfully bulk-copied to host-file. Total received: 234000
1000 rows successfully bulk-copied to host-file. Total received: 235000
1000 rows successfully bulk-copied to host-file. Total received: 236000
1000 rows successfully bulk-copied to host-file. Total received: 237000
1000 rows successfully bulk-copied to host-file. Total received: 238000
1000 rows successfully bulk-copied to host-file. Total received: 239000
1000 rows successfully bulk-copied to host-file. Total received: 240000
1000 rows successfully bulk-copied to host-file. Total received: 241000
1000 rows successfully bulk-copied to host-file. Total received: 242000
1000 rows successfully bulk-copied to host-file. Total received: 243000
1000 rows successfully bulk-copied to host-file. Total received: 244000
1000 rows successfully bulk-copied to host-file. Total received: 245000
1000 rows successfully bulk-copied to host-file. Total received: 246000
1000 rows successfully bulk-copied to host-file. Total received: 247000
1000 rows successfully bulk-copied to host-file. Total received: 248000
1000 rows successfully bulk-copied to host-file. Total received: 249000
1000 rows successfully bulk-copied to host-file. Total received: 250000
1000 rows successfully bulk-copied to host-file. Total received: 251000
1000 rows successfully bulk-copied to host-file. Total received: 252000
1000 rows successfully bulk-copied to host-file. Total received: 253000
1000 rows successfully bulk-copied to host-file. Total received: 254000
1000 rows successfully bulk-copied to host-file. Total received: 255000
1000 rows successfully bulk-copied to host-file. Total received: 256000
1000 rows successfully bulk-copied to host-file. Total received: 257000
1000 rows successfully bulk-copied to host-file. Total received: 258000
1000 rows successfully bulk-copied to host-file. Total received: 259000
1000 rows successfully bulk-copied to host-file. Total received: 260000
1000 rows successfully bulk-copied to host-file. Total received: 261000
1000 rows successfully bulk-copied to host-file. Total received: 262000
1000 rows successfully bulk-copied to host-file. Total received: 263000
1000 rows successfully bulk-copied to host-file. Total received: 264000
1000 rows successfully bulk-copied to host-file. Total received: 265000
1000 rows successfully bulk-copied to host-file. Total received: 266000
1000 rows successfully bulk-copied to host-file. Total received: 267000
1000 rows successfully bulk-copied to host-file. Total received: 268000
1000 rows successfully bulk-copied to host-file. Total received: 269000
1000 rows successfully bulk-copied to host-file. Total received: 270000
1000 rows successfully bulk-copied to host-file. Total received: 271000
1000 rows successfully bulk-copied to host-file. Total received: 272000
1000 rows successfully bulk-copied to host-file. Total received: 273000
1000 rows successfully bulk-copied to host-file. Total received: 274000
1000 rows successfully bulk-copied to host-file. Total received: 275000
1000 rows successfully bulk-copied to host-file. Total received: 276000
1000 rows successfully bulk-copied to host-file. Total received: 277000
1000 rows successfully bulk-copied to host-file. Total received: 278000
1000 rows successfully bulk-copied to host-file. Total received: 279000
1000 rows successfully bulk-copied to host-file. Total received: 280000
1000 rows successfully bulk-copied to host-file. Total received: 281000
1000 rows successfully bulk-copied to host-file. Total received: 282000
1000 rows successfully bulk-copied to host-file. Total received: 283000
1000 rows successfully bulk-copied to host-file. Total received: 284000
1000 rows successfully bulk-copied to host-file. Total received: 285000
1000 rows successfully bulk-copied to host-file. Total received: 286000
1000 rows successfully bulk-copied to host-file. Total received: 287000
1000 rows successfully bulk-copied to host-file. Total received: 288000
1000 rows successfully bulk-copied to host-file. Total received: 289000
1000 rows successfully bulk-copied to host-file. Total received: 290000
1000 rows successfully bulk-copied to host-file. Total received: 291000
1000 rows successfully bulk-copied to host-file. Total received: 292000
1000 rows successfully bulk-copied to host-file. Total received: 293000
1000 rows successfully bulk-copied to host-file. Total received: 294000
1000 rows successfully bulk-copied to host-file. Total received: 295000
1000 rows successfully bulk-copied to host-file. Total received: 296000
1000 rows successfully bulk-copied to host-file. Total received: 297000
1000 rows successfully bulk-copied to host-file. Total received: 298000
1000 rows successfully bulk-copied to host-file. Total received: 299000
1000 rows successfully bulk-copied to host-file. Total received: 300000
1000 rows successfully bulk-copied to host-file. Total received: 301000
1000 rows successfully bulk-copied to host-file. Total received: 302000
1000 rows successfully bulk-copied to host-file. Total received: 303000
1000 rows successfully bulk-copied to host-file. Total received: 304000
1000 rows successfully bulk-copied to host-file. Total received: 305000
1000 rows successfully bulk-copied to host-file. Total received: 306000
1000 rows successfully bulk-copied to host-file. Total received: 307000
1000 rows successfully bulk-copied to host-file. Total received: 308000
1000 rows successfully bulk-copied to host-file. Total received: 309000
1000 rows successfully bulk-copied to host-file. Total received: 310000
1000 rows successfully bulk-copied to host-file. Total received: 311000
1000 rows successfully bulk-copied to host-file. Total received: 312000
1000 rows successfully bulk-copied to host-file. Total received: 313000
1000 rows successfully bulk-copied to host-file. Total received: 314000
1000 rows successfully bulk-copied to host-file. Total received: 315000
1000 rows successfully bulk-copied to host-file. Total received: 316000
NULL
316041 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total : 5047 Average : (62619.58 rows per sec.)
NULL


But there's no file called emp.txt on the C drive where I told it write to.

I also tried to create a blank txt emp.txt where its suppose to write to as well and it didnt work.
Go to Top of Page

sqlchiq
Posting Yak Master

133 Posts

Posted - 2008-08-13 : 11:15:16
quote:
Originally posted by Peso

Also remember to supply server name!



E 12°55'05.25"
N 56°04'39.16"




I've added the server like so

DECLARE	@Str VARCHAR(1000) 

SET @Str = 'bcp "SELECT * FROM ' + QUOTENAME(DB_NAME()) + '..' + QUOTENAME(@Table) + '" queryout "' + @FileName + '"
-c -U sqlchiq -P mypasswordhere -S 34.3.234.134'

EXEC master..xp_CmdShell @Str



but it still is giving the write successfully but no file is there
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-13 : 11:17:09
"C:\" is relative to SQL Server, not your local machine.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

sqlchiq
Posting Yak Master

133 Posts

Posted - 2008-08-13 : 11:19:53
quote:
Originally posted by Peso

"C:\" is relative to SQL Server, not your local machine.



E 12°55'05.25"
N 56°04'39.16"




Ahhh, I see it now, thank you very much peso!
Go to Top of Page

sqlchiq
Posting Yak Master

133 Posts

Posted - 2008-08-13 : 11:22:42
There's probably no way to get it to write to the local machine is there?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-13 : 11:22:59
Thank you.
All I did was reading out loud from Books Online.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-13 : 11:24:12
Yes there is.
Use an UNC path name instead of local drive.
DECLARE	@Str VARCHAR(1000) 

SET @Str = 'bcp "SELECT * FROM ' + QUOTENAME(DB_NAME()) + '..' + QUOTENAME(@Table) + '" queryout "\\MyMachine\C$\' + @FileName + '"
-c -U sqlchiq -P mypasswordhere -S 34.3.234.134'

EXEC master..xp_CmdShell @Str
Also found in Books Online.


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -