2013-05-08 2 views
1

희망 사항 .. 다시 묻지는 않겠지 만 ...BCP 매개 변수 문제

여기에 SQL의 관련 섹션이 있습니다. 문제의 뷰 (vw_TempALlItems)는 이전 단계에서 생성 된 것으로, 예를 들어 컬럼 이름을 사용하여 생성되었고 & 등의 유형에주의를 기울였습니다. 뷰는 100 % 작동합니다 .. 그러나 BCP가 아니라 너무 많이 ..

--------------------------------------------------------------- 
DECLARE @bcpCommand varchar(2000) 

SET @bcpCommand = 'bcp vw_TempAllItems out 
"c:\FEPData.csv" -c -t -U USER -P PWD' 

EXEC master..xp_cmdshell @bcpCommand 
GO 

Drop View vw_TempAllItems 
GO 
---------------------------------------------------------------- 

내가 얻을 수있는 유일한 방법은 결과 창은

사람은 있습니다 .. BCP 명령 매개 변수

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] 
    [-d database name] 
    NULL 

및 생성되지 않습니다 CSV 파일을 보여줍니다입니까?

답변

1

잘 .. 그래도 그것을 알아 냈다

DECLARE @bcpCommand varchar(2000) 
    SET @bcpCommand = 'bcp ' + DB_NAME() + '..vw_TempAllItems out c:\FEPData.csv -c -t, -U User -P Pwd -S' + @@SERVERNAME 
    EXEC master..xp_cmdshell @bcpCommand 
    GO 
1

하나를 들어, 그것을 쿼리를 만드는 시도 :

또한
SET @bcpCommand = 'bcp "SELECT * FROM vw_TempAllItems" out 
"c:\FEPData.csv" -c -t -U USER -P PWD' 

, 체크 아웃, 귀하의 질문에 대답 : stackoverlow에 How to pass parameter to a bcp command in sql server합니다. 여기에 신경 수있는 사람들을위한

+0

감사를 작동하는 최종 결과입니다. 두 가지 문제가 있습니다. 심지어 tho 나는 문제의 서버에서 실행 중입니다. -S @@ ServerName으로 BCP에 알려야하며 파일 이름 주위에 따옴표가 맘에 들지 않았습니다. –