<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
	xmlns:media="http://search.yahoo.com/mrss/"
>

<channel>
	<title>ashchuan.com - Web Technology &#187; Database</title>
	<atom:link href="http://www.ashchuan.com/blog/category/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ashchuan.com/blog</link>
	<description>On web technology, blogging and gadgets</description>
	<lastBuildDate>Thu, 29 Jul 2010 23:03:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<!-- podcast_generator="podPress/8.8" - maintenance_release="8.8.5.3" -->
	<copyright>Copyright &#xA9; 2010 ashchuan.com - Web Technology </copyright>
	<managingEditor>ashley@ashchuan.com</managingEditor>
	<webMaster>ashley@ashchuan.com</webMaster>
	<category>posts</category>
	<ttl>1440</ttl>
	<image>
		<url>http://ashchuan.com/blog/wp-content/plugins/podpress/images/powered_by_podpress.jpg</url>
		<title>ashchuan.com - Web Technology &#187; Database</title>
		<link>http://www.ashchuan.com/blog</link>
		<width>144</width>
		<height>144</height>
	</image>
	<itunes:subtitle></itunes:subtitle>
	<itunes:summary>On web technology, blogging and gadgets</itunes:summary>
	<itunes:keywords></itunes:keywords>
	<itunes:category text="Society &amp; Culture" />
	<itunes:author></itunes:author>
	<itunes:owner>
		<itunes:name></itunes:name>
		<itunes:email>ashley@ashchuan.com</itunes:email>
	</itunes:owner>
	<itunes:block>no</itunes:block>
	<itunes:explicit>no</itunes:explicit>
	<itunes:image href="http://ashchuan.com/blog/wp-content/plugins/podpress/images/powered_by_podpress.jpg" />
		<item>
		<title>Here&#8217;s a SQL Server Tip</title>
		<link>http://www.ashchuan.com/blog/2010/07/29/heres-a-sql-server-tip/</link>
		<comments>http://www.ashchuan.com/blog/2010/07/29/heres-a-sql-server-tip/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 23:03:20 +0000</pubDate>
		<dc:creator>ash</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Management Studio]]></category>
		<category><![CDATA[Query]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.ashchuan.com/blog/?p=959</guid>
		<description><![CDATA[How many times have you asked this question when you run a query. How do I copy the query result with the column names into Microsoft Excel? In the SQL Server Management Studio, in the Tools menu, select Tools > Options > SQL Server > Results to Grid Then check the Include column headers when [...]]]></description>
			<content:encoded><![CDATA[<!-- sphereit start --><p>How many times have you asked this question when you run a query.  How do I copy the query result with the column names into Microsoft Excel?</p>
<p>In the SQL Server Management Studio, in the Tools menu, select <strong>Tools > Options > SQL Server > Results to Grid</strong><em></p>
<p>Then check the <strong>Include column headers when copying or saving the results</strong> checkbox and click on OK.</p>
<p>That&#8217;s it.  The next time you run a query, copy the query result, paste in Excel and voila, the column names are pasted together with the data.</p>
<p><a href="http://www.ashchuan.com/blog/wp-content/uploads/2010/07/sqlwithcolumnname.png" rel="lightbox"><img src="http://www.ashchuan.com/blog/wp-content/uploads/2010/07/sqlwithcolumnname-300x174.png" alt="" title="sqlwithcolumnname" width="300" height="174" class="aligncenter size-medium wp-image-961" /></a></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-2635249250939971";
/* 300x250, created 10/02/08 */
google_ad_slot = "1990815382";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<!-- sphereit end --><span style="margin-bottom:40px; border-bottom:none;"><a class="iconsphere" title="Sphere: Related Content" onclick="return Sphere.Widget.search('http://www.ashchuan.com/blog/2010/07/29/heres-a-sql-server-tip/')" href="http://www.sphere.com/search?q=sphereit:http://www.ashchuan.com/blog/2010/07/29/heres-a-sql-server-tip/">Sphere: Related Content</a></span><br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.ashchuan.com/blog/2010/07/29/heres-a-sql-server-tip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL xp_findnextmsg and xp_readmail</title>
		<link>http://www.ashchuan.com/blog/2009/11/15/sql-xp_findnextmsg-and-xp_readmail/</link>
		<comments>http://www.ashchuan.com/blog/2009/11/15/sql-xp_findnextmsg-and-xp_readmail/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 22:48:24 +0000</pubDate>
		<dc:creator>ash</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL Mail]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[xp_findnextmsg]]></category>
		<category><![CDATA[xp_readmail]]></category>

		<guid isPermaLink="false">http://www.ashchuan.com/blog/?p=936</guid>
		<description><![CDATA[If you use SQL mail, you can read the messages in the SQL inbox stack and do stuff with them. Recently I had to use SQL scripting to find messages in the SQL inbox, read the message, determine if it is a text or html email, then add the message to a table in the [...]]]></description>
			<content:encoded><![CDATA[<!-- sphereit start --><p>If you use SQL mail, you can read the messages in the SQL inbox stack and do stuff with them.  Recently I had to use SQL scripting to find messages in the SQL inbox, read the message, determine if it is a text or html email, then add the message to a table in the database.</p>
<p>This can be easily achieved using the xp_findnextmsg and xp_readmail procedures.  To strip the html tags from the email, I used a UDF (User Defined Function) written by the SQL guru of http://blog.sqlauthority.com.  Kudos to him for sharing the function.<br />
<span id="more-936"></span><br />
All SQL examples are shown below.</p>
<p>The xp_readmail example is written for SQL Server 2000, where there is a limit of varchar(8000) for data type varchar.  In SQL Server 2005, you can use varchar(max) which extends the limit.  You will see in my example I split email messages that are bigger than varchar(8000) when using xp_readmail.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-2635249250939971";
/* 300x250, created 10/02/08 */
google_ad_slot = "1990815382";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
<img src="http://www.ashchuan.com/blog/wp-content/uploads/2009/07/readmail.PNG" alt="readmail" title="readmail" class="alignnone size-full wp-image-937" /></p>
<p><img src="http://www.ashchuan.com/blog/wp-content/uploads/2009/07/readmail2.PNG" alt="readmail2" title="readmail2" class="alignnone size-full wp-image-938" /></p>
<!-- sphereit end --><span style="margin-bottom:40px; border-bottom:none;"><a class="iconsphere" title="Sphere: Related Content" onclick="return Sphere.Widget.search('http://www.ashchuan.com/blog/2009/11/15/sql-xp_findnextmsg-and-xp_readmail/')" href="http://www.sphere.com/search?q=sphereit:http://www.ashchuan.com/blog/2009/11/15/sql-xp_findnextmsg-and-xp_readmail/">Sphere: Related Content</a></span><br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.ashchuan.com/blog/2009/11/15/sql-xp_findnextmsg-and-xp_readmail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Database Mail vs SQL Mail in SQL Server 2005</title>
		<link>http://www.ashchuan.com/blog/2008/10/29/database-mail-vs-sql-mail-in-sql-server-2005/</link>
		<comments>http://www.ashchuan.com/blog/2008/10/29/database-mail-vs-sql-mail-in-sql-server-2005/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 22:20:32 +0000</pubDate>
		<dc:creator>ash</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Database Mail]]></category>
		<category><![CDATA[SQL Mail]]></category>
		<category><![CDATA[SQL Server 2005]]></category>

		<guid isPermaLink="false">http://1275313070</guid>
		<description><![CDATA[SQL Mail was what one would use to send emails from SQL Server in the SQL Server 2000 version. But in SQL Server 2005, SQL Mail is considered legacy. Microsoft introduced a better email component called Database Mail for SQL Server 2005. In SQL Mail, you can run the xp_sendmail stored procedure to send an [...]]]></description>
			<content:encoded><![CDATA[<!-- sphereit start --><div align="center">
<a href="http://www.ashchuan.com/blog/wp-content/uploads/2008/10/dbmail.gif" rel="lightbox"><img src="http://www.ashchuan.com/blog/wp-content/uploads/2008/10/dbmail.gif" alt="" title="dbmail" class="alignnone size-medium wp-image-530" border="0" /></a>
</div>
<p>SQL Mail was what one would use to send emails from SQL Server in the SQL Server 2000 version.  But in SQL Server 2005, SQL Mail is considered legacy.  Microsoft introduced a better email component called Database Mail for SQL Server 2005.</p>
<p>In SQL Mail, you can run the xp_sendmail stored procedure to send an email from SQL Server 2000.  Here is an example of the xp_sendmail script.  </p>
<div align="center">
<a href="http://www.ashchuan.com/blog/wp-content/uploads/2008/10/mail6.jpg" rel="lightbox"><img src="http://www.ashchuan.com/blog/wp-content/uploads/2008/10/mail6.jpg" alt="" title="mail6" class="alignnone size-medium wp-image-534" border="0" /></a>
</div>
<p>I use a lot of xp_sendmail in my SQL script when I was developing applications in SQL Server 2000 and since migrating to SQL Server 2005, there are still the legacy SQL Mail scripts lurking in SQL Server 2005 which I have not migrated to using Database Mail.</p>
<p><strong>So why did Microsoft make the decision to move away from SQL Mail and introduce Database Mail?<br />
</strong><br />
<span id="more-523"></span></p>
<p>1.  SQL Mail was developed and runs in-process to SQL Server service.  This means if SQL Mail goes down, your SQL Server also goes down.  You don&#8217;t want this to happen on your production database because you will not have many happy users if that happens.</p>
<p>2.  To use SQL Mail you need to install the extended MAPI client component on your server.  How I usually do this is by installing Microsoft Outlook on the server.  This will install the MAPI client component.  Without MAPI, SQL Mail will not run.</p>
<p><strong>What are the advantages of using Database Mail?</strong></p>
<p>1.  Unlike SQL Mail, Database Mail runs outside SQL Server in a separate process.  So if Database Mail goes down, it will not bring down SQL Server.</p>
<p>2. Database Mail does not need Extended MAPI client components installed for it to run.</p>
<p><!--adsense--></p>
<p>3.  Database Mail can be configued with multiple SMTP accounts and with multiple profiles.  This increases the robustness of the system.  In a realtime environment, if one mail server goes down, Database Mail will still be able to send emails through the other configured SMTP accounts.</p>
<p>4.  In Database Mail, all mail events are logged and you can view the mail history.</p>
<p>5.  You can configure Database Mail to limit file sizes, disallowing large attachments and filtering of file extensions such as .exe or .bat</p>
<p><strong>Where do you enable Database Mail and SQL Mail in SQL Server 2005?</strong></p>
<p>You do it through SQL Server 2005 Surface Area Configuration shown below.  Click on Surface Area Configuration for Features.</p>
<div align="center"><a href="http://www.ashchuan.com/blog/wp-content/uploads/2008/10/mail3a.jpg" rel="lightbox"><img src="http://www.ashchuan.com/blog/wp-content/uploads/2008/10/mail3a.jpg" alt="" title="mail3a" class="alignnone size-medium wp-image-541" border="0" /></a></div>
<p>Tick Enable Database Mail Stored Procedures to enable Database Mail in SQL Server</p>
<div align="center">
<a href="http://www.ashchuan.com/blog/wp-content/uploads/2008/10/mail1a.jpg" rel="lightbox"><img src="http://www.ashchuan.com/blog/wp-content/uploads/2008/10/mail1a.jpg" alt="" title="mail1a" class="alignnone size-medium wp-image-539" border="0" /></a></div>
<p>Tick Enable SQL Mail Stored Procedures to enable SQL Mail in SQL Server</p>
<div align="center"><a href="http://www.ashchuan.com/blog/wp-content/uploads/2008/10/mail2a.jpg" rel="lightbox"><img src="http://www.ashchuan.com/blog/wp-content/uploads/2008/10/mail2a.jpg" alt="" title="mail2a" class="alignnone size-medium wp-image-540" border="0" /></a></div>
<p>Access Database Mail and SQL Mail and setup both in SQL Server Management Console, shown below.<br />
  Once that is setup, you can invoke Database Mail and SQL Mail to send emails and notification.</p>
<div align="center">
<a href="http://www.ashchuan.com/blog/wp-content/uploads/2008/10/mail4.jpg" rel="lightbox"><img src="http://www.ashchuan.com/blog/wp-content/uploads/2008/10/mail4.jpg" alt="" title="mail4" class="alignnone size-medium wp-image-527" border="0" /></a></div>
<div align="center">
<a href="http://www.ashchuan.com/blog/wp-content/uploads/2008/10/mail5.jpg" rel="lightbox"><img src="http://www.ashchuan.com/blog/wp-content/uploads/2008/10/mail5.jpg" alt="" title="mail5" class="alignnone size-medium wp-image-528" border="0" /></a></div>
<!-- sphereit end --><span style="margin-bottom:40px; border-bottom:none;"><a class="iconsphere" title="Sphere: Related Content" onclick="return Sphere.Widget.search('http://www.ashchuan.com/blog/2008/10/29/database-mail-vs-sql-mail-in-sql-server-2005/')" href="http://www.sphere.com/search?q=sphereit:http://www.ashchuan.com/blog/2008/10/29/database-mail-vs-sql-mail-in-sql-server-2005/">Sphere: Related Content</a></span><br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.ashchuan.com/blog/2008/10/29/database-mail-vs-sql-mail-in-sql-server-2005/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
