<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; Running Batch File Using T-SQL &#8211; xp_cmdshell bat file</title>
	<atom:link href="http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Fri, 10 Feb 2012 02:12:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Jit</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-246273</link>
		<dc:creator><![CDATA[Jit]]></dc:creator>
		<pubDate>Tue, 31 Jan 2012 17:46:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-246273</guid>
		<description><![CDATA[Hi Pinal,
   Please suggest me how to export data to Excel or CSV file format using bcp with Column Names]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,<br />
   Please suggest me how to export data to Excel or CSV file format using bcp with Column Names</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: radio</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-185430</link>
		<dc:creator><![CDATA[radio]]></dc:creator>
		<pubDate>Sun, 30 Oct 2011 12:02:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-185430</guid>
		<description><![CDATA[This post couldnt be more precise!]]></description>
		<content:encoded><![CDATA[<p>This post couldnt be more precise!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kalaingar</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-167755</link>
		<dc:creator><![CDATA[kalaingar]]></dc:creator>
		<pubDate>Tue, 13 Sep 2011 12:54:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-167755</guid>
		<description><![CDATA[hi i am using in my php project as a database sqlserver when i run the page i got this below error

this is error

Unable to coonect to server :TOMEDES\SQLEXPRESS IN D:\htdocs\pmo\getattandance.php line 18 couldn&#039;t connect to sql server on TOMEDES\SQLEXPREESS


my php code is

&lt;?php
require_once(&#039;include/include.php&#039;);
set_time_limit(0);

$lastdate = getlastdate();
for($inte=0;$inte= strtotime($curdate))
$edate = $curdate;
//echo $sdate.&quot;===&quot;.$edate; die;
if(strtotime($sdate) &gt;= strtotime($edate))
die;
//$sdate = &#039;Aug 16 2011 12:00AM&#039;;
//$edate = &#039;Aug 17 2011 12:00AM&#039;;
$query = &quot;SELECT * FROM $table_name where AttendanceDate &gt; &#039;&quot;.$sdate.&quot;&#039; and AttendanceDate queryToArray($sql);
}
}

function getlastdate()
{
global $db;
$sql=&quot;SELECT AttendanceDate FROM attendancelog order by id desc limit 1&quot;;
$list=$db-&gt;queryToArray($sql);
return $list;

}


?&gt;]]></description>
		<content:encoded><![CDATA[<p>hi i am using in my php project as a database sqlserver when i run the page i got this below error</p>
<p>this is error</p>
<p>Unable to coonect to server :TOMEDES\SQLEXPRESS IN D:\htdocs\pmo\getattandance.php line 18 couldn&#8217;t connect to sql server on TOMEDES\SQLEXPREESS</p>
<p>my php code is</p>
<p>&lt;?php<br />
require_once(&#039;include/include.php&#039;);<br />
set_time_limit(0);</p>
<p>$lastdate = getlastdate();<br />
for($inte=0;$inte= strtotime($curdate))<br />
$edate = $curdate;<br />
//echo $sdate.&#8221;===&#8221;.$edate; die;<br />
if(strtotime($sdate) &gt;= strtotime($edate))<br />
die;<br />
//$sdate = &#8216;Aug 16 2011 12:00AM&#8217;;<br />
//$edate = &#8216;Aug 17 2011 12:00AM&#8217;;<br />
$query = &#8220;SELECT * FROM $table_name where AttendanceDate &gt; &#8216;&#8221;.$sdate.&#8221;&#8216; and AttendanceDate queryToArray($sql);<br />
}<br />
}</p>
<p>function getlastdate()<br />
{<br />
global $db;<br />
$sql=&#8221;SELECT AttendanceDate FROM attendancelog order by id desc limit 1&#8243;;<br />
$list=$db-&gt;queryToArray($sql);<br />
return $list;</p>
<p>}</p>
<p>?&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: prakash</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-139225</link>
		<dc:creator><![CDATA[prakash]]></dc:creator>
		<pubDate>Mon, 06 Jun 2011 13:24:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-139225</guid>
		<description><![CDATA[plz help me I m in trouble..I hv made project in VS 2010 DB sqlserver 2008 windows form and make EXE file.I hv install Exe file but I think there is some DB connection error.plz tell me what should I need and what should I Do to run this Exe properly....
reply me as soon as posible...]]></description>
		<content:encoded><![CDATA[<p>plz help me I m in trouble..I hv made project in VS 2010 DB sqlserver 2008 windows form and make EXE file.I hv install Exe file but I think there is some DB connection error.plz tell me what should I need and what should I Do to run this Exe properly&#8230;.<br />
reply me as soon as posible&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mei</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-124341</link>
		<dc:creator><![CDATA[Mei]]></dc:creator>
		<pubDate>Tue, 22 Mar 2011 05:19:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-124341</guid>
		<description><![CDATA[Hi Pinal,

I have problem adding a SQL job with the below command:-

exec master.dbo.xp_cmdshell &#039;&quot;C:\Program Files\WinZip\winzip32.exe&quot; /autorunjobfile S:\POSTOFF\_SCR\extract_encryption.wjf&#039;

The job can be started but it is like goin into a loop and will not complete.

Can you help me on this?]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>I have problem adding a SQL job with the below command:-</p>
<p>exec master.dbo.xp_cmdshell &#8216;&#8221;C:\Program Files\WinZip\winzip32.exe&#8221; /autorunjobfile S:\POSTOFF\_SCR\extract_encryption.wjf&#8217;</p>
<p>The job can be started but it is like goin into a loop and will not complete.</p>
<p>Can you help me on this?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeevangurajala</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-119129</link>
		<dc:creator><![CDATA[Jeevangurajala]]></dc:creator>
		<pubDate>Fri, 18 Feb 2011 10:33:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-119129</guid>
		<description><![CDATA[Hi Dave,

  I have an issue, where my storedprocedure calling a batch file and it consist of application exe to trigger email notification.

 I am using an administrator account both in OS and SQL level and executing the SP. 

my sp is like this..

CREATE Procedure [dbo].[spemailpassword_exam]    
 @empno int    
As       
 Declare @icount int    
 --DECLARE @ssql varchar(255)    
    
  BEGIN    
             INSERT INTO dbo.CanPay_Email_Info(EmpNo,EmailTemplate)    
       Values(@empno,8)    
SET @icount=0    
   SELECT @icount=@icount + 1    
  END    
    
 IF @icount &gt; 0    
   BEGIN    
     
   EXEC master.dbo.xp_cmdshell &#039;D:\jeevan\OTTest\target\jeevan.bat&#039;  
  
   --SELECT @ssql = &#039;exec master.dbo.xp_cmdshell &#039;D:\jeevan\OTTest\target\jeevan.HRIT.CanPayroll.EmailNotifications&#039;&#039;    
           --EXEC (@ssql)    
            
      END]]></description>
		<content:encoded><![CDATA[<p>Hi Dave,</p>
<p>  I have an issue, where my storedprocedure calling a batch file and it consist of application exe to trigger email notification.</p>
<p> I am using an administrator account both in OS and SQL level and executing the SP. </p>
<p>my sp is like this..</p>
<p>CREATE Procedure [dbo].[spemailpassword_exam]<br />
 @empno int<br />
As<br />
 Declare @icount int<br />
 &#8211;DECLARE @ssql varchar(255)    </p>
<p>  BEGIN<br />
             INSERT INTO dbo.CanPay_Email_Info(EmpNo,EmailTemplate)<br />
       Values(@empno,8)<br />
SET @icount=0<br />
   SELECT @icount=@icount + 1<br />
  END    </p>
<p> IF @icount &gt; 0<br />
   BEGIN    </p>
<p>   EXEC master.dbo.xp_cmdshell &#8216;D:\jeevan\OTTest\target\jeevan.bat&#8217;  </p>
<p>   &#8211;SELECT @ssql = &#8216;exec master.dbo.xp_cmdshell &#8216;D:\jeevan\OTTest\target\jeevan.HRIT.CanPayroll.EmailNotifications&#8221;<br />
           &#8211;EXEC (@ssql)    </p>
<p>      END</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CK</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-101539</link>
		<dc:creator><![CDATA[CK]]></dc:creator>
		<pubDate>Mon, 22 Nov 2010 19:14:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-101539</guid>
		<description><![CDATA[ALTER PROCEDURE [dbo].[ProcessXMLCSVTest1]
as
declare @filename varchar(255)


BEGIN
INSERT INTO [Test].[dbo].[XMLCSVTable1]
           ([ID]
           ,[RollNo]
           ,[SchoolNo]
           ,[SchoolAdd])
    SELECT  convert (varchar(10),a.[ID] ,101),convert (varchar(10),a.[RollNo] ,101),
    convert (varchar(10),a.[SchoolNo] ,101),convert (varchar(10),a.[SchoolAdd] ,101) 
    FROM OPENROWSET( BULK  &#039;C:\Desktop\Chandresh\CSVInput.txt&#039; ,
  FORMATFILE = &#039;C:\Chandresh\CSVXML.txt&#039;) AS a;
  end

This is my Store Proc. i created Variable @FileName for C:\Desktop\Chandresh\CSVInput.txt&#039;  this path. 
My Text File Path is Dynamic .so can anyone help me what should i do for mY Dynamic Text File path.
i will be appriciate for comment.
Thanks!!!!]]></description>
		<content:encoded><![CDATA[<p>ALTER PROCEDURE [dbo].[ProcessXMLCSVTest1]<br />
as<br />
declare @filename varchar(255)</p>
<p>BEGIN<br />
INSERT INTO [Test].[dbo].[XMLCSVTable1]<br />
           ([ID]<br />
           ,[RollNo]<br />
           ,[SchoolNo]<br />
           ,[SchoolAdd])<br />
    SELECT  convert (varchar(10),a.[ID] ,101),convert (varchar(10),a.[RollNo] ,101),<br />
    convert (varchar(10),a.[SchoolNo] ,101),convert (varchar(10),a.[SchoolAdd] ,101)<br />
    FROM OPENROWSET( BULK  &#8216;C:\Desktop\Chandresh\CSVInput.txt&#8217; ,<br />
  FORMATFILE = &#8216;C:\Chandresh\CSVXML.txt&#8217;) AS a;<br />
  end</p>
<p>This is my Store Proc. i created Variable @FileName for C:\Desktop\Chandresh\CSVInput.txt&#8217;  this path.<br />
My Text File Path is Dynamic .so can anyone help me what should i do for mY Dynamic Text File path.<br />
i will be appriciate for comment.<br />
Thanks!!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-99027</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Thu, 11 Nov 2010 08:27:50 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-99027</guid>
		<description><![CDATA[You need ask this question in mysql forums]]></description>
		<content:encoded><![CDATA[<p>You need ask this question in mysql forums</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joseph</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-98759</link>
		<dc:creator><![CDATA[Joseph]]></dc:creator>
		<pubDate>Tue, 09 Nov 2010 21:54:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-98759</guid>
		<description><![CDATA[any equivalent command in MYSQL ?]]></description>
		<content:encoded><![CDATA[<p>any equivalent command in MYSQL ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jai Tripathi</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-93581</link>
		<dc:creator><![CDATA[Jai Tripathi]]></dc:creator>
		<pubDate>Sat, 16 Oct 2010 07:32:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-93581</guid>
		<description><![CDATA[Dear Pinal,

I want to run a batch file
exec master..xp_cmdshell &#039;c:\psftp.bat&#039;

containing secured FTP command

psftp 172.16.173.226 -l sftpuser -pw 12345 -b cmdFile.txt

but it gives me the following error
C:\&gt;psftp 172.16.173.226 -l sftpuser -pw 12345 -b cmdFile.txt 
Fatal: Network error: Software caused connection abort
NULL

when i am just double clicking the batch file it works fine

Please tell me the procedure to run the same.

Regards]]></description>
		<content:encoded><![CDATA[<p>Dear Pinal,</p>
<p>I want to run a batch file<br />
exec master..xp_cmdshell &#8216;c:\psftp.bat&#8217;</p>
<p>containing secured FTP command</p>
<p>psftp 172.16.173.226 -l sftpuser -pw 12345 -b cmdFile.txt</p>
<p>but it gives me the following error<br />
C:\&gt;psftp 172.16.173.226 -l sftpuser -pw 12345 -b cmdFile.txt<br />
Fatal: Network error: Software caused connection abort<br />
NULL</p>
<p>when i am just double clicking the batch file it works fine</p>
<p>Please tell me the procedure to run the same.</p>
<p>Regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rajiv</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-90082</link>
		<dc:creator><![CDATA[Rajiv]]></dc:creator>
		<pubDate>Wed, 29 Sep 2010 12:39:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-90082</guid>
		<description><![CDATA[Hi Pinal
I am using stored procedure (cmd_shell) to run an .exe file but it is just keep executing. please tell me how can i run an exe file from SQL Server 2005.]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal<br />
I am using stored procedure (cmd_shell) to run an .exe file but it is just keep executing. please tell me how can i run an exe file from SQL Server 2005.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Palaksha P N</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-89319</link>
		<dc:creator><![CDATA[Palaksha P N]]></dc:creator>
		<pubDate>Fri, 24 Sep 2010 22:49:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-89319</guid>
		<description><![CDATA[Hi, 

Thank you, I have setup a job to run batch file. works very well.]]></description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>Thank you, I have setup a job to run batch file. works very well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keyun</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-85799</link>
		<dc:creator><![CDATA[Keyun]]></dc:creator>
		<pubDate>Tue, 31 Aug 2010 16:03:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-85799</guid>
		<description><![CDATA[Hi Pinal, 

First of Nice Article, Learn lot from it. 

Question:

Is there a way we can supply UserName and PWD when we use xp_cmdshell with COPY command?

Please let me know your thoughts

Thanks
Keyun]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal, </p>
<p>First of Nice Article, Learn lot from it. </p>
<p>Question:</p>
<p>Is there a way we can supply UserName and PWD when we use xp_cmdshell with COPY command?</p>
<p>Please let me know your thoughts</p>
<p>Thanks<br />
Keyun</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: marcelo</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-79100</link>
		<dc:creator><![CDATA[marcelo]]></dc:creator>
		<pubDate>Wed, 07 Jul 2010 16:03:47 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-79100</guid>
		<description><![CDATA[Hi Pinal,

I developed a job, with the next sentense into them:

exec master..xp_cmdshell &#039;del c:\test\*.bak&#039;

and recived the next error:

Executed as user: PUENTEDBAMAIN\SYSTEM. The process could not be created for step 1 of job 0x33CD203A90451545B466D4CCAA10428C (reason: The system cannot find the file specified).  The step failed.

I have SQL Server 2000, with the last SP.

The job runs with the sa user.

Thanks
Marcelo]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>I developed a job, with the next sentense into them:</p>
<p>exec master..xp_cmdshell &#8216;del c:\test\*.bak&#8217;</p>
<p>and recived the next error:</p>
<p>Executed as user: PUENTEDBAMAIN\SYSTEM. The process could not be created for step 1 of job 0x33CD203A90451545B466D4CCAA10428C (reason: The system cannot find the file specified).  The step failed.</p>
<p>I have SQL Server 2000, with the last SP.</p>
<p>The job runs with the sa user.</p>
<p>Thanks<br />
Marcelo</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: neha</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-75658</link>
		<dc:creator><![CDATA[neha]]></dc:creator>
		<pubDate>Fri, 11 Jun 2010 13:48:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-75658</guid>
		<description><![CDATA[Hi Pinal, 
I have an macro in access that I want to execute from a SQL Server trigger using xp_cmdshell. I am able to run other batch files from xp_cmdshell (runs under ntauthority\system account), but not this one. It shows executing query and kind of hangs..The batch file just creates a csv file for me. How can I execute it from SQL Server?? Is there a way I can invoke a Windows task (disabled) from SQL server trigger???
PLease suggest
Thanks
Neha]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,<br />
I have an macro in access that I want to execute from a SQL Server trigger using xp_cmdshell. I am able to run other batch files from xp_cmdshell (runs under ntauthority\system account), but not this one. It shows executing query and kind of hangs..The batch file just creates a csv file for me. How can I execute it from SQL Server?? Is there a way I can invoke a Windows task (disabled) from SQL server trigger???<br />
PLease suggest<br />
Thanks<br />
Neha</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James knapp</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-74394</link>
		<dc:creator><![CDATA[James knapp]]></dc:creator>
		<pubDate>Wed, 02 Jun 2010 13:54:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-74394</guid>
		<description><![CDATA[Save the .xls file as a comma delimited .txt file and then run something like this:

bulk insert dbo.table
from &#039;c:\folder\folder\filename.txt&#039;
with 
(
FIELDTERMINATOR = &#039;,&#039;,
ROWTERMINATOR = &#039;\n&#039;,
FIRSTROW=2
)
File must be on the SQL Server to work.]]></description>
		<content:encoded><![CDATA[<p>Save the .xls file as a comma delimited .txt file and then run something like this:</p>
<p>bulk insert dbo.table<br />
from &#8216;c:\folder\folder\filename.txt&#8217;<br />
with<br />
(<br />
FIELDTERMINATOR = &#8216;,&#8217;,<br />
ROWTERMINATOR = &#8216;\n&#8217;,<br />
FIRSTROW=2<br />
)<br />
File must be on the SQL Server to work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nith</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-74339</link>
		<dc:creator><![CDATA[Nith]]></dc:creator>
		<pubDate>Wed, 02 Jun 2010 08:39:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-74339</guid>
		<description><![CDATA[Dear buddies,

I have around 200 bsps to be run from command prompt so I created it as a bat file but its not working.

Any suggestion? I added a semicolon at the end of each bcp command.

Eg:

bcp &quot;SELECT * FROM dbname.schema.tablename&quot; queryout C:\tablename.txt -c -U login -P password -S servername;

bcp &quot;SELECT * FROM dbname.schema.tablename&quot; queryout C:\tablename.txt -c -U login -P password -S servername;

 each with different table names and file names

Please advice.

Nith]]></description>
		<content:encoded><![CDATA[<p>Dear buddies,</p>
<p>I have around 200 bsps to be run from command prompt so I created it as a bat file but its not working.</p>
<p>Any suggestion? I added a semicolon at the end of each bcp command.</p>
<p>Eg:</p>
<p>bcp &#8220;SELECT * FROM dbname.schema.tablename&#8221; queryout C:\tablename.txt -c -U login -P password -S servername;</p>
<p>bcp &#8220;SELECT * FROM dbname.schema.tablename&#8221; queryout C:\tablename.txt -c -U login -P password -S servername;</p>
<p> each with different table names and file names</p>
<p>Please advice.</p>
<p>Nith</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James knapp</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-61667</link>
		<dc:creator><![CDATA[James knapp]]></dc:creator>
		<pubDate>Tue, 23 Feb 2010 23:20:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-61667</guid>
		<description><![CDATA[Ron I am reading some comments here in Journey to SQL Authority  because I am having the same problems that you had in 2007.  I have only been using t-sql for 3 years but only reciently have i needed to exec a .bat file from T-SQL.  I was wondering what you did to solve this problem.  James knapp]]></description>
		<content:encoded><![CDATA[<p>Ron I am reading some comments here in Journey to SQL Authority  because I am having the same problems that you had in 2007.  I have only been using t-sql for 3 years but only reciently have i needed to exec a .bat file from T-SQL.  I was wondering what you did to solve this problem.  James knapp</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: santosh kumar</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-61270</link>
		<dc:creator><![CDATA[santosh kumar]]></dc:creator>
		<pubDate>Tue, 16 Feb 2010 14:16:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-61270</guid>
		<description><![CDATA[i am fresser student  &amp; i want to know about sql job
and how to prepared  for  job as will as interview   for as database administretore


please help me 

and i have also quarry

I have a batch file that runs T-SQL query, How can we catch exception/error thrown while running sql query in a batch file?



i wait  thank.............................]]></description>
		<content:encoded><![CDATA[<p>i am fresser student  &amp; i want to know about sql job<br />
and how to prepared  for  job as will as interview   for as database administretore</p>
<p>please help me </p>
<p>and i have also quarry</p>
<p>I have a batch file that runs T-SQL query, How can we catch exception/error thrown while running sql query in a batch file?</p>
<p>i wait  thank&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tejas Shah</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-61247</link>
		<dc:creator><![CDATA[Tejas Shah]]></dc:creator>
		<pubDate>Tue, 16 Feb 2010 13:17:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-61247</guid>
		<description><![CDATA[Hi Ahmed,

One solution is to send an email from catch block, so you can come to know that there is an error in query.

Thanks,

Tejas]]></description>
		<content:encoded><![CDATA[<p>Hi Ahmed,</p>
<p>One solution is to send an email from catch block, so you can come to know that there is an error in query.</p>
<p>Thanks,</p>
<p>Tejas</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ahmed</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-61217</link>
		<dc:creator><![CDATA[Ahmed]]></dc:creator>
		<pubDate>Tue, 16 Feb 2010 05:40:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-61217</guid>
		<description><![CDATA[Dear Pinal,

I have a batch file that runs T-SQL query, How can we catch exception/error thrown while running sql query in a batch file?
Please help me. It is very critical now. Thanks in Advance.]]></description>
		<content:encoded><![CDATA[<p>Dear Pinal,</p>
<p>I have a batch file that runs T-SQL query, How can we catch exception/error thrown while running sql query in a batch file?<br />
Please help me. It is very critical now. Thanks in Advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-58436</link>
		<dc:creator><![CDATA[Pinal Dave]]></dc:creator>
		<pubDate>Fri, 11 Dec 2009 15:17:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-58436</guid>
		<description><![CDATA[Hello Venkat,

From SQL Server we can not open an application with user interface. Even the process switch to application but without interface it does not get responce from application and stay in waiting. After all the process has to be killed.
Usnig t-sql we can perform only tasks that do not require user interaction using xp_cmdshell, OLE automation extended procedures or by CLR coding. On the first glance it seems a limitation but this is not the target SQL server is designed for.
If you explain your requirement then the complete approach to acheive that can be suggested.]]></description>
		<content:encoded><![CDATA[<p>Hello Venkat,</p>
<p>From SQL Server we can not open an application with user interface. Even the process switch to application but without interface it does not get responce from application and stay in waiting. After all the process has to be killed.<br />
Usnig t-sql we can perform only tasks that do not require user interaction using xp_cmdshell, OLE automation extended procedures or by CLR coding. On the first glance it seems a limitation but this is not the target SQL server is designed for.<br />
If you explain your requirement then the complete approach to acheive that can be suggested.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: venkat</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-58405</link>
		<dc:creator><![CDATA[venkat]]></dc:creator>
		<pubDate>Thu, 10 Dec 2009 14:56:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-58405</guid>
		<description><![CDATA[Did you observe the file is running in the background process, I couldn&#039;t able to see.    Do you have any idea of how can I run this and see the file on screen.  

Thanks in Advance.]]></description>
		<content:encoded><![CDATA[<p>Did you observe the file is running in the background process, I couldn&#8217;t able to see.    Do you have any idea of how can I run this and see the file on screen.  </p>
<p>Thanks in Advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sugavaneswaran</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-56539</link>
		<dc:creator><![CDATA[sugavaneswaran]]></dc:creator>
		<pubDate>Thu, 08 Oct 2009 15:18:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-56539</guid>
		<description><![CDATA[Hi Pinal,

I have a batch file.  This calls a console application (say like notepad) which executes for a while &amp; exits normally.  No user intervention is required.

When i call the batch file using xp_cmdshell.  The command seems to execute forever but the console application never starts.

I run the batch file by remote desktoping to the machine and the file is available in the appropriate location.

Any thoughts on this would be useful.

Thanks
Suga]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>I have a batch file.  This calls a console application (say like notepad) which executes for a while &amp; exits normally.  No user intervention is required.</p>
<p>When i call the batch file using xp_cmdshell.  The command seems to execute forever but the console application never starts.</p>
<p>I run the batch file by remote desktoping to the machine and the file is available in the appropriate location.</p>
<p>Any thoughts on this would be useful.</p>
<p>Thanks<br />
Suga</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TAMI</title>
		<link>http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-53676</link>
		<dc:creator><![CDATA[TAMI]]></dc:creator>
		<pubDate>Mon, 13 Jul 2009 22:36:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/#comment-53676</guid>
		<description><![CDATA[hi, trying to find examples of how to export to excel with multiple heading columns before the actual data, but the first &amp; second heading keeps being override by the third, the columns name, what i&#039;m doing wrong?? please help..

DECLARE @beg_startdate datetime
DECLARE @end_enddate datetime
DECLARE @file_name varchar(200), @data_file varchar(200), @timestamp varchar(20), @columns varchar(2000)
DECLARE @sql varchar(2000),@headings varchar(200),@headings2 varchar(200)
BEGIN

SELECT @beg_startdate = DATEADD(wk, DATEDIFF(wk,-1,getdate()), -1)
SELECT @end_enddate = DATEADD(wk, DATEDIFF(wk,-1,getdate()), -1)	
		SET @timestamp = convert(varchar,@beg_startdate,10)
		SELECT @headings=&#039;&#039;&#039;&#039;&#039;Destination Cost Report &#039;&#039;&#039;&#039;&#039;+ &#039; as &#039;+ &#039;&#039;&#039;&#039;&#039;Destination Cost Report &#039;&#039;&#039;&#039;&#039;
		SELECT @headings2=@timestamp+ &#039; as &#039;+ @timestamp
--+@timestamp+ CHAR(10)
		
		SELECT @columns=coalesce(@columns+&#039;,&#039;,&#039;&#039;)+column_name+&#039; as &#039;+column_name FROM INFORMATION_SCHEMA.COLUMNS where table_name=&#039;th_Group_By_Dest&#039;
	
		SELECT @columns=&#039;&#039;&#039;&#039;&#039;&#039;+replace(replace(@columns,&#039; as &#039;,&#039;&#039;&#039;&#039;&#039; as &#039;),&#039;,&#039;,&#039;,&#039;&#039;&#039;&#039;&#039;)	

		SET @file_name = &#039;\\tcireports\Backup\Destination_&#039; + @timestamp + &#039;.xls&#039;

		--Create a dummy file to have actual data
		SELECT @data_file=substring(@file_name,1,len(@file_name)-charindex(&#039;\&#039;,reverse(@file_name)))+&#039;\desttest.xls&#039;

		-- 		Generate column names in the passed EXCEL file
		--		-c Output in ASCII with the default field terminator (tab) and row terminator (crlf) 
		SET @sql=&#039;EXEC master..xp_cmdshell &#039;&#039; bcp &quot;SELECT * FROM (SELECT &#039;+@headings+&#039;) as t&quot; queryout &quot;&#039;+ @file_name+ &#039;&quot; -c&#039;&#039;&#039;
		EXEC (@sql)
		
		SET @sql=&#039;EXEC master..xp_cmdshell &#039;&#039; bcp &quot;SELECT * FROM (SELECT &#039;+@headings2+&#039;) as t&quot; queryout &quot;&#039;+ @file_name+ &#039;&quot; -c&#039;&#039;&#039;
		EXEC (@sql)
		
		SET @sql=&#039;EXEC master..xp_cmdshell &#039;&#039; bcp &quot;SELECT * FROM (SELECT &#039;+@columns+&#039;) as t&quot; queryout &quot;&#039;+ @file_name+ &#039;&quot; -c&#039;&#039;&#039;

		EXEC (@sql)


		--	--Generate data in the dummy file
		SET @sql=&#039;EXEC master..xp_cmdshell &#039;&#039; bcp &quot;SELECT * FROM TCIReports.MarginReport.dbo.th_Group_By_Dest &quot; queryout &quot;&#039;+ @data_file + &#039;&quot; -c&#039;&#039;&#039;
		EXEC (@sql)
--
--	--	--Copy dummy file to passed EXCEL file
		SET @sql=&#039;EXEC master..xp_cmdshell &#039;&#039; type &#039;+ @data_file+&#039; &gt;&gt; &#039;+ @file_name + &#039;&#039;&#039;&#039;
		EXEC (@sql)
END]]></description>
		<content:encoded><![CDATA[<p>hi, trying to find examples of how to export to excel with multiple heading columns before the actual data, but the first &amp; second heading keeps being override by the third, the columns name, what i&#8217;m doing wrong?? please help..</p>
<p>DECLARE @beg_startdate datetime<br />
DECLARE @end_enddate datetime<br />
DECLARE @file_name varchar(200), @data_file varchar(200), @timestamp varchar(20), @columns varchar(2000)<br />
DECLARE @sql varchar(2000),@headings varchar(200),@headings2 varchar(200)<br />
BEGIN</p>
<p>SELECT @beg_startdate = DATEADD(wk, DATEDIFF(wk,-1,getdate()), -1)<br />
SELECT @end_enddate = DATEADD(wk, DATEDIFF(wk,-1,getdate()), -1)<br />
		SET @timestamp = convert(varchar,@beg_startdate,10)<br />
		SELECT @headings=&#8221;&#8221;&#8217;Destination Cost Report &#8221;&#8221;&#8217;+ &#8216; as &#8216;+ &#8221;&#8221;&#8217;Destination Cost Report &#8221;&#8221;&#8217;<br />
		SELECT @headings2=@timestamp+ &#8216; as &#8216;+ @timestamp<br />
&#8211;+@timestamp+ CHAR(10)</p>
<p>		SELECT @columns=coalesce(@columns+&#8217;,',&#8221;)+column_name+&#8217; as &#8216;+column_name FROM INFORMATION_SCHEMA.COLUMNS where table_name=&#8217;th_Group_By_Dest&#8217;</p>
<p>		SELECT @columns=&#8221;&#8221;&#8221;+replace(replace(@columns,&#8217; as &#8216;,&#8221;&#8221;&#8217; as &#8216;),&#8217;,',&#8217;,&#8221;&#8221;&#8217;)	</p>
<p>		SET @file_name = &#8216;\\tcireports\Backup\Destination_&#8217; + @timestamp + &#8216;.xls&#8217;</p>
<p>		&#8211;Create a dummy file to have actual data<br />
		SELECT @data_file=substring(@file_name,1,len(@file_name)-charindex(&#8216;\&#8217;,reverse(@file_name)))+&#8217;\desttest.xls&#8217;</p>
<p>		&#8211; 		Generate column names in the passed EXCEL file<br />
		&#8211;		-c Output in ASCII with the default field terminator (tab) and row terminator (crlf)<br />
		SET @sql=&#8217;EXEC master..xp_cmdshell &#8221; bcp &#8220;SELECT * FROM (SELECT &#8216;+@headings+&#8217;) as t&#8221; queryout &#8220;&#8216;+ @file_name+ &#8216;&#8221; -c&#8221;&#8217;<br />
		EXEC (@sql)</p>
<p>		SET @sql=&#8217;EXEC master..xp_cmdshell &#8221; bcp &#8220;SELECT * FROM (SELECT &#8216;+@headings2+&#8217;) as t&#8221; queryout &#8220;&#8216;+ @file_name+ &#8216;&#8221; -c&#8221;&#8217;<br />
		EXEC (@sql)</p>
<p>		SET @sql=&#8217;EXEC master..xp_cmdshell &#8221; bcp &#8220;SELECT * FROM (SELECT &#8216;+@columns+&#8217;) as t&#8221; queryout &#8220;&#8216;+ @file_name+ &#8216;&#8221; -c&#8221;&#8217;</p>
<p>		EXEC (@sql)</p>
<p>		&#8211;	&#8211;Generate data in the dummy file<br />
		SET @sql=&#8217;EXEC master..xp_cmdshell &#8221; bcp &#8220;SELECT * FROM TCIReports.MarginReport.dbo.th_Group_By_Dest &#8221; queryout &#8220;&#8216;+ @data_file + &#8216;&#8221; -c&#8221;&#8217;<br />
		EXEC (@sql)<br />
&#8211;<br />
&#8211;	&#8211;	&#8211;Copy dummy file to passed EXCEL file<br />
		SET @sql=&#8217;EXEC master..xp_cmdshell &#8221; type &#8216;+ @data_file+&#8217; &gt;&gt; &#8216;+ @file_name + &#8221;&#8221;<br />
		EXEC (@sql)<br />
END</p>
]]></content:encoded>
	</item>
</channel>
</rss>

