Tuesday 30 June 2020

xp_cmdshell - Procedure expects parameter 'command_string' of type 'varchar'

https://www.sqlservercentral.com/forums/topic/xp_cmdshell-procedure-expects-parameter-command_string-of-type-varchar


Here are the contents of @Cmd (varchar(max)):
bcp "SELECT [Data] FROM myserver..dbo.PEC_Citrus_RptData where [Data] is not null order by [Data]" queryout "C:\Documents and Settings\All Users\Documents\Shared\OutputFile.txt" -c -t -T -S "MYMACHINE\MYINSTANCE"
Here's the code:
EXEC master..xp_cmdshell @Cmd ;
Here is the error:
Msg 214, Level 16, State 201, Procedure xp_cmdshell, Line 1
Procedure expects parameter 'command_string' of type 'varchar'.
?



You can't use varchar(max) with xp_cmdshell. Found that out the hard way. Try a finite number (I usually just go with either 1000 or 8000).

No comments:

Post a Comment

Note: only a member of this blog may post a comment.