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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-04-03 : 09:48:36
|
| Joel writes "SQL Server 2000logged on as 'sa'create table TESTTABLE (CUSTID char(15), CUST char(65))goinsert TESTTABLE select 'CUST1','Customer One'goDECLARE @FileName varchar(50), @bcpCommand varchar(2000)SET @FileName = 'c:\TESTOUT.csv' SET @bcpCommand = 'bcp "SELECT CUSTID, CUST FROM TESTTABLE" queryout "'SET @bcpCommand = @bcpCommand + @FileName + '" -U sa -P -c -t \,'select @bcpCommandSELECT CUSTID, CUST FROM TESTTABLEEXEC master..xp_cmdshell @bcpCommandI get the following results bcp "SELECT CUSTID, CUST FROM TESTTABLE" queryout "c:\TESTOUT.csv" -U sa -P -c -t \,CUSTID CUST --------------- ------------------------------------------------ CUST1 Customer One output ---------------------------SQLState = S0002, NativeError = 208Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'TESTTABLE'.SQLState = 37000, NativeError = 8180Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.NULLWhat is invalid about this??" |
|
|
graz
Chief SQLTeam Crack Dealer
4149 Posts |
Posted - 2002-04-03 : 09:48:36
|
Yeah, I've had the same problem :) xp_cmdshell is running this script in the default database. It basically logs in again. There's a bcp parameter to specify the database or you can
SELECT CUSTID, CUST FROM database..TESTTABLE |
 |
|
|
|
|
|