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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Too many arguments specified.

Author  Topic 

latture
Starting Member

24 Posts

Posted - 2013-02-06 : 10:53:16
Hello, fairly new here.

I'm getting a 'Msg 8144, Level 16, State 201, Procedure xp_cmdshell, Line 1 Procedure or function xp_cmdshell has too many arguments specified' error message when I run the bcp process below. Can anyone tell me why?

exec master..xp_cmdshell 'BCP "DECLARE @colnames VARCHAR(max);SELECT @colnames = COALESCE(@colnames + ',', '') + column_name from RPIUser_input.dbo.INFORMATION_SCHEMA.COLUMNS where TABLE_NAME=PartSiteTrans; select @colnames;" queryout c:\export\HeadersOnly.csv -c -T -SRQL', no_output

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-06 : 11:07:00
try like

DECLARE @BCPCmd varchar(8000)

SET @BCPCmd='BCP "DECLARE @colnames VARCHAR(max);SELECT @colnames = COALESCE(@colnames + ',', '') + column_name from RPIUser_input.dbo.INFORMATION_SCHEMA.COLUMNS where TABLE_NAME=PartSiteTrans; select @colnames;" queryout c:\export\HeadersOnly.csv -c -T -SRQL'

EXEC xp_cmdshell @BCPCmd,no_output



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

latture
Starting Member

24 Posts

Posted - 2013-02-06 : 11:41:12
Sweet, thanks.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-06 : 11:42:00
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -