March 1, 2011 at 1:01 pm
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'.
?
*******************
What I lack in youth, I make up for in immaturity!
March 1, 2011 at 2:45 pm
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).
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
March 2, 2011 at 6:23 am
Well good grief, that was the problem! Kinda misleading error message! Thanks.
*******************
What I lack in youth, I make up for in immaturity!
March 2, 2011 at 6:36 am
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.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
September 7, 2012 at 8:47 am
Thank Odin for the internet -- and GSquared for this post! You just saved me a lot of time.
September 10, 2012 at 4:33 am
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!
November 1, 2012 at 3:42 am
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.
November 1, 2012 at 7:25 am
Maybe switch to a Powershell script.
*******************
What I lack in youth, I make up for in immaturity!
November 1, 2012 at 7:32 am
riswana (11/1/2012)
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.
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):
http://www.sqlservercentral.com/Forums/FindPost1378950.aspx
Lowell
November 1, 2012 at 7:40 am
riswana (11/1/2012)
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.
It's easy. Write a stored procedure and use BCP to call the stored procedure.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 15, 2015 at 8:18 am
Thank you again to all on this thread. Just saved me a lot of time and headache. 🙂
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply