A workaround to Pass HUGE Select through xp_cmdshell bcp Command — Use a Stored Procedure


You can use a stored procedure to wrap your huge SELECT inside and call that stored procedure from bcp.

Execute xp_cmdshell





declare @TargetFolder nvarchar(200)='c:\temp\'
, @FileName nvarchar(200)='myfile2.txt'

declare @Cmd nvarchar(max)
SET @Cmd =N' exec master..xp_cmdshell ''bcp "EXEC test1.dbo.usp_for_bcp " queryout "'+@TargetFolder +@FileName +'" -c -T  -t\t -S '+ @@servername + '''';
--print @Cmd
EXEC (@Cmd)





 
Advertisements

One Comment on “A workaround to Pass HUGE Select through xp_cmdshell bcp Command — Use a Stored Procedure”

  1. NAresh says:

    Nice article thanks a lot,


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s