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
 General SQL Server Forums
 New to SQL Server Programming
 bcp syntax 2k8

Author  Topic 

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-13 : 13:59:44
OK...I must be going senile


bcp [PLS_WORK].[dbo].[ACHLDR_Stage_X150753] in "C:\PLS\Data\PRU_ALLIANCE.txt" -SNJROS1BBLD0304\DEV2K08 -T -c


What's wrong with that..in a dos prompt??

It's asking me for a password..I even tried my pwd..but to no avail

not like I don't do this millions of times...maybe I'm drunk and don't know it?

"Nah, Drunks more Fun" -- Phil Conners



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Kristen
Test

22859 Posts

Posted - 2010-08-13 : 14:01:41
Haven't tried BCP in 2K8 ... but

BCP -?

should give you the switches? or BOL will. Maybe something has changed subtly?

Sorry, only 101-level-help, but just in case you haven't scratched-that-itch it might help?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-13 : 14:03:03
I get

quote:

C:\>bcp [PLS_WORK].[dbo].[ACHLDR_Stage_X150753] out "C:\test.dat" -SNJROS1BBLD03
04\DEV2K08 -T -c
Password:
CTLIB Message: - L6/O8/S5/N3/5/0:
ct_connect(): directory service layer: internal directory control layer error: R
equested server name not found.
Establishing connection failed.



And I can ping the server

quote:

C:\>ping njros1bbld0304

Pinging njros1bbld0304.prudential.com [48.160.98.188] with 32 bytes of data:

Reply from 48.160.98.188: bytes=32 time=53ms TTL=120
Reply from 48.160.98.188: bytes=32 time=2ms TTL=120
Reply from 48.160.98.188: bytes=32 time=2ms TTL=120
Reply from 48.160.98.188: bytes=32 time=3ms TTL=120

Ping statistics for 48.160.98.188:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 2ms, Maximum = 53ms, Average = 15ms




Is it the "Friday I just don't care to see what's Wong"-itis?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-13 : 14:04:44
quote:
Originally posted by Kristen

Haven't tried BCP in 2K8 ... but

BCP -?

should give you the switches? or BOL will. Maybe something has changed subtly?

Sorry, only 101-level-help, but just in case you haven't scratched-that-itch it might help?



Dude, I've done this in my sleep...Of course I looked at BOL, and yes it also gave me the switches when I mokeyed arounfd in dos (or whatever they're calling it these days)

Thanks for the post though

And yes, this is my first 2k8 bcp


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-08-13 : 14:10:19
have to add named instance servername in quotes?

bcp [PLS_WORK].[dbo].[ACHLDR_Stage_X150753] in "C:\PLS\Data\PRU_ALLIANCE.txt" -S"NJROS1BBLD0304\DEV2K08" -T -c


just a guess. i always bcp OUT and Bulk Insert in...

let me try it on a named instance...
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-08-13 : 14:26:58
ok, it's not the "\" in the instance name. works for me with and without. but it does matter where i run it from. on my workstation i get failed login with the -T switch. from a different server it works.

Network Authority / SPN issue?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-13 : 14:49:43
well you shouldn't..depending on your authority

I'm sa on the box, and I'm using Windows security

When I run



DECLARE @cmd varchar(8000)
SET @cmd = 'bcp [PLS_WORK].[dbo].[ACHLDR_Stage_X150753] out D:\Test.dat -SNJROS1BBLD0304\DEV2K08 -T -c'
exec master..xp_cmdshell @cmd



I get

[/code]
output
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQLState = 37000, NativeError = 4060
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open database "[PLS_WORK]" requested by the login. The login failed.
NULL

(3 row(s) affected)
[/code]

Time for Tequila Shooters


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-13 : 14:53:44
I ran this


DECLARE @cmd varchar(8000)
SET @cmd = 'bcp [DIVERSITY].[dbo].[USERS] out D:\Test.dat -SPAERSCBVD0403\dev -T -c'
exec master..xp_cmdshell @cmd


And got this?



output
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQLState = 28000, NativeError = 18456
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'PRUDENTIAL\NJROS1BBLD0304$'.
NULL

(3 row(s) affected)



So it is running under the context of the connection....from SSMS


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-08-13 : 14:57:39
xp_cmdshell runs as sql service account
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-13 : 15:05:14
yes, I knew that

I remove the brackets from schema.owner.table
and now that works for cmdshell

I think I might be running the wrong version of bcp?

There are new switched in 2k8 that don't appear in the prompt
like -d


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-13 : 15:21:31
funny...I only see bcp from sybase on my laptop

Doesn't it get installed with the client tools?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-13 : 16:27:18
Yes it does.

If you've got Sybase bcp, and either the SQL Server bcp is not in the path or isn't high enough in the path, then the Sybase one will run.

Fix your path.

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

Subscribe to my blog
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-08-13 : 16:39:00
haha yeah, that would do it. or you can call it with the full path

C:\Program Files\Microsoft SQL Server\100\Tools\Binn\bcp.exe [PLS_WORK].[dbo].[ACHLDR_Stage_X150753] in "C:\PLS\Data\PRU_ALLIANCE.txt" -S"NJROS1BBLD0304\DEV2K08" -T -c
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-13 : 16:42:20
I forgot to mention that once you fix the path, the SQL Server service will need to be restarted in order to see the change. The path gets loaded into its memory, so it won't see the new path until the next startup.

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

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-13 : 16:43:02
Dude, so you work on Sybase, DB2, Oracle, and SQL Server? I sure hope they pay you tons!

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

Subscribe to my blog
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-16 : 10:24:04
quote:


Phil: I'm a god.
Rita: You're God?
Phil: I'm a god. I'm not the God... I don't think.

Rita: You're not a god. You can take my word for it; this is twelve years of Catholic school talking.

Phil: Well maybe the real God uses tricks, you know? Maybe he's not omnipotent. He's just been around so long he knows everything.




>> He's just been around so long

That would be me...

but I do need a new gig

They (Server Ops/Network/Software Push??) have been messing around quite a bit lately...they just pushed Lotus Notes 8.x...and everything is a mess...Now my T60 is craaaaaawwwwling....



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-16 : 10:25:44
quote:
Originally posted by tkizer

I forgot to mention that once you fix the path, the SQL Server service will need to be restarted in order to see the change. The path gets loaded into its memory, so it won't see the new path until the next startup.



It's just on my client...I was actually helping a SQL server "expert", near shore (IRL), trying to figure out how to get data into a table

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-16 : 10:26:57
quote:
Originally posted by tkizer

Dude, so you work on Sybase, DB2, Oracle, and SQL Server? I sure hope they pay you tons!

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

Subscribe to my blog



Good to know...define "tons"



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-16 : 10:41:08
Oh, for the love of god


"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\bcp.exe" PLS_WORK.dbo.ACHLDR_Stage_X150753 in "C:\PLS\Data\PRU_ALLIANCE.txt" -SNJROS1BBLD0304\DEV2K08 -T -c



Success...time for a beer...


Starting copy...
SQLState = 22001, NativeError = 0
Error = [Microsoft][SQL Server Native Client 10.0]String data, right truncation
1000 rows sent to SQL Server. Total sent: 1000
1000 rows sent to SQL Server. Total sent: 2000

2207 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total : 391 Average : (5644.50 rows per sec.)

C:\>
C:\>



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-16 : 11:08:34
quote:

Sajesh,

To make life easier...take your excel spreadsheets, and make sure the have data in a format that matches the columns in the database

create a staging table, the use bcp.

The do a join on these 2 columns...the staging table does not need an index because it will be scanned anyway (being the driver)

USE [PLS_Work]
GO

CREATE TABLE [dbo].[ACHLDR_Stage_X150753](
[acct_ledger] [char](3),
[acct_num] [char](5),

) ON [PRIMARY]
GO

Then do the bcp load from cmdshell (>>Run >> CMD). This creates a dos window

Then execute

"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\bcp.exe" PLS_WORK.dbo.ACHLDR_Stage_X150753 in "C:\PLS\Data\PRU_ALLIANCE.txt" -SNJROS1BBLD0304\DEV2K08 -T -c

You do this in a dos prompt so it makes sure it uses your credentials, and uses your drive mappings

Then, do your query

SELECT *
FROM PLS.dbo.ACHLDR a
INNER JOIN PLS_WORK.dbo.ACHLDR_Stage_X150753 xxx
ON a.acct_ledger = xxx.acct_ledger
AND a.acct_num = xxx.acct_num

The other way you were trying..

SELECT * FROM ACHLDR
WHERE acct_num+acct_ledger IN (
SELECT 'XYZ1123' UNION ALL
SELECT 'XYZ1123' UNION ALL
..
..
..
20,000 more times
)

Will only cause a scan...and I wonder about an upper limit on the size of a sql query

To get the data out, I can help you with that as well...

First things first





This was a query that was never coming home...his reply IM

quote:

yeah got it..that was quick.I modified the query to include all the rows from the stage table..




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-08-16 : 11:19:53
Clearly naming the database "Please work ... Pretty pretty please work" was the trick you needed?!! {:D]
Go to Top of Page
    Next Page

- Advertisement -