我使用这些命令但它只在我正常选择
时才有效SELECT INSTITUTE as INSTITUTE,
custno+ REPLICATE(' ', 16 - len(custno)) AS CUSTNO,
REPLICATE(' ', 32 - len(LASTNAME))+LASTNAME as LASTNAME
from TB_CUSTOMERS_DAILY
但是当在bcp实用程序的存储过程中使用时,它不起作用
USE [test]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[DO_TRANSACTION_AML]
AS
Declare @V_SQL_TMP VARCHAR (4000)
EXEC DO_LOG @MSG_IN = 'START DO_TRANSACTION_AML'
SET @V_SQL_TMP = 'bcp "select CUST_INSTITUTE,CUST_CUSTNO + REPLICATE (' ',
16 - len(CUST_CUSTNO)) from test.dbo.TB_TRANSACTIONS_AML" queryout
"C:\Users\nvhun\test\Transaction_AML.txt" -c -UTF8 -T -Slocalhost'
EXEC xp_cmdshell @V_SQL_TMP
答案 0 :(得分:1)
您应该将字符串变量中的引号加倍:
SET @V_SQL_TMP = 'bcp "select CUST_INSTITUTE,CUST_CUSTNO + REPLICATE ('' '',
16 - len(CUST_CUSTNO)) from test.dbo.TB_TRANSACTIONS_AML" queryout
"C:\Users\nvhun\test\Transaction_AML.txt" -c -UTF8 -T -Slocalhost'
(见REPLICATE附近)