<?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: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>Ashish Gilhotra's -- SQL Learning</title>
	<atom:link href="http://ashishgilhotra.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ashishgilhotra.wordpress.com</link>
	<description>This Blog is All About SQl And Web Technologies</description>
	<lastBuildDate>Mon, 10 Aug 2009 11:16:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ashishgilhotra.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Ashish Gilhotra's -- SQL Learning</title>
		<link>http://ashishgilhotra.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ashishgilhotra.wordpress.com/osd.xml" title="Ashish Gilhotra&#039;s -- SQL Learning" />
	<atom:link rel='hub' href='http://ashishgilhotra.wordpress.com/?pushpress=hub'/>
		<item>
		<title>My New Home for Blog</title>
		<link>http://ashishgilhotra.wordpress.com/2009/08/10/my-new-home-for-blog/</link>
		<comments>http://ashishgilhotra.wordpress.com/2009/08/10/my-new-home-for-blog/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 11:16:41 +0000</pubDate>
		<dc:creator>ashishgilhotra</dc:creator>
				<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://ashishgilhotra.wordpress.com/?p=109</guid>
		<description><![CDATA[Hi All &#8230; Now it about a month when i write some thing about Technology or SQL in blog. The reason behind this is i started writing at some new place so can&#8217;t get enough time to synchronize these two places so this post is about to inform you peoples about my new space for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashishgilhotra.wordpress.com&amp;blog=7164552&amp;post=109&amp;subd=ashishgilhotra&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi All &#8230;</p>
<p>Now it about a month when i write some thing about Technology or SQL in blog. The reason behind this is i started writing at some new place so can&#8217;t get enough time to synchronize these two places so this post is about to inform you peoples about my new space for blogging and here it is.. you will find me writing their so keep in touch with me at this blog&#8230;.</p>
<p><a href="http://beyondrelational.com/blogs/ashish/default.aspx">http://beyondrelational.com/blogs/ashish/default.aspx</a></p>
<p>So from now you find me rarely do posting on this blog about SQL &amp; Technology, but i decided to continue with this blog also as a non professional and more personal blog so you will find some musings and random thoughts which strikes my mind on this blog and for all other techinical stuff you can found me there,,,,,,,,,</p>
<p><a href="http://beyondrelational.com/blogs/ashish/default.aspx">http://beyondrelational.com/blogs/ashish/default.aspx</a></p>
<p>Hope you enjoy reading this.!!!!!!!!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ashishgilhotra.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ashishgilhotra.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ashishgilhotra.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ashishgilhotra.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ashishgilhotra.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ashishgilhotra.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ashishgilhotra.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ashishgilhotra.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ashishgilhotra.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ashishgilhotra.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ashishgilhotra.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ashishgilhotra.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ashishgilhotra.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ashishgilhotra.wordpress.com/109/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashishgilhotra.wordpress.com&amp;blog=7164552&amp;post=109&amp;subd=ashishgilhotra&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ashishgilhotra.wordpress.com/2009/08/10/my-new-home-for-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c1c2313df2e9f4bf381ea695b7bf84e0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ashishgilhotra</media:title>
		</media:content>
	</item>
		<item>
		<title>Running Out of System Tables</title>
		<link>http://ashishgilhotra.wordpress.com/2009/06/19/105/</link>
		<comments>http://ashishgilhotra.wordpress.com/2009/06/19/105/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 13:20:29 +0000</pubDate>
		<dc:creator>ashishgilhotra</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[sqlserver 2005]]></category>
		<category><![CDATA[u_tables.sql]]></category>

		<guid isPermaLink="false">http://ashishgilhotra.wordpress.com/2009/06/19/105/</guid>
		<description><![CDATA[Hi all, Today i encounter a issue with my instance as i am using the table SPT_VALUES from the master database available in our Sql Server, so when i tried to fetch some records from master..spt_values then it shows me error… Here is a example of query and the error thrown by SQL is.. SELECT [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashishgilhotra.wordpress.com&amp;blog=7164552&amp;post=105&amp;subd=ashishgilhotra&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi all,</p>
<p>Today i encounter a issue with my instance as i am using the table SPT_VALUES from the master database available in our Sql Server, so when i tried to fetch some records from master..spt_values then it shows me error…</p>
<p>Here is a example of query and the error thrown by SQL is..</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">SELECT</span> * <span style="color:#0000ff;">FROM</span> orders <span style="color:#0000ff;">WHERE</span> order_id <span style="color:#0000ff;">in</span> (<span style="color:#0000ff;">SELECT</span> number <span style="color:#0000ff;">FROM</span> master..spt_values <span style="color:#0000ff;">WHERE</span> type=<span style="color:#006080;">'P'</span>)</pre>
<p><!--CRLF--></div>
</div>
<p>and Error is..</p>
<p><span style="color:#ff0000;">Msg 208, Level 16, State 1, Line 1</span></p>
<p>Invalid object name &#8216;master..spt_values&#8217;.</p>
<p><span style="color:#ff0000;"> </span></p>
<p>So it is very uncommon thing to me to loose table from Master Database in Sql Server 2005. But i found that it is not a very uncommon thing because if you can right click on the table present in Master Database and choose the ‘DELETE’ option then table would be deleted from your server.</p>
<p>Now what happen next when tables get deleted from your Master Database, there are some information which stored in Tables in Master Database…</p>
<p>So i googled a lot about this and here is the solution…</p>
<p>There is a script file named “u_tables.sql”  in “installation directory &gt;MSSQL&gt;Install” folder .</p>
<p>Execute this script against the instance that has these missing tables, and you will get the tables again.</p>
<p>But this script has limitations because its only able to recreate /reproduce only two System Tables “dbo.spt_monitor and dbo.spt_values” .</p>
<p>So in this way you can get your tables back in Master Database..But it is highly recommended that you don’t delete tables present in Master Database.</p>
<p>Thanks.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ashishgilhotra.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ashishgilhotra.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ashishgilhotra.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ashishgilhotra.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ashishgilhotra.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ashishgilhotra.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ashishgilhotra.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ashishgilhotra.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ashishgilhotra.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ashishgilhotra.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ashishgilhotra.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ashishgilhotra.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ashishgilhotra.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ashishgilhotra.wordpress.com/105/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashishgilhotra.wordpress.com&amp;blog=7164552&amp;post=105&amp;subd=ashishgilhotra&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ashishgilhotra.wordpress.com/2009/06/19/105/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c1c2313df2e9f4bf381ea695b7bf84e0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ashishgilhotra</media:title>
		</media:content>
	</item>
		<item>
		<title>Error/Exception Handling in Sql Server 2005</title>
		<link>http://ashishgilhotra.wordpress.com/2009/05/12/95/</link>
		<comments>http://ashishgilhotra.wordpress.com/2009/05/12/95/#comments</comments>
		<pubDate>Tue, 12 May 2009 05:48:43 +0000</pubDate>
		<dc:creator>ashishgilhotra</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Error Handling]]></category>
		<category><![CDATA[Sql Server 2005]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://ashishgilhotra.wordpress.com/?p=95</guid>
		<description><![CDATA[Being a .Net developer, the most useful feature i found was the Error Handling or Exception Handling technique.When it comes to programming languages , all popular OOP languages have TRY()…Catch() method to handle an exception. In Sql Server 2005, error handling was made easy . This article demonstrates various methods of handling errors using Try()..Catch() [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashishgilhotra.wordpress.com&amp;blog=7164552&amp;post=95&amp;subd=ashishgilhotra&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Being a .Net developer, the most useful feature i found was the Error Handling or Exception Handling technique.When it comes to programming languages , all popular OOP languages have TRY()…Catch() method to handle an exception.</p>
<p>In Sql Server 2005, error handling was made easy . This article demonstrates various methods of handling errors using<br />
Try()..Catch() in T-SQL.</p>
<p>Here you try something like that…</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">declare</span> @i tinyint</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">select</span> @i=<span style="color:#0000ff;">count</span>(*) <span style="color:#0000ff;">from</span> sys.sysobjects</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">select</span> @i*999999999 <span style="color:#0000ff;">as</span> myval</pre>
<p><!--CRLF--></div>
</div>
<p>When you try to run this you will get a error like this…</p>
<p>&#8211; Error</p>
<p>Msg 220, Level 16, State 2, Line 2</p>
<p>Arithmetic overflow error for data type tinyint, value = 1812.</p>
<p>(1 row(s) affected)</p>
<p>Now try to run it something like this….</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">begin</span> try</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">declare</span> @i tinyint</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">select</span> @i=<span style="color:#0000ff;">count</span>(*) <span style="color:#0000ff;">from</span> sys.sysobjects</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">select</span> @i*999999999 <span style="color:#0000ff;">as</span> myval</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">end</span> try</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">begin</span> catch</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">select</span></pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;">    error_line() <span style="color:#0000ff;">as</span> errornumber</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">end</span> catch</pre>
<p><!--CRLF--></div>
</div>
<p>you will get result like</p>
<p>errornumber</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>4</p>
<p>so now this time it throws the number of error.</p>
<p>You can also get more parameters  like Error_Line from this like,,,</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">begin</span> try</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">declare</span> @i tinyint</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">select</span> @i=<span style="color:#0000ff;">count</span>(*) <span style="color:#0000ff;">from</span> sys.sysobjects</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">select</span> @i*999999999 <span style="color:#0000ff;">as</span> myval</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">end</span> try</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">begin</span> catch</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">select</span></pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;">        ERROR_NUMBER() <span style="color:#0000ff;">AS</span> ErrorNumber,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">        ERROR_SEVERITY() <span style="color:#0000ff;">AS</span> ErrorSeverity,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;">        ERROR_STATE() <span style="color:#0000ff;">AS</span> ErrorState,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">        ERROR_PROCEDURE() <span style="color:#0000ff;">AS</span> ErrorProcedure,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;">        ERROR_LINE() <span style="color:#0000ff;">AS</span> ErrorLine,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">        ERROR_MESSAGE() <span style="color:#0000ff;">AS</span> ErrorMessage;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">end</span> catch</pre>
<p><!--CRLF--></div>
</div>
<p> </p>
<p>like this……<br />
 </p>
<p><img class="alignleft size-medium wp-image-99" title="error_handling1" src="http://ashishgilhotra.files.wordpress.com/2009/05/error_handling11.jpg?w=300&#038;h=164" alt="error_handling1" width="300" height="164" /></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>Now you can also make a Store Procedure like this which throws error and use this in your try()..catch() statement like this…</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">CREATE</span> <span style="color:#0000ff;">PROCEDURE</span> Sp_ThrowErrorInfo</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">AS</span></pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">SELECT</span></pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;">        ERROR_NUMBER() <span style="color:#0000ff;">AS</span> ErrorNumber,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">        ERROR_SEVERITY() <span style="color:#0000ff;">AS</span> ErrorSeverity,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;">        ERROR_STATE() <span style="color:#0000ff;">AS</span> ErrorState,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">        ERROR_PROCEDURE() <span style="color:#0000ff;">AS</span> ErrorProcedure,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;">        ERROR_LINE() <span style="color:#0000ff;">AS</span> ErrorLine,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">        ERROR_MESSAGE() <span style="color:#0000ff;">AS</span> ErrorMessage;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">GO</span></pre>
<p><!--CRLF--></div>
</div>
<p>then try  like this..</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">BEGIN</span> TRY</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">declare</span> @i tinyint</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">select</span> @i=<span style="color:#0000ff;">count</span>(*) <span style="color:#0000ff;">from</span> sys.sysobjects</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">select</span> @i*999999999 <span style="color:#0000ff;">as</span> myval</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">END</span> TRY</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">BEGIN</span> CATCH</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">   <span style="color:#0000ff;">Exec</span> Sp_ThrowErrorInfo</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">END</span> CATCH;</pre>
<p><!--CRLF--></div>
</div>
<p>This gives you same results as above.</p>
<p>You can also use it with a procedure like if you have some kind of procedure than you want to associate with it</p>
<p>Try()…Catch() block then do something like that</p>
<p>First create a Procedure which contains SQL statements to do a specific task, i made a Store procedure which select all the data from a table which doesn’t present in the database </p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">CREATE</span> <span style="color:#0000ff;">PROCEDURE</span> Sp_ErrorTest</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">AS</span></pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">SELECT</span> * <span style="color:#0000ff;">FROM</span> NonexistentTable;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">GO</span></pre>
<p><!--CRLF--></div>
</div>
<p>then do like this….</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">BEGIN</span> TRY</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">EXECUTE</span> usp_ExampleProc</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">END</span> TRY</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">BEGIN</span> CATCH</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">     <span style="color:#0000ff;">EXECUTE</span> Sp_ThrowErrorInfo</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:'Courier New', courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">END</span> CATCH;</pre>
<p><!--CRLF--></div>
</div>
<p>This will show you error,, so in this way you can use Store Procedures in Error Handling</p>
<p>There are many kind of errors which you able to trace with Try()…Catch() statements in T-SQL</p>
<p>The following system functions can be used to obtain information about the error that CATCH block  to be executed:</p>
<ul>
<li><strong>ERROR_NUMBER()</strong> returns the number of the error.</li>
<li><strong>ERROR_SEVERITY()</strong> returns the severity.</li>
<li><strong>ERROR_STATE()</strong> returns the error state number.</li>
<li><strong>ERROR_PROCEDURE()</strong> returns the name of the stored procedure or trigger where the error occurred.</li>
<li><strong>ERROR_LINE()</strong> returns the line number inside the routine that caused the error.</li>
<li><strong>ERROR_MESSAGE()</strong> returns the complete text of the error message. The text includes the values supplied for any substitutable parameters, such as lengths, object names, or times.</li>
</ul>
<p>If these functions are used outside the CATCH block, then all of them will return NULL value.</p>
<p>You can also use Try()..Catch() statement  to handle errors that occur inside a transaction, by checking the value of  XACT_STATE . The XACT_STATE function determines whether the transaction should be committed or rolled back.</p>
<p>You can use XACT_STATE_ABORT is on, this makes transaction uncommittable when error occurs..</p>
<p>If XACT_STATE =1 , transaction is committable.</p>
<p>If XACT_STATE=-1, the transaction is uncommittable and should be rolled back.</p>
<p>If XACT_STATE=0, means that there is no transaction and a commit or rollback operation would generate an error.</p>
<p>In this way there is a lot more to do in error handling, and there are commands which give you very fine-grained control over small set of errors.</p>
<p>Thanks..</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ashishgilhotra.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ashishgilhotra.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ashishgilhotra.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ashishgilhotra.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ashishgilhotra.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ashishgilhotra.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ashishgilhotra.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ashishgilhotra.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ashishgilhotra.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ashishgilhotra.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ashishgilhotra.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ashishgilhotra.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ashishgilhotra.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ashishgilhotra.wordpress.com/95/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashishgilhotra.wordpress.com&amp;blog=7164552&amp;post=95&amp;subd=ashishgilhotra&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ashishgilhotra.wordpress.com/2009/05/12/95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c1c2313df2e9f4bf381ea695b7bf84e0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ashishgilhotra</media:title>
		</media:content>

		<media:content url="http://ashishgilhotra.files.wordpress.com/2009/05/error_handling11.jpg?w=300" medium="image">
			<media:title type="html">error_handling1</media:title>
		</media:content>
	</item>
		<item>
		<title>Indexes in SQL</title>
		<link>http://ashishgilhotra.wordpress.com/2009/05/03/indexes-in-sql/</link>
		<comments>http://ashishgilhotra.wordpress.com/2009/05/03/indexes-in-sql/#comments</comments>
		<pubDate>Sun, 03 May 2009 17:41:45 +0000</pubDate>
		<dc:creator>ashishgilhotra</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Index]]></category>

		<guid isPermaLink="false">http://ashishgilhotra.wordpress.com/?p=89</guid>
		<description><![CDATA[Hi this is first post for INDEXES in SQL Server. In this we learn about indexes , how SQL use indexes and all. If you have much experience with indexes at all, you are probably already familiar with the difference between clustered and non-clustered indexes. So we look at that whether or not SQL SERVER [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashishgilhotra.wordpress.com&amp;blog=7164552&amp;post=89&amp;subd=ashishgilhotra&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi this is first post for INDEXES in SQL Server. In this we learn about indexes , how SQL use indexes and all.</p>
<p>If you have much experience with indexes at all, you are probably already familiar with the difference between clustered and non-clustered indexes. So we look at that whether or not SQL SERVER Query Optimizer will use your indexes or not.</p>
<p>Lets start with an table say IndexTest  which has many columns, but we are interested in only “reg_no”.</p>
<p>This table has more 10,000  records for testing purpose now we create a non-clustered index on “reg_no” now we run this query on table and INCLUDE THE ACTUAL EXECUTION PLAN</p>
<p><strong>1: select * from IndexTest where reg_no &gt;=&#8217;20040510377&#8242;</strong></p>
<p><strong></strong><br />
Now we notice that “reg_no” column used in where clause of the query has a non-clustered index on it so it supposed that the Query Optimizer would use the index to produce the requested results but its not and query does a Table Scan operation. This is because  Query Analyzer always evaluates whether or not an index is useful before it is used. So “How you would know whether your index is useful or not?”. Its depends on the selectivity of your query “Selectivity” refers to how many rows in a table that are returned by your query so if the number of rows is that are returned back is less than ,it is considered to have high selectivity ,and the index will be used. In my case its only 300 rows , mean if my query returns 300 rows than it uses the index otherwise not here.</p>
<p>Now if you want to find the selectivity of an index then run this.</p>
<p><strong>1: DBCC SHOW_STATISTICS (IndexTest, IX_NonTest)</strong></p>
<p><strong></strong><br />
This will show the statistics of your index and there is a All Density Column which shows average percentage of duplicate rows in an Index.</p>
<p>AND IN CASE OF a CLUSTERED INDEX lets see what happen when we use clustered index on our table.</p>
<p>for this on the same table we first drop that Non-Clustered index and make a new unique clustered index on it</p>
<p>1<strong>: &#8212; Drop Index<br />
2: drop index IndexTest.IX_NonTest<br />
3: &#8212; Now Create a New Unique Clustered index  on same column of the table<br />
4: CREATE UNIQUE CLUSTERED INDEX IX_UniTest on IndexTest(reg_no)</strong></p>
<p><strong></strong><br />
You can Check your indexes and statistics  by this</p>
<p>1<strong>: &#8211;Check Index and Statistics Date<br />
2: SELECT<br />
3:             &#8216;Index Name&#8217; = ind.name,<br />
4:             &#8216;Index Type&#8217;= ind.type_desc,<br />
5:             &#8216;Statistics Date&#8217; = STATS_DATE(ind.object_id, ind.index_id)<br />
6: FROM<br />
7:             SYS.INDEXES ind<br />
8: WHERE<br />
9:             OBJECT_NAME(ind.object_id) = &#8216;IndexTest&#8217;</strong></p>
<p><strong></strong></p>
<p>So now you have a Unique Clustered Index on your table on column “reg_no”. In this  when we run query like this</p>
<p>query on table and Include Actual Execution Plan</p>
<p>1:<br />
2: select * from IndexTest where reg_no &gt;=&#8217;20030100451&#8242;<br />
Then this query returns ‘9992’ records and this uses the index to requested results and do a Scan Seek operation on this.</p>
<p>But when we run this query</p>
<p><strong>1: select * from IndexTest</strong></p>
<p>then this query don&#8217;t use any index and return all the records(10,000) and  do a Clustered Index Scan operation.</p>
<p>Try one more query which is..</p>
<p><strong>1: select * from IndexTest where reg_no &gt;=&#8217;-1&#8242;</strong></p>
<p><strong></strong><br />
this query also returns all the records(10,000) but do a Clustered Index Seek operation on this.</p>
<p>So here we a lots of things about indexes about non-clustered and Unique Clustered indexes .</p>
<p>There are lot more about indexes in Sql Server 2008 there is a feature is called filtered indexes  which is very useful to improve the performance .</p>
<p>Thanks.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ashishgilhotra.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ashishgilhotra.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ashishgilhotra.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ashishgilhotra.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ashishgilhotra.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ashishgilhotra.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ashishgilhotra.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ashishgilhotra.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ashishgilhotra.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ashishgilhotra.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ashishgilhotra.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ashishgilhotra.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ashishgilhotra.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ashishgilhotra.wordpress.com/89/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashishgilhotra.wordpress.com&amp;blog=7164552&amp;post=89&amp;subd=ashishgilhotra&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ashishgilhotra.wordpress.com/2009/05/03/indexes-in-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c1c2313df2e9f4bf381ea695b7bf84e0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ashishgilhotra</media:title>
		</media:content>
	</item>
		<item>
		<title>CTE&#8217;s and Recursive CTE&#8217;s</title>
		<link>http://ashishgilhotra.wordpress.com/2009/04/22/ctes-and-recursive-ctes/</link>
		<comments>http://ashishgilhotra.wordpress.com/2009/04/22/ctes-and-recursive-ctes/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 18:22:38 +0000</pubDate>
		<dc:creator>ashishgilhotra</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[CTE]]></category>
		<category><![CDATA[RECURSIVE]]></category>

		<guid isPermaLink="false">http://ashishgilhotra.wordpress.com/?p=86</guid>
		<description><![CDATA[Hi guys today we talk something about recursive CTE &#8216;s So CTE(Common Table Expression) can be thought of as a temporary result set that is defined within the execution scope of a single SELECT, INSERT, UPDATE or DELETE statement.You can say that CTE is improved version on derived tables in SQL 2000. CTE is used [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashishgilhotra.wordpress.com&amp;blog=7164552&amp;post=86&amp;subd=ashishgilhotra&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi guys today we talk something about recursive CTE &#8216;s</p>
<p>So CTE(Common Table Expression) can be thought of as a temporary result set that is defined within the execution scope of a single SELECT, INSERT, UPDATE or DELETE statement.You can say that CTE is improved version on derived tables in SQL 2000.</p>
<p>CTE is used for many purposes like for data recursion,generate a series of numbers,date etc.</p>
<p>CTE is extensively used in Recursion&#8230;. here u can find a tree structure with CTE</p>
<p>here i show you how to recurse through a CTE</p>
<p><strong>&#8211; Create a table first to play with</strong></p>
<p><strong>CREATE TABLE [dbo].[RecurseCTE](<br />
[empid] [int] NULL,<br />
[empname] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,<br />
[mgrid] [int] NULL<br />
) ON [PRIMARY]</strong></p>
<p><strong>&#8211; populate some data to play with</strong></p>
<p><strong>insert into [RecurseCTE]<br />
select 1,    &#8216;a&#8217;,    0 union all<br />
select 2,    &#8216;B&#8217;,    1 union all<br />
select 3,    &#8216;C&#8217;,    1 union all<br />
select 4,    &#8216;D&#8217;,    2 union all<br />
select 5,    &#8216;E&#8217;,    2 union all<br />
select 6,    &#8216;F&#8217;,    3 union all<br />
select 7,    &#8216;G&#8217;,    3 union all<br />
select 8,    &#8216;H&#8217;,    4 union all<br />
select 9,    &#8216;I&#8217;,    4 union all<br />
select 10,    &#8216;J&#8217;,    5 union all<br />
select 11,    &#8216;K&#8217;,    5 union all<br />
select 12,    &#8216;L&#8217;,    6 union all<br />
select 13,    &#8216;M&#8217;,    6 union all<br />
select 14,    &#8216;N&#8217;,    7 union all<br />
select 15,    &#8216;O&#8217;,    7 union all<br />
select 16,    &#8216;P&#8217;,    8 union all<br />
select 17,    &#8216;Q&#8217;,    8 union all<br />
select 18,    &#8216;R&#8217;,    9 union all<br />
select 19,    &#8216;S&#8217;,    9 union all<br />
select 20,    &#8216;T&#8217;,    10 union all<br />
select 21,    &#8216;U&#8217;,    10 union all<br />
select 22,    &#8216;V&#8217;,    11 union all<br />
select 23,    &#8216;W&#8217;,    11 union all<br />
select 24,    &#8216;X&#8217;,    12 union all<br />
select 25,    &#8216;Y&#8217;,    12</strong></p>
<p>so here is our recursive CTE</p>
<p><strong>&#8211; Declare Recursive CTE<br />
;with descedent (Mgrid)<br />
AS<br />
(select mgrid from<br />
</strong><strong>RecurseCTE </strong><strong>where empid=25<br />
&#8211; Here you initialize your query<br />
union all<br />
select T.mgrid from descedent D<br />
join </strong><strong>RecurseCTE </strong><strong>T<br />
on t.empid=D.mgrID<br />
&#8211; Here is Recursive Part Of Query which Recurse through all the data<br />
)<br />
SELECT Mgrid<br />
FROM descedent<br />
OPTION (MAXRECURSION 0)</strong></p>
<p>So in this query you just start with query which fetch managerid associated with empid 25 It gives you result 12 and store in CTE(mgrid) so now just recursive part of query do all the things&#8230;</p>
<p>and it also uses to generate sequence dates like this&#8230;.</p>
<p><strong>DECLARE    @StartDate datetime, @EndDate datetime<br />
SELECT @StartDate = &#8217;20090101&#8242;, @EndDate = &#8217;20090131&#8242;<br />
;WITH IntervalSet AS<br />
(<br />
SELECT @StartDate AS StartDate<br />
UNION ALL<br />
SELECT DATEADD(dd,1,Startdate) AS StartDate<br />
FROM   IntervalSet<br />
WHERE  DATEADD(d,1,Startdate)&lt;=@EndDate<br />
)<br />
SELECT * FROM IntervalSet<br />
OPTION(MAXRECURSION 32500)</strong></p>
<p>So this will generate just the dates from your <strong>@</strong>StartDate to @Enddate&#8230;</p>
<p>So in this way CTE are very helpful in many ways,,,if u have any question about CTE. Then just let me know i will soon get back to you.</p>
<p>Thanks and Happy Quering..</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ashishgilhotra.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ashishgilhotra.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ashishgilhotra.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ashishgilhotra.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ashishgilhotra.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ashishgilhotra.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ashishgilhotra.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ashishgilhotra.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ashishgilhotra.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ashishgilhotra.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ashishgilhotra.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ashishgilhotra.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ashishgilhotra.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ashishgilhotra.wordpress.com/86/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashishgilhotra.wordpress.com&amp;blog=7164552&amp;post=86&amp;subd=ashishgilhotra&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ashishgilhotra.wordpress.com/2009/04/22/ctes-and-recursive-ctes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c1c2313df2e9f4bf381ea695b7bf84e0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ashishgilhotra</media:title>
		</media:content>
	</item>
		<item>
		<title>Data\Table Partitioning and Indexing</title>
		<link>http://ashishgilhotra.wordpress.com/2009/04/16/datatable-partitioning-and-indexing/</link>
		<comments>http://ashishgilhotra.wordpress.com/2009/04/16/datatable-partitioning-and-indexing/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 15:43:27 +0000</pubDate>
		<dc:creator>ashishgilhotra</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Performance Tuning]]></category>

		<guid isPermaLink="false">http://ashishgilhotra.wordpress.com/?p=80</guid>
		<description><![CDATA[  Hi to all&#8230; Here is again a new stuff for you guys,, here we talk today something about performance tunning in SQl&#8230; as SQL Server 2005 provide us several new features,,,from which we can better manages our Databases and Tables .. SO here is one thing called table partitioning.. So data partitioning is just [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashishgilhotra.wordpress.com&amp;blog=7164552&amp;post=80&amp;subd=ashishgilhotra&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p> </p>
<p>Hi to all&#8230;</p>
<p>Here is again a new stuff for you guys,,</p>
<p>here we talk today something about performance tunning in SQl&#8230;</p>
<p>as SQL Server 2005 provide us several new features,,,from which we can better manages our Databases and Tables ..</p>
<p>SO here is one thing called table partitioning..</p>
<p>So data partitioning is just split large tables and indexes into smaller tables and indexes..</p>
<p>Data partitioning improves the performance, reduces contention and increases availability of data.</p>
<p> </p>
<p>Data partitioning is based on any column in the table,,,,</p>
<p>so here we start&#8230;.</p>
<p> </p>
<p>We just Start wid a very basic thing in table partitioning,,</p>
<p> </p>
<p>First we have to Create i Partitioning function&#8230;&#8230;.Data Partitioning is based on partitioning function like,,,</p>
<p>This,,,,</p>
<p> </p>
<p><strong>/* Create a partition function. */</strong></p>
<p> </p>
<p><strong>Create Function [PARTITONRANGE] (int)</strong></p>
<p><span><strong> </strong></span><strong>AS RANGE LEFT FOR VALUES (100000)</strong></p>
<p> </p>
<p>Here we can use two keywords <strong>left </strong>and <strong>right</strong>..</p>
<p>left for -infinity to that value&#8230;</p>
<p>right for that value to infinity&#8230;</p>
<p><span> </span></p>
<p>So here we create a partition function which partion data on the basis of ..</p>
<p>the values from -infinity to 100000 and above this&#8230;</p>
<p>ok</p>
<p>afte that make a scheme for that and associate it with partition function</p>
<p> </p>
<p><strong>/* Associate the partition function with a partition scheme. */</strong></p>
<p><strong><br />
</strong></p>
<p><strong>CREATE PARTITION SCHEME [PartitionScheme]</strong></p>
<p><strong>        AS PARTITION [PartitionRange]</strong></p>
<p><strong>        All TO ([PRIMARY]);</strong></p>
<p><span> </span></p>
<p>Now a Table to play with&#8230;</p>
<p> </p>
<p><strong>/* Create a partitioned table. */</strong></p>
<p><strong>CREATE TABLE MyPartitiontable1Table</strong></p>
<p><strong>       (ID INT NOT NULL,</strong></p>
<p><strong>        Date DATETIME,</strong></p>
<p><strong>        Cost money)</strong></p>
<p><strong>      ON [PartitionScheme] (ID);</strong></p>
<p><strong><br />
</strong></p>
<p><strong>CREATE UNIQUE CLUSTERED INDEX MyTable_IXC</strong></p>
<p><strong>       ON MyPartitiontable1Table(ID)</strong></p>
<p><strong>       ON [PartitionScheme]  (ID)</strong></p>
<p><span> </span>   </p>
<p><span> </span>   </p>
<p><strong>/* Create some records to play with. */</strong></p>
<p><strong>declare @count int</strong></p>
<p><strong>set @count =1</strong></p>
<p><strong>while @count &lt;=100</strong></p>
<p><strong>begin</strong></p>
<p><strong>insert into MyPartitiontable1Table select @count,getdate(),100.00</strong></p>
<p><strong>set @count=@count+1</strong></p>
<p><strong>end</strong></p>
<p><strong>set @count =100002</strong></p>
<p><strong>while @count &lt;=100202</strong></p>
<p><strong>begin</strong></p>
<p><strong>insert into MyPartitiontable1Table select @count,getdate(),200.00</strong></p>
<p><strong>set @count=@count+1</strong></p>
<p><strong>end</strong></p>
<p> </p>
<p>Now create index on cost one is on partition and other is simple index&#8230;</p>
<p>like</p>
<p> </p>
<p><strong>/* Now let’s create an partitioned index. */</strong></p>
<p><strong>CREATE NONCLUSTERED INDEX IX_ID_aligned</strong></p>
<p><strong>    ON dbo.MyPartitiontable1Table(cost)</strong></p>
<p><strong>    ON [PartitionScheme](id); </strong></p>
<p><span> </span><strong>/* you don&#8217;t actually need to declare the last</strong></p>
<p><strong>       line of this unless you want to create the</strong></p>
<p><strong>       index on a different partitioning scheme.   */</strong></p>
<p><span> </span>   </p>
<p><span> </span>   </p>
<p><span> </span>   </p>
<p><strong>/* Now let’s create an unpartitioned index. */</strong></p>
<p><span><strong> </strong></span><strong>CREATE NONCLUSTERED INDEX IX_orders_unpartitioned</strong></p>
<p><strong>    ON dbo.MyPartitiontable1Table(cost)</strong></p>
<p><strong>    ON [PRIMARY];</strong></p>
<p><span><strong> </strong></span></p>
<p><span><strong> </strong></span></p>
<p><span><strong> </strong></span></p>
<p> </p>
<p><span> </span></p>
<p>Now just see your data which stores in different indexes,,,,which u make on your table&#8230;</p>
<p>here is a script to do so&#8230;</p>
<p> </p>
<p><strong>/* Let&#8217;s take a look at our index partitions */</strong></p>
<p><strong><br />
</strong></p>
<p><strong>SELECT i.name</strong></p>
<p><strong>    , i.index_id</strong></p>
<p><strong>    , p.partition_number</strong></p>
<p><strong>    , p.ROWS</strong></p>
<p><strong>FROM sys.partitions AS p</strong></p>
<p><strong>Join sys.indexes AS i</strong></p>
<p><strong>    ON p.OBJECT_ID = i.OBJECT_ID </strong></p>
<p><strong>   And p.index_id = i.index_id</strong></p>
<p><strong>WHERE p.OBJECT_ID = OBJECT_ID(&#8216;MyPartitiontable1Table&#8217;)</strong></p>
<p><strong>ORDER BY i.index_id, p.partition_number;</strong></p>
<p> </p>
<p>So the result like this&#8230;</p>
<p><img class="alignleft size-full wp-image-82" title="Index Partitioning" src="http://ashishgilhotra.files.wordpress.com/2009/04/imagepartition1.jpg?w=510&#038;h=317" alt="Index Partitioning" width="510" height="317" /></p>
<p> </p>
<p> </p>
<p>so in this you can partition your table&#8230; and see the data which your indexes stored in partioton,,,</p>
<p>so by this u can partition your tables and make indexes on your partitioned data&#8230;</p>
<p>i will post more about Performance tuning soon,,</p>
<p>till then ..</p>
<p>Thanks and Happy Quering&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ashishgilhotra.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ashishgilhotra.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ashishgilhotra.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ashishgilhotra.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ashishgilhotra.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ashishgilhotra.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ashishgilhotra.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ashishgilhotra.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ashishgilhotra.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ashishgilhotra.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ashishgilhotra.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ashishgilhotra.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ashishgilhotra.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ashishgilhotra.wordpress.com/80/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashishgilhotra.wordpress.com&amp;blog=7164552&amp;post=80&amp;subd=ashishgilhotra&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ashishgilhotra.wordpress.com/2009/04/16/datatable-partitioning-and-indexing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c1c2313df2e9f4bf381ea695b7bf84e0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ashishgilhotra</media:title>
		</media:content>

		<media:content url="http://ashishgilhotra.files.wordpress.com/2009/04/imagepartition1.jpg" medium="image">
			<media:title type="html">Index Partitioning</media:title>
		</media:content>
	</item>
		<item>
		<title>How to Retrive Images from Sql Table</title>
		<link>http://ashishgilhotra.wordpress.com/2009/04/11/how-to-retrive-images-from-sql-table/</link>
		<comments>http://ashishgilhotra.wordpress.com/2009/04/11/how-to-retrive-images-from-sql-table/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 13:03:24 +0000</pubDate>
		<dc:creator>ashishgilhotra</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[BCP]]></category>
		<category><![CDATA[Image retriveing]]></category>

		<guid isPermaLink="false">http://ashishgilhotra.wordpress.com/?p=73</guid>
		<description><![CDATA[In my last post in tell you guys that how to insert images in any SQL Table so this is the post for &#8221; How to retrive images from Sql Table? &#8220; So here we go last time we insert images in Sql Table Imagetest so here we just check data in that table first&#8230;. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashishgilhotra.wordpress.com&amp;blog=7164552&amp;post=73&amp;subd=ashishgilhotra&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://ashishgilhotra.wordpress.com/2009/04/09/insert-image-in-to-sql-table/" target="_blank">last post</a> in tell you guys that how to insert images in any SQL Table so this is the post for &#8221; How to retrive images from Sql Table? &#8220;</p>
<p>So here we go last time we insert images in Sql Table Imagetest so here we just check data in that table first&#8230;.</p>
<p>&#8211;Check Data In Table</p>
<p><strong>select * from IMAGETEST</strong></p>
<p>now just make a format file from it like this&#8230;.</p>
<p><strong>EXEC master..xp_cmdshell &#8216;BCP ashish.dbo.imagetest format NUL -Sserver -Uusername -Ppassword -n -f  D:\My.fmt&#8217;</strong></p>
<div id="attachment_74" class="wp-caption aligncenter" style="width: 520px"><img class="size-full wp-image-74" title="myfmtfile" src="http://ashishgilhotra.files.wordpress.com/2009/04/myfmtfile.jpg?w=510&#038;h=90" alt="My.fmt" width="510" height="90" /><p class="wp-caption-text">My.fmt</p></div>
<p>now just a little bit modification in this fmt file so open it with notepad of textpad and modify it something like that&#8230;</p>
<div id="attachment_75" class="wp-caption aligncenter" style="width: 520px"><img class="size-full wp-image-75" title="newmyfmt" src="http://ashishgilhotra.files.wordpress.com/2009/04/newmyfmt.jpg?w=510&#038;h=83" alt="New fmtfile" width="510" height="83" /><p class="wp-caption-text">New fmtfile</p></div>
<p>so after made that type of modification in your format file jus  run that script to get your image back&#8230;..</p>
<p><strong>EXEC master..xp_cmdshell &#8216;bcp &#8220;select top 1 image from ashish.dbo.imagetest where id=2&#8243; queryout D:\ashu.jpg -Sserver -Uusername -Ppassword -fD:\MY.fmt&#8217;</strong></p>
<p>Here is a cursor which loop through all the records in your table and give you images in any folder so here is my working cursor for this purpose,,,,,,</p>
<p><strong>I just add one more column to my table IMAGETEST names image_name</strong>.</p>
<p>So i also add a column to your table so this is my cursor for this purpose&#8230;.</p>
<p>&#8211; cursor for image retriveing</p>
<p><strong>SET NOCOUNT ON<br />
DECLARE @ID int,@LargePhotoFileName varchar(200) ,@Sqlstmt varchar(2000)<br />
DECLARE Cursor_ProductPhoto CURSOR FOR<br />
SELECT ID, IMAGEname<br />
from ashish.dbo.imagetest<br />
ORDER BY ID<br />
OPEN Cursor_ProductPhoto<br />
FETCH NEXT FROM Cursor_ProductPhoto<br />
INTO @ID, @LargePhotoFileName<br />
WHILE @@FETCH_STATUS = 0<br />
BEGIN<br />
PRINT @LargePhotoFileName<br />
Set @Sqlstmt=&#8217;bcp &#8220;SELECT top 1 image FROM ashish.dbo.imagetest where ID=&#8217;+str(@ID)+&#8217;&#8221; queryout d:\&#8217;+ltrim(@LargePhotoFileName)+&#8217; -Sserver -Uusername -Ppassword -fD:\PP.fmt&#8217;<br />
print @sqlstmt<br />
FETCH NEXT FROM Cursor_ProductPhoto<br />
INTO @ID, @LargePhotoFileName<br />
END<br />
CLOSE Cursor_ProductPhoto<br />
DEALLOCATE Cursor_ProductPhoto</strong></p>
<p>Thanks and Happy Quering&#8230;<strong><br />
</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ashishgilhotra.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ashishgilhotra.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ashishgilhotra.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ashishgilhotra.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ashishgilhotra.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ashishgilhotra.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ashishgilhotra.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ashishgilhotra.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ashishgilhotra.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ashishgilhotra.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ashishgilhotra.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ashishgilhotra.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ashishgilhotra.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ashishgilhotra.wordpress.com/73/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashishgilhotra.wordpress.com&amp;blog=7164552&amp;post=73&amp;subd=ashishgilhotra&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ashishgilhotra.wordpress.com/2009/04/11/how-to-retrive-images-from-sql-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c1c2313df2e9f4bf381ea695b7bf84e0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ashishgilhotra</media:title>
		</media:content>

		<media:content url="http://ashishgilhotra.files.wordpress.com/2009/04/myfmtfile.jpg" medium="image">
			<media:title type="html">myfmtfile</media:title>
		</media:content>

		<media:content url="http://ashishgilhotra.files.wordpress.com/2009/04/newmyfmt.jpg" medium="image">
			<media:title type="html">newmyfmt</media:title>
		</media:content>
	</item>
		<item>
		<title>Insert Image In to Sql Table</title>
		<link>http://ashishgilhotra.wordpress.com/2009/04/09/insert-image-in-to-sql-table/</link>
		<comments>http://ashishgilhotra.wordpress.com/2009/04/09/insert-image-in-to-sql-table/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 13:08:57 +0000</pubDate>
		<dc:creator>ashishgilhotra</dc:creator>
				<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://ashishgilhotra.wordpress.com/?p=71</guid>
		<description><![CDATA[People asked me many times that &#8220;How  to Store Images In SQL Server Table&#8221; So here i post a method which i explore recently from which we can store images in SQL Server Table&#8230;&#8230; On this post i just show you the way from which we can insert images in SQl Server Table&#8230;.. So here [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashishgilhotra.wordpress.com&amp;blog=7164552&amp;post=71&amp;subd=ashishgilhotra&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span class="Apple-style-span" style="border-collapse:separate;color:#000000;font-family:Arial;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;orphans:2;text-indent:0;text-transform:none;white-space:normal;widows:2;word-spacing:0;">People asked me many times that</span> &#8220;How  to Store Images In SQL Server Table&#8221; So here i post a method which i explore recently from which we can store images in SQL Server Table&#8230;&#8230;</p>
<p>On this post i just show you the way from which we can insert images in SQl Server Table&#8230;..</p>
<p>So here we start with Declare a Table in which images are storedso here we go by just creating a table&#8230;.like..</p>
<p><strong>CREATE TABLE [dbo].[ImageTest](<br />
[ID] [int] IDENTITY(1,1) NOT NULL,<br />
[Image] [varbinary](max) NULL<br />
SQL_Latin1_General_CP1_CI_AS NULL<br />
) ON [PRIMARY]</strong></p>
<p>So by this we can create table with two columns one is identity and other image . Image column is varbinary (max) which stores the image in binary format&#8230;</p>
<p>So here is the code from which we can insert image in to this table &#8230;..</p>
<p>&#8211;Image Insert</p>
<p><strong>INSERT INTO [dbo].[ImageTest]([Image])<br />
SELECT * FROM<br />
OPENROWSET(BULK N&#8217;D:\images1\image.jpg&#8217;, SINGLE_BLOB) AS Document<br />
GO</strong></p>
<p>Here D:\images1= Physical Path of Images OR Folder where images <span class="Apple-style-span" style="border-collapse:separate;color:#000000;font-family:Arial;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;orphans:2;text-indent:0;text-transform:none;white-space:pre;widows:2;word-spacing:0;">actually</span> stored&#8230;.</p>
<p>so in this way you can store images in your SQL Table..</p>
<p>u can see your data</p>
<p>&#8211; Check Data</p>
<p>select * from IMAGETEST</p>
<p>You have to ENABLE &#8220;<strong>Ad Hoc Remote Queries</strong>&#8220;  from your Sql Server Surface Area Configuration</p>
<p>OR USE</p>
<p>&#8220;<strong>Sp_Configure</strong>&#8221; to do so..</p>
<p>So here is the way from which you can store IMAGES in your SQL Table</p>
<p>This is only a way but from my opinion you just store only the physical path in your table and try to retrive Images in your application from your physical path,,,</p>
<p>but this is also a way to do so&#8230;</p>
<p>in my next post you will find how to retrive images from SQL Table i will show you the way that how u can retrive images from SQL table..</p>
<p>So jus keep watching&#8230;.</p>
<p>Thanks and Happy Quering&#8230;.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ashishgilhotra.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ashishgilhotra.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ashishgilhotra.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ashishgilhotra.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ashishgilhotra.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ashishgilhotra.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ashishgilhotra.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ashishgilhotra.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ashishgilhotra.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ashishgilhotra.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ashishgilhotra.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ashishgilhotra.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ashishgilhotra.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ashishgilhotra.wordpress.com/71/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashishgilhotra.wordpress.com&amp;blog=7164552&amp;post=71&amp;subd=ashishgilhotra&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ashishgilhotra.wordpress.com/2009/04/09/insert-image-in-to-sql-table/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c1c2313df2e9f4bf381ea695b7bf84e0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ashishgilhotra</media:title>
		</media:content>
	</item>
		<item>
		<title>Pivot Data</title>
		<link>http://ashishgilhotra.wordpress.com/2009/04/08/pivot-data/</link>
		<comments>http://ashishgilhotra.wordpress.com/2009/04/08/pivot-data/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 13:34:45 +0000</pubDate>
		<dc:creator>ashishgilhotra</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[PIVOT]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://ashishgilhotra.wordpress.com/?p=67</guid>
		<description><![CDATA[Hi.. There is a example of pivot query to PIVOT your data &#8230;many times u need to show your data in this way so here is a example to do so&#8230; first make a table and populate some data in it&#8230;&#8230; after that check the data and at last PIVOT that Data&#8230;&#8230;&#8230;&#8230;&#8230; Here is the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashishgilhotra.wordpress.com&amp;blog=7164552&amp;post=67&amp;subd=ashishgilhotra&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi..</p>
<p>There is a example of pivot query to PIVOT your data &#8230;many times u need to show your data in this way so here is a example to do so&#8230;</p>
<p>first make a table and populate some data in it&#8230;&#8230;</p>
<p>after that check the data and at last</p>
<p>PIVOT that Data&#8230;&#8230;&#8230;&#8230;&#8230;</p>
<p>Here is the whole script to do so&#8230;<br />
<strong>&#8211; Create Table<br />
declare @sales TABLE (<br />
SALEID VARCHAR(20),<br />
SALEDATE DATETIME,<br />
SALEAmount MONEY )</p>
<p>&#8211;Populate Data In it<br />
INSERT INTO @SAles<br />
SELECT &#8217;001&#8242;, &#8217;2005-01-01&#8242;, 100 UNION<br />
SELECT &#8217;002&#8242;, &#8217;2005-02-01&#8242;, 40 UNION<br />
SELECT &#8217;003&#8242;, &#8217;2005-03-01&#8242;, 60 UNION<br />
SELECT &#8217;004&#8242;, &#8217;2005-03-10&#8242;, 15 UNION<br />
SELECT &#8217;005&#8242;, &#8217;2005-04-01&#8242;, 50 UNION<br />
SELECT &#8217;006&#8242;, &#8217;2005-05-01&#8242;, 77 UNION<br />
SELECT &#8217;007&#8242;, &#8217;2005-06-01&#8242;, 12 UNION<br />
SELECT &#8217;008&#8242;, &#8217;2005-06-05&#8242;, 56 UNION<br />
SELECT &#8217;009&#8242;, &#8217;2005-07-01&#8242;, 34 UNION<br />
SELECT &#8217;010&#8242;, &#8217;2005-08-01&#8242;, 76 UNION<br />
SELECT &#8217;011&#8242;, &#8217;2005-09-01&#8242;, 24 UNION<br />
SELECT &#8217;012&#8242;, &#8217;2005-09-20&#8242;, 10 UNION<br />
SELECT &#8217;013&#8242;, &#8217;2005-10-01&#8242;, 15 UNION<br />
SELECT &#8217;014&#8242;, &#8217;2005-11-01&#8242;, 40 UNION<br />
SELECT &#8217;015&#8242;, &#8217;2005-11-15&#8242;, 21 UNION<br />
SELECT &#8217;016&#8242;, &#8217;2005-12-01&#8242;, 17 UNION<br />
SELECT &#8217;017&#8242;, &#8217;2006-01-01&#8242;, 34 UNION<br />
SELECT &#8217;018&#8242;, &#8217;2006-02-01&#8242;, 24 UNION<br />
SELECT &#8217;019&#8242;, &#8217;2006-03-01&#8242;, 56 UNION<br />
SELECT &#8217;020&#8242;, &#8217;2006-03-10&#8242;, 43 UNION<br />
SELECT &#8217;021&#8242;, &#8217;2006-04-01&#8242;, 24 UNION<br />
SELECT &#8217;022&#8242;, &#8217;2006-05-01&#8242;, 11 UNION<br />
SELECT &#8217;023&#8242;, &#8217;2006-06-01&#8242;, 6 UNION<br />
SELECT &#8217;024&#8242;, &#8217;2006-06-05&#8242;, 13</p>
<p>&#8211; Chech the data in table<br />
select * from @sales</p>
<p>&#8211; Here Starts Pivot Query w<br />
SELECT *<br />
FROM (SELECT year(SALEDATE) as [year], left(datename(month,saledate),3)as [month], SALEAmount as Amount FROM @sales) as A<br />
PIVOT<br />
(<br />
SUM(Amount)<br />
FOR [month]<br />
IN (jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec)<br />
)<br />
AS B<br />
</strong></p>
<p>so in this way u can pivot your data&#8230;.</p>
<p>its just a simple example to PIVOT query&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ashishgilhotra.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ashishgilhotra.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ashishgilhotra.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ashishgilhotra.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ashishgilhotra.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ashishgilhotra.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ashishgilhotra.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ashishgilhotra.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ashishgilhotra.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ashishgilhotra.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ashishgilhotra.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ashishgilhotra.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ashishgilhotra.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ashishgilhotra.wordpress.com/67/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashishgilhotra.wordpress.com&amp;blog=7164552&amp;post=67&amp;subd=ashishgilhotra&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ashishgilhotra.wordpress.com/2009/04/08/pivot-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c1c2313df2e9f4bf381ea695b7bf84e0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ashishgilhotra</media:title>
		</media:content>
	</item>
		<item>
		<title>BCP for TEXT and XML file</title>
		<link>http://ashishgilhotra.wordpress.com/2009/04/08/bcp-for-text-and-xml-file/</link>
		<comments>http://ashishgilhotra.wordpress.com/2009/04/08/bcp-for-text-and-xml-file/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 13:16:31 +0000</pubDate>
		<dc:creator>ashishgilhotra</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[BCP]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[TEXT]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://ashishgilhotra.wordpress.com/?p=64</guid>
		<description><![CDATA[Hi &#8230; There is a stuff to export ur data in to text file or XML file&#8230;. here i post store procedure to do that&#8230;. Here this is procedure to export your data to a plain text file&#8230; CREATE Procedure [dbo].[BCP_Text_File] ( @table varchar(100), @FileName varchar(100) ) as If exists(Select * from information_Schema.tables where table_name=@table) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashishgilhotra.wordpress.com&amp;blog=7164552&amp;post=64&amp;subd=ashishgilhotra&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi &#8230;</p>
<p>There is a stuff to export ur data in to text file or XML file&#8230;.</p>
<p>here i post store procedure to do that&#8230;.</p>
<p>Here this is procedure to export your data to a plain text file&#8230;</p>
<p><strong><br />
CREATE Procedure [dbo].[BCP_Text_File]<br />
(<br />
@table varchar(100),<br />
@FileName varchar(100)<br />
)<br />
as<br />
If exists(Select * from information_Schema.tables where table_name=@table)<br />
Begin<br />
Declare @str varchar(1000)<br />
set @str=&#8217;Exec Master..xp_Cmdshell &#8221;bcp &#8220;Select * from &#8216;+db_name()+&#8217;..&#8217;+@table+&#8217;&#8221; queryout &#8220;&#8216;+@FileName+&#8217;&#8221; -Sservername -Uusername -Ppassword -c&#8221;&#8217;<br />
Exec(@str)<br />
end<br />
else<br />
Select &#8216;The table &#8216;+@table+&#8217; does not exist in the database&#8217;</strong></p>
<p>And here the version which export data in XML format&#8230;</p>
<p><strong>CREATE Procedure [dbo].[BCP_XML_File]<br />
(<br />
@table varchar(100),<br />
@FileName varchar(100)<br />
)<br />
as<br />
If exists(Select * from information_Schema.tables where table_name=@table)<br />
Begin<br />
Declare @str varchar(1000)<br />
set @str=&#8217;Exec Master..xp_Cmdshell &#8221;bcp &#8220;Select * from &#8216;+db_name()+&#8217;..&#8217;+@table+&#8217; for XML AUTO&#8221; queryout &#8220;&#8216;+@FileName+&#8217;&#8221; -Sservername -Uusername -Ppassword -c -r -t&#8221;&#8217;<br />
Exec(@str)<br />
end<br />
else<br />
Select &#8216;The table &#8216;+@table+&#8217; does not exist in the database&#8217;</strong></p>
<p>So in this way u can export your data in Text or XMl file&#8230;.</p>
<p>Thanks and Happy Quering&#8230;.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ashishgilhotra.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ashishgilhotra.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ashishgilhotra.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ashishgilhotra.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ashishgilhotra.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ashishgilhotra.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ashishgilhotra.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ashishgilhotra.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ashishgilhotra.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ashishgilhotra.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ashishgilhotra.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ashishgilhotra.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ashishgilhotra.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ashishgilhotra.wordpress.com/64/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ashishgilhotra.wordpress.com&amp;blog=7164552&amp;post=64&amp;subd=ashishgilhotra&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ashishgilhotra.wordpress.com/2009/04/08/bcp-for-text-and-xml-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c1c2313df2e9f4bf381ea695b7bf84e0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ashishgilhotra</media:title>
		</media:content>
	</item>
	</channel>
</rss>
