我有精美的作品查詢:混淆引號和雙引號中查詢
CREATE Procedure BCP_Text_File
(
@table varchar(100),
@FileName varchar(100)
)
AS
If exists(Select * from information_Schema.tables where [email protected])
Begin
Declare @str varchar(1000)
set @str='Exec Master..xp_Cmdshell ''bcp "Select * from '+db_name()+'..'[email protected]+'" queryout "'[email protected]+'" -c'''
Exec(@str)
end
else
Select 'The table '[email protected]+' does not exist in the database'
,但我需要在那裏補充一點:
select column_name
from information_schema.columns
where table_name = @table
order by ordinal_position
到目前爲止,我有:
alter Procedure BCP_Text_File
(
@table varchar(100),
@FileName varchar(100)
)
AS
If exists(Select * from information_Schema.tables where [email protected])
Begin
Declare @str varchar(1000)
set @str='Exec Master..xp_Cmdshell ''bcp "
select column_name
from information_schema.columns
where table_name = '+db_name()+'..'[email protected]+'
order by ordinal_position
Select * from '+db_name()+'..'[email protected]+'" queryout "'[email protected]+'" -c'''
Exec(@str)
end
else
Select 'The table '[email protected]+' does not exist in the database'
但我想我錯過了單引號和/或雙引號。我將添加此選擇語句,以便我的結果將字段名稱作爲第一行。
非常感謝您的幫助或指導。
調試101:將'EXEC(@str)'更改爲'PRINT(@str)' –
這些「'..」實際上是在查詢中嗎? –
@AaronBertrand對不起,我無法改變它。我不能編譯它 –