﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / T-SQL (SS2K5)  / xp_cmdshell - Procedure expects parameter 'command_string' of type 'varchar' / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 22 May 2013 17:32:43 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: xp_cmdshell - Procedure expects parameter 'command_string' of type 'varchar'</title><link>http://www.sqlservercentral.com/Forums/Topic1071530-338-1.aspx</link><description>[quote][b]riswana (11/1/2012)[/b][hr]Hi, I am having the same problem. My query string is greater than 8000 characters. I am using varchar(max). Can someone assist urgently with a result, please.[/quote]It's easy.  Write a stored procedure and use BCP to call the stored procedure.</description><pubDate>Thu, 01 Nov 2012 07:40:15 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: xp_cmdshell - Procedure expects parameter 'command_string' of type 'varchar'</title><link>http://www.sqlservercentral.com/Forums/Topic1071530-338-1.aspx</link><description>[quote][b]riswana (11/1/2012)[/b][hr]Hi, I am having the same problem. My query string is greater than 8000 characters. I am using varchar(max). Can someone assist urgently with a result, please.[/quote]On computers running Microsoft Windows XP or later, the maximum length of the string that you can use at the command prompt is 8191 characters.so you need to shorten up whatever is being passed as a query to your bcp.use the query string to insert the data into a view, and use bcp to select from the view instead.see this very similar post, where the Original poster needed to change his bcp query to select from  a view(or global temp table):[b][url]http://www.sqlservercentral.com/Forums/FindPost1378950.aspx[/url][/b]</description><pubDate>Thu, 01 Nov 2012 07:32:16 GMT</pubDate><dc:creator>Lowell</dc:creator></item><item><title>RE: xp_cmdshell - Procedure expects parameter 'command_string' of type 'varchar'</title><link>http://www.sqlservercentral.com/Forums/Topic1071530-338-1.aspx</link><description>Maybe switch to a Powershell script.</description><pubDate>Thu, 01 Nov 2012 07:25:50 GMT</pubDate><dc:creator>brosspaxedi</dc:creator></item><item><title>RE: xp_cmdshell - Procedure expects parameter 'command_string' of type 'varchar'</title><link>http://www.sqlservercentral.com/Forums/Topic1071530-338-1.aspx</link><description>Hi, I am having the same problem. My query string is greater than 8000 characters. I am using varchar(max). Can someone assist urgently with a result, please.</description><pubDate>Thu, 01 Nov 2012 03:42:00 GMT</pubDate><dc:creator>riswana</dc:creator></item><item><title>RE: xp_cmdshell - Procedure expects parameter 'command_string' of type 'varchar'</title><link>http://www.sqlservercentral.com/Forums/Topic1071530-338-1.aspx</link><description>I experienced this error, I now make sure I make nvarchar types with 4000 rather than using the max function.Also just a note on BCP. Ensure it's always on one line, else it won't work, won't even print, very annoying!</description><pubDate>Mon, 10 Sep 2012 04:33:41 GMT</pubDate><dc:creator>Nesuke</dc:creator></item><item><title>RE: xp_cmdshell - Procedure expects parameter 'command_string' of type 'varchar'</title><link>http://www.sqlservercentral.com/Forums/Topic1071530-338-1.aspx</link><description>Thank Odin for the internet -- and GSquared for this post! You just saved me a lot of time.</description><pubDate>Fri, 07 Sep 2012 08:47:14 GMT</pubDate><dc:creator>haleya</dc:creator></item><item><title>RE: xp_cmdshell - Procedure expects parameter 'command_string' of type 'varchar'</title><link>http://www.sqlservercentral.com/Forums/Topic1071530-338-1.aspx</link><description>You're welcome.It's probably because they haven't rewritten xp_cmdshell since SQL 2000, and that didn't have the max option available.</description><pubDate>Wed, 02 Mar 2011 06:36:48 GMT</pubDate><dc:creator>GSquared</dc:creator></item><item><title>RE: xp_cmdshell - Procedure expects parameter 'command_string' of type 'varchar'</title><link>http://www.sqlservercentral.com/Forums/Topic1071530-338-1.aspx</link><description>Well good grief, that was the problem! Kinda misleading error message! Thanks.</description><pubDate>Wed, 02 Mar 2011 06:23:48 GMT</pubDate><dc:creator>brosspaxedi</dc:creator></item><item><title>RE: xp_cmdshell - Procedure expects parameter 'command_string' of type 'varchar'</title><link>http://www.sqlservercentral.com/Forums/Topic1071530-338-1.aspx</link><description>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).</description><pubDate>Tue, 01 Mar 2011 14:45:53 GMT</pubDate><dc:creator>GSquared</dc:creator></item><item><title>xp_cmdshell - Procedure expects parameter 'command_string' of type 'varchar'</title><link>http://www.sqlservercentral.com/Forums/Topic1071530-338-1.aspx</link><description>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 1Procedure expects parameter 'command_string' of type 'varchar'.?</description><pubDate>Tue, 01 Mar 2011 13:01:10 GMT</pubDate><dc:creator>brosspaxedi</dc:creator></item></channel></rss>