<?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>MuNiRs</title>
	<atom:link href="http://irfanmunir.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://irfanmunir.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Sat, 10 Oct 2009 14:04:51 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='irfanmunir.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/d0aaa875e69f82eb439ce7af1843b1dc?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>MuNiRs</title>
		<link>http://irfanmunir.wordpress.com</link>
	</image>
			<item>
		<title>Going Mouseless &#8211; Implementing Keyboard Shortcuts in ASP.NET 2.0 Using Javascript</title>
		<link>http://irfanmunir.wordpress.com/2008/11/14/going-mouseless-implementing-keyboard-shortcuts-in-aspnet-20-using-javascript/</link>
		<comments>http://irfanmunir.wordpress.com/2008/11/14/going-mouseless-implementing-keyboard-shortcuts-in-aspnet-20-using-javascript/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 10:51:38 +0000</pubDate>
		<dc:creator>Irfan Munir</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://irfanmunir.wordpress.com/?p=46</guid>
		<description><![CDATA[Going Mouseless &#8211; Implementing Keyboard Shortcuts in ASP.NET 2.0 Using Javascript

Keyboard shortcuts improve productivity by accomplishing tasks more quickly and without much effort. In applications, where the user has to select from a variety of actions to perform, keyboard shortcuts can save on time and effort. If you have used the new YahooMail or Gmail, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanmunir.wordpress.com&blog=853136&post=46&subd=irfanmunir&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><div style="margin:24pt 0 0;"><strong><span style="font-size:x-large;"><span style="font-family:Cambria;color:#365f91;font-size:large;">Going Mouseless &#8211; Implementing Keyboard Shortcuts in ASP.NET 2.0 Using Javascript</span></span></strong></div>
<div style="margin:0 0 10pt;"></div>
<div style="margin:0 0 10pt;"><span style="font-size:x-small;"><span style="font-family:Verdana;">Keyboard shortcuts improve productivity by accomplishing tasks more quickly and without much effort<span style="color:black;">. In applications, where the user has to select from a variety of actions to perform, keyboard shortcuts can </span>save on time and effort. If you have used the new YahooMail or Gmail, you will be quiet familiar with these shortcuts. In this article, we will explore how to implement shortcuts and use it in our ASP.NET applications. Please note that this solution is Internet Explorer(IE) specific.</span></span></div>
<div style="margin:0 0 10pt;"><span style="font-family:Verdana;font-size:x-small;">I was recently implementing a solution where users needed the ability to use shortcuts in ASP.NET applications, similar to what we see in Gmail and Yahoo mail. The requirement was as follows:</span></div>
<div style="margin:0 0 10pt;"><strong><span style="font-size:x-small;"><span style="font-family:Verdana;">Problem Scenario</span></span></strong></div>
<div style="margin:0 0 10pt;"><span style="font-family:Verdana;font-size:x-small;">The user visits a screen which contains a series of links (linkbuttons). The user is then required to click on one of the links to navigate to a different page to perform some action (For eg: filling forms). After performing the action, the user returns back to the screen. The process is repeated by the user, quiet a number of times. Now if you visualize, the user has to use the mouse to click one of the links and then shift back to the keyboard to enter data. Then use the mouse again to go back to the main screen. What a pain, especially if someone is involved in data entry operations!! </span></div>
<div style="margin:0 0 10pt;"><strong><span style="font-size:x-small;"><span style="font-family:Verdana;">Solution </span></span></strong></div>
<div style="margin:0 0 10pt;"><span style="font-family:Verdana;font-size:x-small;">The solution was simple. The solution was to introduce Keyboard shortcuts into the application. The user could use a shortcut instead of the mouse, to click the linkbutton and perform an action. So let us say for example, when the user clicks ‘H’, the click event of the Home button gets fired and the user navigates to the Home page. </span></div>
<div style="margin:0 0 10pt;"><span style="font-family:Verdana;font-size:x-small;">We will see how to implement this feature in this article. It can be done easily with just a few lines of code. Follow these steps:</span></div>
<div style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span style="font-family:Verdana;font-size:x-small;">1.</span><span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span><span style="font-family:Verdana;font-size:x-small;">Create an ASP.NET website. Add a master page to the application. Also create 4 pages that will be using this master page: Default.aspx, Page1.aspx, Page2.aspx and Page3.aspx. If you are unfamiliar with MasterPages, I recommend you to read my article : </span><a href="http://www.dotnetcurry.com/ShowArticle.aspx?ID=80"><span style="font-family:Verdana;font-size:x-small;">http://www.dotnetcurry.com/ShowArticle.aspx?ID=80</span></a></div>
<div style="margin:0 0 0 .5in;"></div>
<div style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span style="font-family:Verdana;font-size:x-small;">2.</span><span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span><span style="font-family:Verdana;font-size:x-small;">In the default.aspx, drag and drop 3 link buttons to the form. Rename these linkbuttons as Page 1, Page 2 and Page 3 respectively.</span></div>
<div style="margin:0 0 0 .5in;"></div>
<div style="margin:0 0 10pt .5in;"><span style="font-family:Verdana;font-size:x-small;">The page would look like this:</span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-size:x-small;"><span style="color:blue;font-family:'Courier New';">&lt;</span><span style="color:#a31515;font-family:'Courier New';">asp</span><span style="color:blue;font-family:'Courier New';">:</span><span style="color:#a31515;font-family:'Courier New';">Content</span><span style="font-family:'Courier New';"> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;Content1&#8243;</span> <span style="color:red;">ContentPlaceHolderID</span><span style="color:blue;">=&#8221;ContentPlaceHolder1&#8243;</span> <span style="color:red;">Runat</span><span style="color:blue;">=&#8221;Server&#8221;&gt;</span> </span></span></div>
<div style="line-height:normal;margin:0;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> <span style="color:blue;">&lt;</span><span style="color:#a31515;">div</span> <span style="color:red;">style</span><span style="color:blue;">=&#8221;width: 100%; height: 154px;&#8221;&gt;</span></span></span></div>
<div style="line-height:normal;margin:0 0 0 1in;"><span style="font-size:x-small;"><span style="color:blue;font-family:'Courier New';">&lt;</span><span style="color:#a31515;font-family:'Courier New';">asp</span><span style="color:blue;font-family:'Courier New';">:</span><span style="color:#a31515;font-family:'Courier New';">LinkButton</span><span style="font-family:'Courier New';"> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;lbPage1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;</span> <span style="color:red;">PostBackUrl</span><span style="color:blue;">=&#8221;Page1.aspx&#8221;&gt;</span>Page 1<span style="color:blue;">&lt;/</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">LinkButton</span><span style="color:blue;">&gt;&lt;</span><span style="color:#a31515;">br</span> <span style="color:blue;">/&gt;</span></span></span></div>
<div style="line-height:normal;margin:0;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> <span style="color:blue;">&lt;</span><span style="color:#a31515;">br</span> <span style="color:blue;">/&gt;</span></span></span></div>
<div style="line-height:normal;margin:0 0 0 1in;"><span style="font-size:x-small;"><span style="color:blue;font-family:'Courier New';">&lt;</span><span style="color:#a31515;font-family:'Courier New';">asp</span><span style="color:blue;font-family:'Courier New';">:</span><span style="color:#a31515;font-family:'Courier New';">LinkButton</span><span style="font-family:'Courier New';"> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;lbPage2&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;</span> <span style="color:red;">PostBackUrl</span><span style="color:blue;">=&#8221;Page2.aspx&#8221;&gt;</span>Page 2<span style="color:blue;">&lt;/</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">LinkButton</span><span style="color:blue;">&gt;&lt;</span><span style="color:#a31515;">br</span> <span style="color:blue;">/&gt;</span></span></span></div>
<div style="line-height:normal;margin:0;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> <span style="color:blue;">&lt;</span><span style="color:#a31515;">br</span> <span style="color:blue;">/&gt;</span></span></span></div>
<div style="line-height:normal;margin:0 0 0 1in;"><span style="font-size:x-small;"><span style="color:blue;font-family:'Courier New';">&lt;</span><span style="color:#a31515;font-family:'Courier New';">asp</span><span style="color:blue;font-family:'Courier New';">:</span><span style="color:#a31515;font-family:'Courier New';">LinkButton</span><span style="font-family:'Courier New';"> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;lbPage3&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;</span> <span style="color:red;">PostBackUrl</span><span style="color:blue;">=&#8221;Page3.aspx&#8221;&gt;</span>Page 3<span style="color:blue;">&lt;/</span><span style="color:#a31515;">asp</span><span style="color:blue;">:</span><span style="color:#a31515;">LinkButton</span><span style="color:blue;">&gt;&lt;</span><span style="color:#a31515;">br</span> <span style="color:blue;">/&gt;</span></span></span></div>
<div style="line-height:normal;margin:0;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> <span style="color:blue;">&lt;</span><span style="color:#a31515;">br</span> <span style="color:blue;">/&gt;</span></span></span></div>
<div style="line-height:normal;margin:0;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> </span></span></div>
<div style="text-indent:.5in;line-height:normal;margin:0;"><span style="font-size:x-small;"><span style="color:blue;font-family:'Courier New';">&lt;/</span><span style="color:#a31515;font-family:'Courier New';">div</span><span style="color:blue;font-family:'Courier New';">&gt;</span></span></div>
<div style="margin:0 0 0 .5in;"><span style="font-size:x-small;"><span style="color:blue;font-family:'Courier New';">&lt;/</span><span style="color:#a31515;font-family:'Courier New';">asp</span><span style="color:blue;font-family:'Courier New';">:</span><span style="color:#a31515;font-family:'Courier New';">Content</span><span style="color:blue;font-family:'Courier New';">&gt;</span></span></div>
<div style="margin:0 0 0 .5in;"></div>
<div style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span style="font-family:Verdana;font-size:x-small;">3.</span><span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span><span style="font-family:Verdana;font-size:x-small;">In the code behind of default.aspx, add the following code to the Page_Load event</span></div>
<div style="margin:0 0 0 .5in;"></div>
<div style="margin:0 0 10pt .5in;"><span style="font-family:Verdana;font-size:x-small;">C#</span></div>
<div style="line-height:normal;margin:0;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> <span style="color:blue;">protected</span> <span style="color:blue;">void</span> Page_Load(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">EventArgs</span> e)</span></span></div>
<div style="line-height:normal;margin:0;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> { </span></span></div>
<div style="line-height:normal;margin:0 0 0 1in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;">ClientScript.RegisterClientScriptBlock(<span style="color:blue;">this</span>.GetType(), <span style="color:#a31515;">&#8220;Shortcut&#8221;</span>, <span style="color:#a31515;">&#8220;document.attachEvent (&#8216;onkeyup&#8217;,ShortcutKeys);&#8221;</span>, <span style="color:blue;">true</span>);</span></span></div>
<div style="line-height:normal;margin:0;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> }</span></span></div>
<div style="line-height:normal;margin:0;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> </span></span></div>
<div style="line-height:normal;margin:0;"><span style="font-size:x-small;"><span style="font-family:'Courier New';"> </span><span style="font-family:Verdana;">VB.NET</span></span></div>
<div style="line-height:normal;margin:0;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> </span></span></div>
<div style="line-height:normal;margin:0;"><span style="font-size:x-small;"><span style="font-family:'Courier New';"> </span><span style="color:blue;font-family:'Courier New';">Protected</span><span style="font-family:'Courier New';"> <span style="color:blue;">Sub</span> Page_Load(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> <span style="color:blue;">Object</span>, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> EventArgs)</span></span></div>
<div style="line-height:normal;margin:0 0 0 1in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;">ClientScript.RegisterClientScriptBlock(<span style="color:blue;">Me</span>.GetType(), &#8220;Shortcut&#8221;, &#8220;document.attachEvent (&#8216;onkeyup&#8217;,ShortcutKeys);&#8221;, <span style="color:blue;">True</span>)</span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-size:x-small;"><span style="color:blue;font-family:'Courier New';">End</span><span style="font-family:'Courier New';"> <span style="color:blue;">Sub</span></span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-family:Verdana;font-size:x-small;">The ClientScript.RegisterClientScriptBlock registers the client script block to the top of the rendered page using a type, key, and script literal. A client script is uniquely identified by its key and its type.</span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"></div>
<div style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span style="font-family:Verdana;font-size:x-small;">4.</span><span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span><span style="font-family:Verdana;font-size:x-small;">Add a javascript file to the project called shortcut.js. Add the following code to the javascript file.</span></div>
<div style="margin:0 0 10pt .5in;"></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-size:x-small;"><span style="color:blue;font-family:'Courier New';">function</span><span style="font-family:'Courier New';"> ShortcutKeys() </span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;">{</span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> <span style="color:green;">//alert(event.keyCode);</span></span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> </span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> <span style="color:green;">// 1 Pressed For Page1</span></span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> <span style="color:blue;">if</span> (<span style="color:blue;">event</span>.keyCode == 49)</span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> {            document.getElementById(<span style="color:#a31515;">&#8216;ctl00_ContentPlaceHolder1_lbPage1&#8242;</span>).click();</span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> }</span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> </span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> <span style="color:green;">// 2 Pressed For Page2</span></span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> <span style="color:blue;">if</span> (<span style="color:blue;">event</span>.keyCode == 50)</span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> {</span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> document.getElementById(<span style="color:#a31515;">&#8216;ctl00_ContentPlaceHolder1_lbPage2&#8242;</span>).click();</span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> }</span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> </span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> <span style="color:green;">// 3 Pressed For Page3</span></span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> <span style="color:blue;">if</span> (<span style="color:blue;">event</span>.keyCode == 51)</span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> {                      document.getElementById(<span style="color:#a31515;">&#8216;ctl00_ContentPlaceHolder1_lbPage3&#8242;</span>).click();        } </span></span></div>
<div style="text-indent:.5in;margin:0 0 10pt;"><span style="font-family:'Courier New';"><span style="font-size:x-small;">}</span></span></div>
<div style="margin:0 0 10pt .5in;"><span style="font-size:x-small;"><span style="font-family:Verdana;">The javascript, depending on the keycode, invokes the click event of the element, in our case the link button. The element is obtained by using document.getElementById(<span style="color:#a31515;">&#8216;</span><span style="color:maroon;"> &#8216;&lt;%=Control.ClientID%&gt;&#8217;</span><span style="color:#a31515;">&#8216;</span>). </span></span></div>
<div style="margin:0 0 10pt .5in;"><span style="font-size:x-small;"><span style="font-family:Verdana;">Note: While using Master Pages, you need to refer to the control using the control&#8217;s ClientID. I have directly used the ID generated. </span></span></div>
<div style="text-indent:-.25in;margin:0 0 10pt .5in;"><span><span style="font-family:Verdana;font-size:x-small;">5.</span><span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span><span style="font-family:Verdana;font-size:x-small;">Now refer to the javascript in the MasterPage.</span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-size:x-small;"><span style="color:blue;font-family:'Courier New';">&lt;</span><span style="color:#a31515;font-family:'Courier New';">head</span><span style="font-family:'Courier New';"> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;&gt;</span></span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> <span style="color:blue;">&lt;</span><span style="color:#a31515;">title</span><span style="color:blue;">&gt;</span>Untitled Page<span style="color:blue;">&lt;/</span><span style="color:#a31515;">title</span><span style="color:blue;">&gt;</span></span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> <span style="color:blue;">&lt;</span><span style="color:#a31515;">script</span> <span style="color:red;">type</span><span style="color:blue;">=&#8221;text/javascript&#8221;</span> <span style="color:red;">language</span><span style="color:blue;">=&#8221;javascript&#8221;</span> <span style="color:red;">src</span><span style="color:blue;">=&#8221;shortcut.js&#8221;&gt;</span> <span style="color:blue;">&lt;/</span><span style="color:#a31515;">script</span><span style="color:blue;">&gt;</span></span></span></div>
<div style="margin:0 0 10pt .5in;"><span style="font-size:x-small;"><span style="color:blue;font-family:'Courier New';">&lt;/</span><span style="color:#a31515;font-family:'Courier New';">head</span><span style="color:blue;font-family:'Courier New';">&gt;</span></span></div>
<div style="margin:0 0 10pt .5in;"><span style="font-family:Verdana;font-size:x-small;">The keyboard shortcut functionality has been added to the Default.aspx. Before we go ahead and test it, let us make the other pages too ‘mouseless’.</span></div>
<div style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span style="font-family:Verdana;font-size:x-small;">6.</span><span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span><span style="font-family:Verdana;font-size:x-small;">Add the keyboard functionality in each of the pages (Page1, 2 and 3). To do so, add a button called btnHome to each of the pages. Set the PostBackUrl property of btnHome to ‘Default.aspx’.</span></div>
<div style="margin:0 0 0 .5in;"></div>
<div style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span style="font-family:Verdana;font-size:x-small;">7.</span><span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span><span style="font-family:Verdana;font-size:x-small;">In the shortcut.js, add another method to handle the event for the Home button using the keyboard shortcut “H”</span></div>
<div style="margin:0 0 10pt .5in;"></div>
<div style="text-indent:.25in;line-height:normal;margin:0 0 0 .25in;"><span style="font-size:x-small;"><span style="color:blue;font-family:'Courier New';">function</span><span style="font-family:'Courier New';"> HomeKey()</span></span></div>
<div style="text-indent:.25in;line-height:normal;margin:0 0 0 .25in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;">{</span></span></div>
<div style="line-height:normal;margin:0 0 0 .25in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> <span style="color:blue;">if</span>(<span style="color:blue;">event</span>.keyCode == 72)</span></span></div>
<div style="text-indent:.5in;line-height:normal;margin:0;"><span style="font-family:'Courier New';"><span style="font-size:x-small;">{        document.getElementById(<span style="color:#a31515;">&#8216;ctl00_ContentPlaceHolder1_btnHome&#8217;</span>).click();</span></span></div>
<div style="line-height:normal;margin:0 0 0 .25in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> }</span></span></div>
<div style="margin:0 0 10pt .25in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> }</span></span></div>
<div style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span style="font-family:Verdana;font-size:x-small;">8.</span><span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span><span style="font-family:Verdana;font-size:x-small;">Now register the newly added Client script in each of your pages as shown below :</span></div>
<div style="margin:0 0 0 .5in;"></div>
<div style="margin:0 0 10pt .5in;"><span style="font-family:Verdana;font-size:x-small;">C#</span></div>
<div style="text-indent:.5in;line-height:normal;margin:0;"><span style="font-size:x-small;"><span style="color:blue;font-family:'Courier New';">protected</span><span style="font-family:'Courier New';"> <span style="color:blue;">void</span> Page_Load(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">EventArgs</span> e)</span></span></div>
<div style="line-height:normal;margin:0;"><span style="font-family:'Courier New';"><span style="font-size:x-small;"> {</span></span></div>
<div style="line-height:normal;margin:0 0 0 1in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;">ClientScript.RegisterClientScriptBlock(<span style="color:blue;">this</span>.GetType(), <span style="color:#a31515;">&#8220;Home&#8221;</span>, <span style="color:#a31515;">&#8220;document.attachEvent(&#8216;onkeyup&#8217;,HomeKey);&#8221;</span>, <span style="color:blue;">true</span>);</span></span></div>
<div style="margin:0 0 0 .5in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;">}</span></span></div>
<div style="margin:0 0 0 .5in;"></div>
<div style="margin:0 0 0 .5in;"><span style="font-size:x-small;"><span style="font-family:Verdana;">VB.NET</span></span></div>
<div style="margin:0 0 10pt .5in;"></div>
<div style="text-indent:.5in;line-height:normal;margin:0;"><span style="font-size:x-small;"><span style="color:blue;font-family:'Courier New';">Protected</span><span style="font-family:'Courier New';"> <span style="color:blue;">Sub</span> Page_Load(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> <span style="color:blue;">Object</span>, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> EventArgs)</span></span></div>
<div style="line-height:normal;margin:0 0 0 1in;"><span style="font-family:'Courier New';"><span style="font-size:x-small;">ClientScript.RegisterClientScriptBlock(<span style="color:blue;">Me</span>.GetType(), &#8220;<span style="color:#a31515;">Home</span>&#8220;, &#8220;document.attachEvent (&#8216;onkeyup&#8217;,<span style="color:#a31515;"> HomeKey</span>);&#8221;, <span style="color:blue;">True</span>)</span></span></div>
<div style="line-height:normal;margin:0 0 0 .5in;"><span style="font-size:x-small;"><span style="color:blue;font-family:'Courier New';">End</span><span style="font-family:'Courier New';"> <span style="color:blue;">Sub</span></span></span></div>
<div style="margin:0 0 0 .5in;"></div>
<div style="margin:0 0 0 .5in;"></div>
<div style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span style="font-family:Verdana;font-size:x-small;">9.</span><span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span><span style="font-size:x-small;"><span style="font-family:Verdana;">There you are!!. Now all the pages in your application contain keyboard shortcuts.</span></span></div>
<div style="margin:0 0 10pt .5in;"><span style="font-family:Verdana;font-size:x-small;">Run Default.aspx. Test the pages by pressing 1, 2 or 3 to navigate to Page1 , Page2 or Page 3 respectively. Similarly press “H” on each of these pages to go back to the Default.aspx page.</span></div>
<div style="margin:0 0 10pt;"><span style="font-family:Verdana;font-size:x-small;">The usage of keyboard shortcut, in this article has been kept as simple as possible. However once you understand how to use this effectively, the possibilities are endless. Gmail and Yahoomail are two good examples where keyboard shortcuts are being used to improve user interactiveness with the application. </span></div>
<div style="margin:0 0 10pt;"><span style="font-family:Verdana;font-size:x-small;">You can download the source code of this article over </span><a href="http://www.dotnetcurry.com/Uploads/KeyboardShortcut.zip"><span style="font-family:Verdana;color:#0000ff;font-size:x-small;">here</span></a><span style="font-family:Verdana;font-size:x-small;">.</span></div>
<div style="margin:0 0 10pt;"><span style="font-family:Verdana;font-size:x-small;">I hope this article was useful and I thank you for viewing it.</span></div>
<div style="margin:0 0 10pt;"></div>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/irfanmunir.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/irfanmunir.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/irfanmunir.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/irfanmunir.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/irfanmunir.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/irfanmunir.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/irfanmunir.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/irfanmunir.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/irfanmunir.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/irfanmunir.wordpress.com/46/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanmunir.wordpress.com&blog=853136&post=46&subd=irfanmunir&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://irfanmunir.wordpress.com/2008/11/14/going-mouseless-implementing-keyboard-shortcuts-in-aspnet-20-using-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/97ab84ac30aa08332253c3302cb86efd?s=96&#38;d=identicon" medium="image">
			<media:title type="html">irfanmunir</media:title>
		</media:content>
	</item>
		<item>
		<title></title>
		<link>http://irfanmunir.wordpress.com/2008/07/07/39/</link>
		<comments>http://irfanmunir.wordpress.com/2008/07/07/39/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 06:57:24 +0000</pubDate>
		<dc:creator>Irfan Munir</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://irfanmunir.wordpress.com/2008/07/07/39/</guid>
		<description><![CDATA[muslim_calendar_1429
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanmunir.wordpress.com&blog=853136&post=39&subd=irfanmunir&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://irfanmunir.files.wordpress.com/2008/07/muslim_calendar_1429.pdf">muslim_calendar_1429</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/irfanmunir.wordpress.com/39/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/irfanmunir.wordpress.com/39/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/irfanmunir.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/irfanmunir.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/irfanmunir.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/irfanmunir.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/irfanmunir.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/irfanmunir.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/irfanmunir.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/irfanmunir.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/irfanmunir.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/irfanmunir.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanmunir.wordpress.com&blog=853136&post=39&subd=irfanmunir&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://irfanmunir.wordpress.com/2008/07/07/39/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/97ab84ac30aa08332253c3302cb86efd?s=96&#38;d=identicon" medium="image">
			<media:title type="html">irfanmunir</media:title>
		</media:content>
	</item>
		<item>
		<title>Asp.NET user Control tips</title>
		<link>http://irfanmunir.wordpress.com/2008/07/05/aspnet-user-control-tips/</link>
		<comments>http://irfanmunir.wordpress.com/2008/07/05/aspnet-user-control-tips/#comments</comments>
		<pubDate>Sat, 05 Jul 2008 11:02:42 +0000</pubDate>
		<dc:creator>Irfan Munir</dc:creator>
				<category><![CDATA[General Concepts]]></category>

		<guid isPermaLink="false">http://irfanmunir.wordpress.com/?p=37</guid>
		<description><![CDATA[&#60;br /&#62; 	Shahed Khan (MVP)&#60;br /&#62;


&#60;!&#8211;
//
 &#60;!&#8211;
//









Shahed Khan (MVP)
blog





posts &#8211; 213, comments &#8211; 140, trackbacks &#8211; 68






My Links

 Home
 Contact
 
 Login


 






&#60;!&#8211;
	var browName = navigator.appName;
	var SiteID = 1;
	var ZoneID = 1;
	var browDateTime = (new Date()).getTime();
	if (browName==&#8217;Netscape&#8217;)
	{
	document.write(&#8216;&#8216;); document.write(&#8221;);
	}
	if (browName!=&#8217;Netscape&#8217;)
	{
	document.write(&#8216;&#8216;); document.write(&#8221;);
	}
// &#8211;&#62;
&#38;lt;br /&#38;gt; 	&#38;lt;a href=&#8221;http://ads.geekswithblogs.net/a.aspx?ZoneID=1&#38;amp;Task=Click&#38;amp;Mode=HTML&#38;amp;SiteID=1&#38;amp;PageID=51102&#8243; mce_href=&#8221;http://ads.geekswithblogs.net/a.aspx?ZoneID=1&#38;amp;amp;Task=Click&#38;amp;amp;Mode=HTML&#38;amp;amp;SiteID=1&#38;amp;amp;PageID=51102&#8243; target=&#8221;_blank&#8221;&#38;gt;&#38;lt;br /&#38;gt; 	&#38;lt;img src=&#8221;http://ads.geekswithblogs.net/a.aspx?ZoneID=1&#38;amp;Task=Get&#38;amp;Mode=HTML&#38;amp;SiteID=1&#38;amp;PageID=51102&#8243; mce_src=&#8221;http://ads.geekswithblogs.net/a.aspx?ZoneID=1&#38;amp;amp;Task=Get&#38;amp;amp;Mode=HTML&#38;amp;amp;SiteID=1&#38;amp;amp;PageID=51102&#8243; width=&#8221;160&#8243; height=&#8221;600&#8243; border=&#8221;0&#8243;  alt=&#8221;"&#38;gt;&#38;lt;/a&#38;gt;&#38;lt;/p&#38;gt; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanmunir.wordpress.com&blog=853136&post=37&subd=irfanmunir&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>&lt;br /&gt; 	Shahed Khan (MVP)&lt;br /&gt;</p>
<div>
</div>
<p>&lt;!&#8211;<br />
//</p>
<p> &lt;!&#8211;<br />
//</p>
<table class="Framework" border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td colspan="2">
<div id="top">
<table border="0" cellspacing="0" cellpadding="8" width="100%">
<tbody>
<tr>
<td>
<h1><a id="Header1_HeaderTitle" class="headermaintitle" title="The Title Of This Blog." href="/shahed/Default.aspx">Shahed Khan (MVP)</a></h1>
<p><span>blog</span></td>
</tr>
</tbody>
</table>
</div>
<div id="sub">
<div class="BlogStats">posts &#8211; 213, comments &#8211; 140, trackbacks &#8211; 68</div>
</div>
</td>
</tr>
<tr>
<td class="LeftCell" rowspan="2">
<div id="leftmenu">
<h3>My Links</h3>
<ul>
<li> <a id="MyLinks1_HomeLink" title="Link to the home page." href="/shahed/Default.aspx">Home</a></li>
<li> <a id="MyLinks1_ContactLink" title="Contact form." href="/shahed/contact.aspx">Contact</a></li>
<li> <a id="MyLinks1_XMLLink" title="Subscribe to this feed." href="http://geekswithblogs.net/shahed/Rss.aspx"><img style="border-width:0;" src="../images/xml.gif" alt="RSS 2.0 Feed" /></a></li>
<li> <a id="MyLinks1_Admin" title="Login Form." href="/shahed/login.aspx">Login</a></li>
</ul>
<div id="searchWrapper">
<div id="search"> </div>
<div id="search_searchUpdate"></div>
<div id="search_searchProgress" style="display:none;">
<div id="search-progress"></div>
</div>
</div>
<div style="text-align:center;margin-top:10px;"><!-- Begin -  Site: Geekswithblogs.net Zone: Skyscraper --><br />
&lt;!&#8211;<br />
	var browName = navigator.appName;<br />
	var SiteID = 1;<br />
	var ZoneID = 1;<br />
	var browDateTime = (new Date()).getTime();<br />
	if (browName==&#8217;Netscape&#8217;)<br />
	{<br />
	document.write(&#8216;<s>&#8216;); document.write(&#8221;);<br />
	}<br />
	if (browName!=&#8217;Netscape&#8217;)<br />
	{<br />
	document.write(&#8216;<s>&#8216;); document.write(&#8221;);<br />
	}<br />
// &#8211;&gt;<br />
&amp;lt;br /&amp;gt; 	&amp;lt;a href=&#8221;http://ads.geekswithblogs.net/a.aspx?ZoneID=1&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=51102&#8243; mce_href=&#8221;http://ads.geekswithblogs.net/a.aspx?ZoneID=1&amp;amp;amp;Task=Click&amp;amp;amp;Mode=HTML&amp;amp;amp;SiteID=1&amp;amp;amp;PageID=51102&#8243; target=&#8221;_blank&#8221;&amp;gt;&amp;lt;br /&amp;gt; 	&amp;lt;img src=&#8221;http://ads.geekswithblogs.net/a.aspx?ZoneID=1&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=51102&#8243; mce_src=&#8221;http://ads.geekswithblogs.net/a.aspx?ZoneID=1&amp;amp;amp;Task=Get&amp;amp;amp;Mode=HTML&amp;amp;amp;SiteID=1&amp;amp;amp;PageID=51102&#8243; width=&#8221;160&#8243; height=&#8221;600&#8243; border=&#8221;0&#8243;  alt=&#8221;"&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;<br />
<!-- End -  Site: Geekswithblogs.net Zone: Skyscraper --></p>
<p><!-- Start Quantcast tag --></p>
<p>&amp;lt;br /&amp;gt; &amp;lt;a href=&#8221;http://www.quantcast.com/p-03-ZsKAm7O3lI&#8221; mce_href=&#8221;http://www.quantcast.com/p-03-ZsKAm7O3lI&#8221; target=&#8221;_blank&#8221;&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;img src=&#8221;http://pixel.quantserve.com/pixel/p-03-ZsKAm7O3lI.gif&#8221; mce_src=&#8221;http://pixel.quantserve.com/pixel/p-03-ZsKAm7O3lI.gif&#8221; style=&#8221;display: none&#8221; mce_style=&#8221;display: none&#8221; border=&#8221;0&#8243; height=&#8221;1&#8243; width=&#8221;1&#8243; alt=&#8221;Quantcast&#8221;/&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;br /&amp;gt;<br />
<!-- End Quantcast tag --></div>
<h3>News</h3>
<div class="news">
<p><a href="https://mvp.support.microsoft.com/profile=886160C8-0AF6-4A4B-A531-B70B22C42600"><img src="http://www.msbdusers.net/smartmassemail/sk.jpg" border="0" alt="" /></a></p>
<p><a href="https://mvp.support.microsoft.com/profile=886160C8-0AF6-4A4B-A531-B70B22C42600"><img src="http://www.msbdusers.net/shahed/o_mvp_logo.jpg" border="0" alt="" /></a></p>
<p><img src="http://www.msbdusers.net/smartmassemail/mcad.gif" border="0" alt="" /></p>
<p>I am a Microsoft Certified Application Developer <strong>MCAD Chartered Member (C# .Net)</strong> and born in Bangladesh.<br />
I work for Ocean Informatics Pty Ltd as a Senior Developer &#8211; Analyst.<br />
I am also co-founder and core developer of Pageflakes <a href="http://www.pageflakes.com" target="_blank">www.pageflakes.com</a><br />
and most recently created <a href="http://www.codeplex.com/smartcodegenerator" target="_blank">SmartCodeGenerator</a></p>
<p><strong>My Articles</strong></p>
<p><a href="http://www.codeproject.com/dotnet/smartjobmanager.asp" target="_blank">Flexible and Plugin based .Net Application..</a></p>
<p><a href="http://www.codeproject.com/cs/internet/smartmassemail.asp" target="_blank">Mass Emailing Functionality with C#, .NET 2.0, and Microsoft® SQL Server 2005 Service Broker&#8217; </a></p>
<p><a href="http://www.codeproject.com/csharp/smarttemplateengine.asp" target="_blank">Write your own Code Generator or Template Engine in .NET</a></p>
<p><a href="http://www.codeproject.com/aspnet/smartcodegeneratorusage.asp" target="_blank">Smart Code Generator .NET: Usage Overview</a></p>
<p><a href="http://www.codeproject.com/aspnet/smartcodegenerator.asp" target="_blank">Smart Code Generator .NET: Architectural Overview</a><br />
<a href="http://www.codeproject.com/useritems/smartcodegeneratorconsole.asp" target="_blank">Smart Code Generator .NET: using with NAnt and Cassini</a></div>
<h3>Archives</h3>
<ul>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl01_Link" href="/shahed/archive/2008/06.aspx">June, 2008 (4)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl02_Link" href="/shahed/archive/2008/05.aspx">May, 2008 (2)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl03_Link" href="/shahed/archive/2008/04.aspx">April, 2008 (2)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl04_Link" href="/shahed/archive/2008/03.aspx">March, 2008 (2)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl05_Link" href="/shahed/archive/2008/02.aspx">February, 2008 (6)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl06_Link" href="/shahed/archive/2008/01.aspx">January, 2008 (4)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl07_Link" href="/shahed/archive/2007/12.aspx">December, 2007 (1)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl08_Link" href="/shahed/archive/2007/11.aspx">November, 2007 (2)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl09_Link" href="/shahed/archive/2007/10.aspx">October, 2007 (5)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl10_Link" href="/shahed/archive/2007/09.aspx">September, 2007 (5)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl11_Link" href="/shahed/archive/2007/07.aspx">July, 2007 (3)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl12_Link" href="/shahed/archive/2007/06.aspx">June, 2007 (1)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl13_Link" href="/shahed/archive/2007/05.aspx">May, 2007 (4)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl14_Link" href="/shahed/archive/2007/04.aspx">April, 2007 (6)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl15_Link" href="/shahed/archive/2007/03.aspx">March, 2007 (4)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl16_Link" href="/shahed/archive/2007/02.aspx">February, 2007 (8)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl17_Link" href="/shahed/archive/2007/01.aspx">January, 2007 (18)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl18_Link" href="/shahed/archive/2006/12.aspx">December, 2006 (13)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl19_Link" href="/shahed/archive/2006/11.aspx">November, 2006 (23)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl20_Link" href="/shahed/archive/2006/10.aspx">October, 2006 (12)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl21_Link" href="/shahed/archive/2006/09.aspx">September, 2006 (11)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl22_Link" href="/shahed/archive/2006/08.aspx">August, 2006 (13)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl23_Link" href="/shahed/archive/2006/07.aspx">July, 2006 (5)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl24_Link" href="/shahed/archive/2006/06.aspx">June, 2006 (7)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl25_Link" href="/shahed/archive/2006/05.aspx">May, 2006 (5)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl26_Link" href="/shahed/archive/2006/04.aspx">April, 2006 (2)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl27_Link" href="/shahed/archive/2006/03.aspx">March, 2006 (2)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl28_Link" href="/shahed/archive/2006/02.aspx">February, 2006 (2)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl29_Link" href="/shahed/archive/2006/01.aspx">January, 2006 (6)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl30_Link" href="/shahed/archive/2005/12.aspx">December, 2005 (8)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl31_Link" href="/shahed/archive/2005/11.aspx">November, 2005 (6)</a></li>
<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl32_Link" href="/shahed/archive/2005/10.aspx">October, 2005 (21)</a></li>
</ul>
<h3>Free Programming Language Training</h3>
<ul>
<li><a id="SingleColumn1_Categories_CatList_ctl01_LinkList_ctl01_Link" href="http://geekswithblogs.net/freetraining/archive/2005/12/28/64295.aspx">Free Programming Language Training</a></li>
</ul>
</div>
</td>
<td class="MainCell">
<div id="main">
<p class="date"><span><br />
<a id="_a838cec9bce_HomePageDays_DaysList_ctl00_DayItem_ImageLink" title="Click to see entries for this day." href="/shahed/archive/2008/06/26.aspx">Thursday, June 26, 2008</a><br />
</span></p>
<div class="post">
<h2><a id="_a838cec9bce_HomePageDays_DaysList_ctl00_DayItem_DayList_ctl00_TitleUrl" title="Click To View Entry." href="/shahed/archive/2008/06/26/123391.aspx">ASP.NET tips: Golden rules for Dynamic Controls.</a></h2>
<p>1. Make sure your dynamic controls are Loaded on every postback.</p>
<p>Lets play with a very simple example,</p>
<p>ASPX</p>
<p>&lt;%@ Page Language=&#8221;C#&#8221; AutoEventWireup=&#8221;true&#8221; CodeFile=&#8221;Default.aspx.cs&#8221; Inherits=&#8221;_Default&#8221; %&gt;</p>
<p>&lt;body&gt;<br />
&lt;form id=&#8221;form1&#8243; runat=&#8221;server&#8221;&gt;<br />
&lt;div&gt;<br />
&lt;asp:PlaceHolder ID=&#8221;PlaceHolder1&#8243; runat=&#8221;server&#8221;&gt;&lt;/asp:PlaceHolder&gt;<br />
&lt;asp:Button ID=&#8221;Button1&#8243; runat=&#8221;server&#8221; Text=&#8221;Button&#8221; /&gt;<br />
&lt;/div&gt;<br />
&lt;/form&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p>
<p>C# Code Behind</p>
<p>public partial class _Default : System.Web.UI.Page<br />
{<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
TextBox t = new TextBox();<br />
t.ID = &#8220;textBox&#8221;;<br />
this.PlaceHolder1.Controls.Add(t);<br />
}</p>
<p>}</p>
<p>The above code works fine, but a common mistake is to try to conditionally load dynamic controls, if we tweak the code a little bit you will notice we loose our TextBox after any postback. The following code will not load the TextBox after our first postback.</p>
<p>public partial class _Default : System.Web.UI.Page<br />
{<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
<strong>if (!IsPostBack)<br />
</strong> {<br />
TextBox t = new TextBox();<br />
t.ID = &#8220;textBox&#8221;;<br />
this.PlaceHolder1.Controls.Add(t);<br />
}<br />
}</p>
<p>}</p>
<p>Its recommended to load the dynamic controls during the Page_Init instead, because we may want to hook up our events with proper handler at an early stage.</p>
<p>public partial class _Default : System.Web.UI.Page<br />
{<br />
<strong>protected void Page_Init(object sender, EventArgs e)<br />
</strong> {<br />
TextBox t = new TextBox();<br />
t.ID = &#8220;textBox&#8221;;<br />
t.TextChanged+=new EventHandler(t_TextChanged);<br />
this.PlaceHolder1.Controls.Add(t);<br />
}</p>
<p>}</p>
<p>2. Do not assigning properties of a dynamic control (viewstate enabled), during Page_Init, it will not be reflected.</p>
<p>Here is scenario of another common mistake, &#8220;123&#8243; assigned to the Text property during Page_Init,</p>
<p>public partial class _Default : System.Web.UI.Page<br />
{<br />
protected void Page_Init(object sender, EventArgs e)<br />
{<br />
TextBox t = new TextBox();<br />
t.ID = &#8220;textBox&#8221;;<br />
<strong>t.Text = &#8220;123&#8243;;<br />
</strong> this.PlaceHolder1.Controls.Add(t);<br />
}</p>
<p>}</p>
<p><a href="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETtipsGoldenrulesforDynamicControl_14FD2/controllifecycle_2.png"><img style="border-width:0;" src="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETtipsGoldenrulesforDynamicControl_14FD2/controllifecycle_thumb.png" border="0" alt="controllifecycle" width="108" height="244" /></a></p>
<p>the above code will not work because, Initialization happens before LoadViewState during the control lifecycle. The value assigned to the properties during Initialization will simply get overwritten by the ViewState values.</p>
<p>3. If you are expecting your ViewState to retain after the postback, always assign same ID to the dynamic control</p>
<p>The following piece of code will not work, as I am assigning a new ID to the dynamic control after each postback. The LoadViewState retrieves previously saved viewstate data using the control ID, as the control ID has changed, it doesn&#8217;t know anymore what to load, as a result it cannot load previously saved viewstate data any more.</p>
<p>public partial class _Default : System.Web.UI.Page<br />
{<br />
protected void Page_Init(object sender, EventArgs e)<br />
{<br />
TextBox t = new TextBox();<br />
<strong> t.ID = Guid.NewGuid().ToString(); </strong><br />
this.form1.Controls.Add(t);<br />
}<br />
}</p>
<p>Thank you for being with me so far.</p>
<p class="postfoot">posted @ <a title="Permanent link to this post" href="/shahed/archive/2008/06/26/123391.aspx">Thursday, June 26, 2008 2:36 AM</a> | <a title="comments, pingbacks, trackbacks" href="/shahed/archive/2008/06/26/123391.aspx#feedback">Feedback (0)</a> |</p>
</div>
<p class="date"><span><br />
<a id="_a838cec9bce_HomePageDays_DaysList_ctl01_DayItem_ImageLink" title="Click to see entries for this day." href="/shahed/archive/2008/06/17.aspx">Tuesday, June 17, 2008</a></span></p>
<div class="post">
<h2><a id="_a838cec9bce_HomePageDays_DaysList_ctl01_DayItem_DayList_ctl00_TitleUrl" title="Click To View Entry." href="/shahed/archive/2008/06/17/122926.aspx">ASP.NET tips, Making Custom Validators work in Partial Rendering mode.</a></h2>
<p><strong>Introduction<br />
</strong><br />
There are many situations where we need to identify if partial rendering is supported in a page, especially when a control uses javascript, to get the control work in partial rendering mode, the script needs to be registered using a ScriptManager Type instead. A classic example will be Validators.</p>
<p>The ASP.NET Page class exposes the Validators property, which is a list of all the IValidator types on the page. A page keeps track of its validators, and registers a javascript array of validators automatically to the page. Example, When we add 3 RequiredFieldValidator in a page the following javascript Array will be automatically generated and added in our page automatically during the page load.</p>
<p>Page_Validators = new Array(document.getElementById(&#8220;RequiredFieldValidator1&#8243;),<br />
document.getElementById(&#8220;RequiredFieldValidator2&#8243;),<br />
document.getElementById(&#8220;RequiredFieldValidator3&#8243;));</p>
<p>The ASP.NET Page also registers couple of other script which eventually hooks up different events ( onclick, onkeypress, onchange, onblur ) to the the target control (ControlToValidate), to some predefined javascript functions that resides in WebUIValidation.js file. So when we add a validator in our Page we also notice the following script is automatically added. [WebUIValidation.js ships with ASP.NET and resides in the following folder "/aspnet_client/system_web/&lt;version&gt;/WebUIValidation.js".]</p>
<p>&lt;script type=&#8221;text/javascript&#8221;&gt;<br />
&lt;!&#8211;<br />
var Page_ValidationActive = false;<br />
if (typeof(ValidatorOnLoad) == &#8220;function&#8221;) {<br />
ValidatorOnLoad();<br />
}</p>
<p>function ValidatorOnSubmit() {<br />
if (Page_ValidationActive) {<br />
return ValidatorCommonOnSubmit();<br />
}<br />
else {<br />
return true;<br />
}<br />
}<br />
// &#8211;&gt;<br />
&lt;/script&gt;</p>
<p>ValidatorOnLoad plays the big role of hooking up the the events mentioned above, and here is a code snippet from this function,</p>
<p>for (i = 0; i &lt; Page_Validators.length; i++) {<br />
val = Page_Validators[i];<br />
if (typeof(val.evaluationfunction) == &#8220;string&#8221;) {<br />
eval(&#8220;val.evaluationfunction = &#8221; + val.evaluationfunction + &#8220;;&#8221;);<br />
}<br />
&#8230;</p>
<p>if (typeof(val.controltovalidate) == &#8220;string&#8221;) {<br />
ValidatorHookupControlID(val.controltovalidate, val);<br />
}<br />
&#8230;<br />
}</p>
<p>keen eyes may have already noticed the val.evaluationfunction property, yes every validators needs to have this property for it to work properly under the ASP.NET validation framework. Custom validators takes advantage of this property to point to custom js functions. Custom validator developers normally use RegisterExpandoAttribute method to register this attribute.</p>
<p>protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)<br />
{<br />
base.AddAttributesToRender(writer);<br />
if (this.RenderUplevel)<br />
{<br />
string clientID = this.ClientID;<br />
Page.ClientScript.RegisterExpandoAttribute(clientID, &#8220;evaluationfunction&#8221;, &#8220;EntryValidatorEvaluateIsValid&#8221;);<br />
}<br />
}</p>
<p><strong>Problem</strong><br />
When I used Update Panel with partial rendering enabled the Page.ClientScript.RegisterExpandoAttribute did not work for me. My validators always stopped working after the first postback, which was performed via partial rendering and triggering. I found the &#8220;evaluationfunction&#8221; in the javascript to be undefined.</p>
<p><strong>Solution</strong><br />
I started looking under the hood, and soon discovered, that the ASP.NET Validators that ships out of the box, ( eg. RangeValidator, RequiredFieldValidator ) uses a different internal method &#8220;AddExpandoAttribute&#8221; to register the property. Here is a code snippet from the RangeValidator.</p>
<p>protected override void AddAttributesToRender(HtmlTextWriter writer)<br />
{<br />
base.AddAttributesToRender(writer);<br />
if (base.RenderUplevel)<br />
{<br />
string clientID = this.ClientID;<br />
HtmlTextWriter writer2 = base.EnableLegacyRendering ? writer : null;<br />
base.AddExpandoAttribute(writer2, clientID, &#8220;evaluationfunction&#8221;, &#8220;RangeValidatorEvaluateIsValid&#8221;, false);<br />
&#8230;<br />
}<br />
}</p>
<p>and code snippet from BaseValidator, the internal method AddExpandoAttribute.</p>
<p>internal void AddExpandoAttribute(HtmlTextWriter writer, string controlId, string attributeName, string attributeValue, bool encode)<br />
{<br />
AddExpandoAttribute(this, writer, controlId, attributeName, attributeValue, encode);<br />
}</p>
<p>After digging further I realized, AddExpandoAttribute checks the ASP.Page whether partial rendering is supported, then it registers the attribute using ScriptManager instead. I did the same with my validation control and it works for me. Here is the piece of code that solved my problem.</p>
<p>protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)<br />
{<br />
base.AddAttributesToRender(writer);<br />
if (this.RenderUplevel)<br />
{<br />
string clientID = this.ClientID;<br />
if (!this.IsPartialRenderingSupported)<br />
{<br />
Page.ClientScript.RegisterExpandoAttribute(clientID, &#8220;evaluationfunction&#8221;, &#8220;EntryValidatorEvaluateIsValid&#8221;);<br />
}<br />
else<br />
{<br />
Type scriptManagerType = BuildManager.GetType(&#8220;System.Web.UI.ScriptManager&#8221;, false);<br />
scriptManagerType.InvokeMember(&#8220;RegisterExpandoAttribute&#8221;, BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static, null, null, new object[] { this, clientID, &#8220;evaluationfunction&#8221;, &#8220;QuantityEntryValidatorEvaluateIsValid&#8221;, false });<br />
}<br />
}<br />
}</p>
<p>Note, the I am first checking whether Partial Rendering is Supported and using the ScriptManager  Type to register the property instead.</p>
<p>The following piece of code uses Reflection to figure out whether partial rendering is supported.</p>
<p>internal bool IsPartialRenderingSupported<br />
{<br />
get<br />
{<br />
if (!this.PartialRenderingChecked)<br />
{<br />
Type scriptManagerType = BuildManager.GetType(&#8220;System.Web.UI.ScriptManager&#8221;, false);<br />
if (scriptManagerType != null)<br />
{<br />
object obj2 = this.Page.Items[scriptManagerType];<br />
if (obj2 != null)<br />
{<br />
PropertyInfo property = scriptManagerType.GetProperty(&#8220;SupportsPartialRendering&#8221;);<br />
if (property != null)<br />
{<br />
object obj3 = property.GetValue(obj2, null);<br />
this.IsPartialRenderingEnabled = (bool)obj3;<br />
}<br />
}<br />
}<br />
this.PartialRenderingChecked = true;<br />
}<br />
return this.IsPartialRenderingEnabled;<br />
}</p>
<p>}</p>
<p>private bool PartialRenderingChecked<br />
{<br />
get<br />
{<br />
object val = ViewState["PartialRenderingChecked"];<br />
if (val != null)<br />
return (bool)val;<br />
return false;<br />
}<br />
set<br />
{<br />
ViewState["PartialRenderingChecked"] = value;<br />
}<br />
}</p>
<p>private bool IsPartialRenderingEnabled<br />
{<br />
get<br />
{<br />
object val = ViewState["IsPartialRenderingEnabled"];<br />
if (val != null)<br />
return (bool)val;<br />
return false;<br />
}<br />
set<br />
{<br />
ViewState["IsPartialRenderingEnabled"] = value;<br />
}<br />
}</p>
<p><strong>Conclusion</strong></p>
<p>The Page.ClientScript.RegisterExpandoAttribute may not work in Partial Rendiring mode, when a postback is performed via triggering,<br />
to get this work we need to determine whether partial rendering is supported and use the ScriptManager Type instead like described above.</p>
<p>Hope this helps, and saves some of your time, Thank you for being with me so far.</p>
<p class="postfoot">posted @ <a title="Permanent link to this post" href="/shahed/archive/2008/06/17/122926.aspx">Tuesday, June 17, 2008 5:43 AM</a> | <a title="comments, pingbacks, trackbacks" href="/shahed/archive/2008/06/17/122926.aspx#feedback">Feedback (0)</a> |</p>
</div>
<p class="date"><span><br />
<a id="_a838cec9bce_HomePageDays_DaysList_ctl02_DayItem_ImageLink" title="Click to see entries for this day." href="/shahed/archive/2008/06/11.aspx">Wednesday, June 11, 2008</a></span></p>
<div class="post">
<h2><a id="_a838cec9bce_HomePageDays_DaysList_ctl02_DayItem_DayList_ctl00_TitleUrl" title="Click To View Entry." href="/shahed/archive/2008/06/11/122791.aspx">C# 3.0 tips, Automatic Property</a></h2>
<p>Declaring a property in C# 3.0 is super easy and super short.</p>
<p>public class Student<br />
{<br />
public string Name {  get; set; }<br />
}</p>
<p>yes that&#8217;s it, the framework will take care of the rest, the private variables will be automatically created and the getter and setter will be automatically implemented.</p>
<p>Here is how we can assign value to an automatic property via the constructor</p>
<p>public class Student<br />
{<br />
public string Name {  get; set; }<br />
public Student (string name)<br />
{</p>
<p>this.Name = name;</p>
<p>}<br />
}</p>
<p>And finally, here is how we can declare a Readonly property</p>
<p>public class Student<br />
{</p>
<p>public string Name {  get; private set; }</p>
<p>public Student (string name)<br />
{</p>
<p>this.Name = name;</p>
<p>}<br />
}</p>
<p>Hope this helps, Enjoy coding.</p>
<p class="postfoot">posted @ <a title="Permanent link to this post" href="/shahed/archive/2008/06/11/122791.aspx">Wednesday, June 11, 2008 12:21 AM</a> | <a title="comments, pingbacks, trackbacks" href="/shahed/archive/2008/06/11/122791.aspx#feedback">Feedback (0)</a> |</p>
</div>
<p class="date"><span><br />
<a id="_a838cec9bce_HomePageDays_DaysList_ctl03_DayItem_ImageLink" title="Click to see entries for this day." href="/shahed/archive/2008/06/09.aspx">Monday, June 09, 2008</a></span></p>
<div class="post">
<h2><a id="_a838cec9bce_HomePageDays_DaysList_ctl03_DayItem_DayList_ctl00_TitleUrl" title="Click To View Entry." href="/shahed/archive/2008/06/09/122751.aspx">System.Net.WebClient().DownloadString(url) for Web Scrapeing</a></h2>
<p>WebRequest is the abstract base class for the .NET Framework&#8217;s request/response model for accessing data from the Internet.</p>
<p>To get content of a website, in .NET 1.0. we used to use WebRequest, which is good and also works asynchronously.</p>
<p>public static string GetContent(string url)<br />
{<br />
System.Net.WebRequest request = System.Net.WebRequest.Create(url);<br />
using (System.Net.WebResponse response = request.GetResponse())<br />
{<br />
using (System.IO.StreamReader reader =new System.IO.StreamReader(response.GetResponseStream()))<br />
{<br />
return reader.ReadToEnd();<br />
}<br />
}<br />
}</p>
<p>But in .NET 2.0, we can also use the WebClient class. It can also work asynchronous and works the same as the other one.</p>
<p>public static string GetContent(string url)<br />
{<br />
using (System.Net.WebClient client =new System.Net.WebClient())<br />
{<br />
return client.DownloadString(url);<br />
}<br />
}</p>
<p>We can use any of the above method for web scrapeing in .NET. But the second approach is probably more cleaner.</p>
<p class="postfoot">posted @ <a title="Permanent link to this post" href="/shahed/archive/2008/06/09/122751.aspx">Monday, June 09, 2008 3:28 PM</a> | <a title="comments, pingbacks, trackbacks" href="/shahed/archive/2008/06/09/122751.aspx#feedback">Feedback (0)</a> |</p>
</div>
<p class="date"><span><br />
<a id="_a838cec9bce_HomePageDays_DaysList_ctl04_DayItem_ImageLink" title="Click to see entries for this day." href="/shahed/archive/2008/05/23.aspx">Friday, May 23, 2008</a></span></p>
<div class="post">
<h2><a id="_a838cec9bce_HomePageDays_DaysList_ctl04_DayItem_DayList_ctl00_TitleUrl" title="Click To View Entry." href="/shahed/archive/2008/05/23/122369.aspx">Project SOAK winner of 2008 Imagine Cup Australia.</a></h2>
<p>The theme of this year’s <a href="http://www.imaginecup.com">Imagine Cup</a> is &#8220;<strong>Imagine a world where technology enables a sustainable environment</strong>.&#8221; It had been a great honorary for me to take part as one the Judges of the 2008 Imagine Cup Australia. All the teams worked real hard and came up with breathtaking solutions. The interesting part was  solutions were built on top of cutting edge technologies technologies ie. Silverlight, Virtual Earth, LINQ, ASP.NET 3.5, WCF, .NET 3.5 and SQL2005.</p>
<p>The Project SOAK is announced the winner of Australian Imagine Cup 08. SOAK which stands for “Smart Operational Agriculture toolKit” is an integrated hardware and softwares platform that aims to help farmers make the most of the water (and other) resources on their land. It does this through an integration of a wide range of sensors which gathers data about the environment in real time, provide rich visual information to end-user about the status of the farm, and electronically controls various systems such as sprinklers. The team members of SOAK blogged more about the project, can be found here</p>
<p><a title="http://davidburela.wordpress.com/2008/05/22/2008-imagine-cup-australian-winner-project-soak/" href="http://davidburela.wordpress.com/2008/05/22/2008-imagine-cup-australian-winner-project-soak/">http://davidburela.wordpress.com/2008/05/22/2008-imagine-cup-australian-winner-project-soak/</a></p>
<p><a title="http://www.istartedsomething.com/20080523/imagine-cup-australian-winner-project-soak/" href="http://www.istartedsomething.com/20080523/imagine-cup-australian-winner-project-soak/">http://www.istartedsomething.com/20080523/imagine-cup-australian-winner-project-soak/</a></p>
<p><a href="http://apcmag.com/imagine_cups_surprise_winners_a_boon_for_farmers.htm">Australian PC Magazine has just published</a> published a very insightful story on this project and the competition</p>
<p><img src="http://apcmag.com/images/apcapc/news/imcup_map_625.jpg" alt="" /></p>
<p>I found SOAK to be a brilliant piece of work, where the team combined latest technologies together and came up with a environment friendly cost effective solution.</p>
<p>The winning team will now represent Australia at the World Imagine Cup finals in Paris in July.</p>
<p><img src="http://apcmag.com/images/apcapc/news/imcup_team625.jpg" alt="" /><br />
<strong><br />
Imagine Cup 2008 &#8211; Australia &#8211; Judging Panel<br />
</strong><br />
<img src="http://apcmag.com/images/apcapc/news/imcup_judges_625.jpg" alt="" /></p>
<p>The Imagine Cup’s judging panel consisted of Roger Lawrence, Microsoft Australia’s Manager Developer Evangelism; Nigel Watson, Microsoft Australia Architect Evangelist; Shekhar Kalra, computer science lecturer at RMIT University; Shahed Khan, Senior Software Engineer at Ocean Informatics MVP C#.NET, and APC, represented by its editor, Tony Sarno.</p>
<p class="postfoot">posted @ <a title="Permanent link to this post" href="/shahed/archive/2008/05/23/122369.aspx">Friday, May 23, 2008 11:41 PM</a> | <a title="comments, pingbacks, trackbacks" href="/shahed/archive/2008/05/23/122369.aspx#feedback">Feedback (0)</a> |</p>
</div>
<p class="date"><span><br />
<a id="_a838cec9bce_HomePageDays_DaysList_ctl05_DayItem_ImageLink" title="Click to see entries for this day." href="/shahed/archive/2008/05/03.aspx">Saturday, May 03, 2008</a></span></p>
<div class="post">
<h2><a id="_a838cec9bce_HomePageDays_DaysList_ctl05_DayItem_DayList_ctl00_TitleUrl" title="Click To View Entry." href="/shahed/archive/2008/05/03/121869.aspx">ASP.NET Bug, Multi View control do not save ViewState, of dynamically added controls</a></h2>
<p>Couple of days back me and my colleague, we discovered an issue with the ASP.NET Multi View Control.<br />
We were surprised  to see that it do not add ViewState, of the dynamically added controls, of the Inactive Tabs.</p>
<p><strong>ASP.NET 2.0 </strong></p>
<p>&lt;asp:MultiView ID=&#8221;MultiView1&#8243; runat=&#8221;server&#8221; EnableViewState=&#8221;true&#8221;&gt;<br />
&lt;/asp:MultiView&gt;</p>
<p><strong>C# Code Behind</strong></p>
<p>if (!IsPostBack)<br />
{<br />
int index = 1;<br />
foreach (View v in MultiView1.Views)<br />
{<br />
TextBox t = new TextBox();<br />
t.ID = index.ToString();<br />
t.Text = &#8220;<strong>This text will not be assigned, to any Inactive Tabs, unless you put a breakpoint on this line and watch the value of this line explicitly</strong>&#8220;;<br />
v.Controls.Add(t);<br />
index = index + 1;<br />
}<br />
}</p>
<p>Surprisingly, you will notice only the Textbox.Text of the Active Tab will have value,<br />
however if you go to any other Tab of the MultiViewControl, you will notice that the TextBoxes are empty.</p>
<p>After investigating further we realized that the Viewstates of the dynamically added controls are not saved (for any of the inactive tabs).<br />
It became more interesting, when we started to debug, by putting a breakpoint to watch TextBox.Text, surprisingly every TextBox gets populated with desired Text ( for all tabs including the inactive tab, only when you explicitly watch ). Also it saves all ViewState correctly.</p>
<p>Not sure whether its a bug,  the ASP.NET team may have wanted this behavior to enhance performance of the Multi View control,</p>
<p>but if that is the case, why does it populate the TextBox.Text and also saves into Viewstate, when we try to debug !!!</p>
<p>Do not believe me?  Try it by yourself !!</p>
<p class="postfoot">posted @ <a title="Permanent link to this post" href="/shahed/archive/2008/05/03/121869.aspx">Saturday, May 03, 2008 3:31 AM</a> | <a title="comments, pingbacks, trackbacks" href="/shahed/archive/2008/05/03/121869.aspx#feedback">Feedback (1)</a> |</p>
</div>
<p class="date"><span><br />
<a id="_a838cec9bce_HomePageDays_DaysList_ctl06_DayItem_ImageLink" title="Click to see entries for this day." href="/shahed/archive/2008/04/28.aspx">Monday, April 28, 2008</a></span></p>
<div class="post">
<h2><a id="_a838cec9bce_HomePageDays_DaysList_ctl06_DayItem_DayList_ctl00_TitleUrl" title="Click To View Entry." href="/shahed/archive/2008/04/28/121739.aspx">ASP.NET in VISTA ( IIS7 ) with VS2005 or VS2008</a></h2>
<p>The following 2 links may help.</p>
<p>VS 2005: <a href="http://learn.iis.net/page.aspx/431/using-visual-studio-2005-with-iis-70/">http://learn.iis.net/page.aspx/431/using-visual-studio-2005-with-iis-70/</a><br />
VS 2008: <a href="http://learn.iis.net/page.aspx/387/using-visual-studio-2008-with-iis-70/">http://learn.iis.net/page.aspx/387/using-visual-studio-2008-with-iis-70/</a></p>
<p class="postfoot">posted @ <a title="Permanent link to this post" href="/shahed/archive/2008/04/28/121739.aspx">Monday, April 28, 2008 4:13 PM</a> | <a title="comments, pingbacks, trackbacks" href="/shahed/archive/2008/04/28/121739.aspx#feedback">Feedback (0)</a> |</p>
</div>
<p class="date"><span><br />
<a id="_a838cec9bce_HomePageDays_DaysList_ctl07_DayItem_ImageLink" title="Click to see entries for this day." href="/shahed/archive/2008/04/12.aspx">Saturday, April 12, 2008</a></span></p>
<div class="post">
<h2><a id="_a838cec9bce_HomePageDays_DaysList_ctl07_DayItem_DayList_ctl00_TitleUrl" title="Click To View Entry." href="/shahed/archive/2008/04/12/121211.aspx">ASP.NET Tips: Using Image as Embedded Resource for ASP.NET CustomControl</a></h2>
<h3>Problem</h3>
<p>I started writing an ASP.NET Custom Server Control, where I wanted an Image to be Embedded Resource of the Assembly itself,<br />
so that, I do not need to ship the images separately, but surprisingly it did not work straightway for me.</p>
<p>The following line was not working for me:<br />
writer.AddAttribute(HtmlTextWriterAttribute.Src, Page.ClientScript.GetWebResourceUrl(typeof(MyControls.MyImageControl), &#8220;ferrari.jpg&#8221;));</p>
<p>Ok, lets elaborate what I did and what I missed,</p>
<p><strong>Step 1</strong>, I created my ClassLibrary project, added an Image, added a Custom Control class.</p>
<p><a href="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image1_4.gif"><img style="border-width:0;" src="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image1_thumb_1.gif" border="0" alt="Image1" width="216" height="138" /></a></p>
<p><strong>Step 2</strong>, Made the image an embedded resource of the Assembly.</p>
<p><a href="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image2_4.gif"><img style="border-width:0;" src="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image2_thumb_1.gif" border="0" alt="Image2" width="398" height="346" /></a></p>
<p><strong>Step3</strong>, Written my very simple Custom Control, where I assigned the image &#8220;src&#8221; to the WebResource URL</p>
<p><a href="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image3_2.gif"><img style="border-width:0;" src="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image3_thumb.gif" border="0" alt="Image3" width="720" height="267" /></a></p>
<p>Step 4, Then I wanted to tryout this CustomControl in my Test Website</p>
<p><a href="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image5_2.gif"><img style="border-width:0;" src="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image5_thumb.gif" border="0" alt="Image5" width="663" height="308" /></a></p>
<p>Step 5, But I got the following result.</p>
<p><a href="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image4_2.gif"><img style="border-width:0;" src="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image4_thumb.gif" border="0" alt="Image4" width="235" height="207" /></a><br />
<a href="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image6_2.gif"><img style="border-width:0;" src="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image6_thumb.gif" border="0" alt="Image6" width="706" height="306" /></a></p>
<h3>Solution</h3>
<p>After investigating a bit, I realized I missed some critical bits.</p>
<p>1. I did not put the correct Resource URL. I discovered this by opening up the assembly via Reflector, I found that the resource URL is different than what I have put in my code.</p>
<p><a href="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image8_2.gif"><img style="border-width:0;" src="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image8_thumb.gif" border="0" alt="Image8" width="359" height="299" /></a></p>
<p>I corrected the resource URL in my code, (but still it did not work).</p>
<p>writer.AddAttribute(HtmlTextWriterAttribute.Src,<br />
Page.ClientScript.GetWebResourceUrl(typeof(MyControls.MyImageControl),<br />
&#8220;MyControls.images.ferrari.jpg&#8221;));</p>
<p><a href="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image9_4.gif"><img style="border-width:0;" src="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image9_thumb_1.gif" border="0" alt="Image9" width="696" height="261" /></a></p>
<p>2. I investigated further and found that I did not explicitly declare the image as WebResource in my assembly info . To get the embedded resource bit working, the following line is very important, and this solved my problem.</p>
<p>[assembly: System.Web.UI.WebResource("MyControls.images.ferrari.jpg", "image/jpg")]</p>
<p><a href="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image7_2.gif"><img style="border-width:0;" src="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image7_thumb.gif" border="0" alt="Image7" width="710" height="397" /></a></p>
<p>Note: We can also put this directly in the class file itself.</p>
<p>After the fix I got the following result as I have desired.</p>
<p><a href="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image10_2.gif"><img style="border-width:0;" src="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image10_thumb.gif" border="0" alt="Image10" width="228" height="244" /></a></p>
<h3>Summary</h3>
<p>I have discussed here, how to embed image in an Assembly and how to use it as WebResource. Two points to note here, which are<br />
1. After embedding a resource it is very important to explicitly declare itself as WebResource in the assembly,<br />
2. We need correct resourceURL to access resouces from the assembly. Note: its case-sensitive as well.</p>
<p>I hope this discussion will save you some time. Thank you for being with me so far.</p>
<p class="postfoot">posted @ <a title="Permanent link to this post" href="/shahed/archive/2008/04/12/121211.aspx">Saturday, April 12, 2008 8:45 PM</a> | <a title="comments, pingbacks, trackbacks" href="/shahed/archive/2008/04/12/121211.aspx#feedback">Feedback (0)</a> |</p>
</div>
<p class="date"><span><br />
<a id="_a838cec9bce_HomePageDays_DaysList_ctl08_DayItem_ImageLink" title="Click to see entries for this day." href="/shahed/archive/2008/03/22.aspx">Saturday, March 22, 2008</a></span></p>
<div class="post">
<h2><a id="_a838cec9bce_HomePageDays_DaysList_ctl08_DayItem_DayList_ctl00_TitleUrl" title="Click To View Entry." href="/shahed/archive/2008/03/22/120709.aspx">DataTable to JSON and ToJSON() Extension</a></h2>
<p>Very recently I wrote an application where I had to deal with DataSet from a Web Service.</p>
<p>Please note, I have no control on the Web Service and I ended up writing a small function which converts DataTable to JSON.</p>
<p>I understand I haven&#8217;t gain anything on the web traffic, but it surely simplified my JavaScript programming.</p>
<p>Let me go through what I did</p>
<p><strong>Step 1.  Extract the XML Schema. </strong><br />
DataTable has two handy methods to extract Xml and Xml Schema. I extracted the Xml Schema to be able to generate a C# class using the xsd.exe.</p>
<p>string path = &#8220;Your File Path&#8221;;<br />
myDataTable.WriteXml(path);<br />
myDataTable.WriteXmlSchema(path);</p>
<p><strong>Step 2. Generate C# Class using Xsd.exe that ships with the .NET Framework.</strong></p>
<p>C:\temp&gt;xsd mydatatable.xsd /l:cs /c<br />
Microsoft (R) Xml Schemas/DataTypes support utility<br />
[Microsoft (R) .NET Framework, Version 2.0.50727.42]<br />
Copyright (C) Microsoft Corporation. All rights reserved.<br />
Writing file &#8216;C:\temp\mydatatableclass.cs&#8217;.</p>
<p><strong>Step 3. DataTable to Object conversion</strong></p>
<p>The Web Service returns DataSet/ DataTable, and I want to transform all data that I I receive in the DataTable, to an instance of the class that I just generated in the above step.  Something like this:</p>
<p>private T DataTableToT&lt;T&gt;(DataTable dataTable, T obj)<br />
{<br />
using (MemoryStream ms = new MemoryStream())<br />
{<br />
dataTable.WriteXml(ms);<br />
Type thetype = obj.GetType();<br />
XmlSerializer x = new XmlSerializer(thetype);<br />
ms.Position = 0;<br />
return (T)x.Deserialize(ms);<br />
}<br />
}</p>
<p>The above method uses the WriteXml() to write the data of DataTable in to a MemoryStream, then using the XmlSerializer I deserialize the xml to a .NET object. Here is how we may use the this method:</p>
<p>DataSet ds = WebService.GetDataSet();<br />
DataTable myDataTable = ds.Tables[0];<br />
MyDataTableClass obj = DataTableToT(myDataTable, new MyDataTableClass());</p>
<p><strong>Step 4. Serialize .NET object to JSON<br />
</strong><br />
We have done the hard part above, now we have .NET object so we have all the flexibility as you can imagine. I found that there is a handful amount of libraries which can serialize .Net Objects to JSON string ie. JavaScriptSerializer, DataContractJsonSerializer, JSON.NET etc.</p>
<p>JavaScriptSerializer ships with System.Web.Extensions.dll and you can locate it under Namespace:  System.Web.Script.Serialization. The following method returns JSON from a .NET object using JavaScriptSerializer.</p>
<p>private string GetJSONUsingJavaScriptSerializer&lt;T&gt;(T obj)<br />
{<br />
JavaScriptSerializer serializer = new JavaScriptSerializer();<br />
string json =   serializer.Serialize(obj);<br />
return json;<br />
}</p>
<p>DataContractJsonSerializer also does pretty much the same as above, it ships with .NET Framework 3.5 :  System.ServiceModel.Web.dll, and you can locate this under  Namespace:  System.Runtime.Serialization.Json, But we need to decorate the class with DataContract and DataMember attributes. Example</p>
<p>[DataContract]<br />
class Order<br />
{<br />
[DataMember]<br />
public int OrderID { get; set; }<br />
[DataMember]<br />
public DateTime OrderDate { get; set; }<br />
}</p>
<p>and the following method can return a JSON string.</p>
<p>private string GetJSONUsingDataContractJsonSerializer&lt;T&gt;(T obj)<br />
{<br />
using (MemoryStream ms = new MemoryStream())<br />
{<br />
DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());<br />
serializer.WriteObject(ms, obj);<br />
return Encoding.UTF8.GetString(ms.ToArray());<br />
}<br />
}</p>
<p><strong>Conclusion<br />
</strong><br />
Here we have discussed how we can easily transform a DataTable to JSON. Sometimes we do not have enough control over the Web Service, or we may need to invoke a legacy Web Service that returns DataSet/ DataTable. In those scenarios sometimes converting DataTable to JSON comes very handy in AJAX programming. In the above example I have shown plain vanilla .NET methods, but we can even take it further and implement Extention methods to return JSON string. <a href="http://weblogs.asp.net/scottgu/archive/2007/10/01/tip-trick-building-a-tojson-extension-method-using-net-3-5.aspx">Scott</a> has shown in his blog how to produce JSON using JavascriptSerializer. Here I show how we can do the same using DataContractJsonSerializer.</p>
<p>Example:</p>
<p>public static string ToJSON&lt;T&gt;(this T obj)<br />
{<br />
using (MemoryStream ms = new MemoryStream())<br />
{<br />
DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());<br />
serializer.WriteObject(ms, obj);<br />
return Encoding.UTF8.GetString(ms.ToArray());<br />
}<br />
}</p>
<p>and then we will be able to use it like this on a order collection,</p>
<p>string json = orders.ToJSON();</p>
<p>Hope this helps.</p>
<p class="postfoot">posted @ <a title="Permanent link to this post" href="/shahed/archive/2008/03/22/120709.aspx">Saturday, March 22, 2008 5:31 PM</a> | <a title="comments, pingbacks, trackbacks" href="/shahed/archive/2008/03/22/120709.aspx#feedback">Feedback (1)</a> |</p>
</div>
<p class="date"><span><br />
<a id="_a838cec9bce_HomePageDays_DaysList_ctl09_DayItem_ImageLink" title="Click to see entries for this day." href="/shahed/archive/2008/03/18.aspx">Tuesday, March 18, 2008</a></span></p>
<div class="post">
<h2><a id="_a838cec9bce_HomePageDays_DaysList_ctl09_DayItem_DayList_ctl00_TitleUrl" title="Click To View Entry." href="/shahed/archive/2008/03/18/120628.aspx">Visual Studio 2005 Debugging in Vista</a></h2>
<p><strong>Problem</strong>: I was trying to debug in Visual Studio 2005 in my new machine which came with Vista Home Premium. Surprisingly I found that none of the break points are touched and I cannot debug. I tried giving all types of permission to the folder but no luck.</p>
<p><strong>Solution</strong>: After googling a bit, I found that I needed to run VisualStudio2005 as an Administrator, and everything started working as I expected.</p>
<p>So all I had to do is :<br />
<em>Right-click the Visual Studio icon and select the &#8220;Run as administrator&#8221; option from the context menu.</em></p>
<p><strong><a href="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/VisualStudio2005DebugginginVista_BFF5/vs05run_2.jpg"><img style="border-width:0;" src="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/VisualStudio2005DebugginginVista_BFF5/vs05run_thumb.jpg" border="0" alt="vs05run" width="175" height="244" /></a></strong></p>
<p><strong></strong></p>
<p>Hope this saves some of your time.</p>
<p class="postfoot">posted @ <a title="Permanent link to this post" href="/shahed/archive/2008/03/18/120628.aspx">Tuesday, March 18, 2008 2:39 PM</a> | <a title="comments, pingbacks, trackbacks" href="/shahed/archive/2008/03/18/120628.aspx#feedback">Feedback (1)</a> |</p>
</div>
<p class="date"><span><br />
<a id="_a838cec9bce_HomePageDays_DaysList_ctl10_DayItem_ImageLink" title="Click to see entries for this day." href="/shahed/archive/2008/02/21.aspx">Thursday, February 21, 2008</a></span></p>
<div class="post">
<h2><a id="_a838cec9bce_HomePageDays_DaysList_ctl10_DayItem_DayList_ctl00_TitleUrl" title="Click To View Entry." href="/shahed/archive/2008/02/21/119884.aspx">Javascript Tips: Carefully use &#8220;this&#8221; when writing classes, else you may cause memory leak.</a></h2>
<p>Lets say we want to declare a class in Javascript, which is equivalent to the following C# class.</p>
<pre><span class="kwrd">public</span> <span class="kwrd">class</span> Student
{
  <span class="kwrd">public</span> <span class="kwrd">string</span> FirstName = <span class="str">""</span>;
  <span class="kwrd">public</span> <span class="kwrd">string</span> LastName = <span class="str">""</span>;

  <span class="kwrd">public</span> Student( <span class="kwrd">string</span> firstname, <span class="kwrd">string</span> lastname)
  {
    <span class="kwrd">this</span>.FirstName = firstname;
    <span class="kwrd">this</span>.LastName = lastname;
  }

  <span class="kwrd">public</span> <span class="kwrd">string</span> GetFullName()
  {
    <span class="kwrd">return</span> FirstName + LastName;
  }
}</pre>
<p>&lt;!&#8211; </p>
<p>To write a similar class in JavaScript we can do something like the following [ but this will create memory leak, I am explaining that in a moment ]</p>
<pre><span class="kwrd">function</span> Student ( firstname, lastname)
{
  <span class="kwrd">this</span>.FirstName = firstname;
  <span class="kwrd">this</span>.LastName = lastname;

  <span class="kwrd">this</span>.GetFullName = <span class="kwrd">function</span>()
  {
    <span class="kwrd">return</span> <span class="kwrd">this</span>.FirstName + <span class="kwrd">this</span>.LastName;
  }

}</pre>
<pre>now in C# if we want to instantiate an object of Student and want to call the GetFullName() method, we do the following.</pre>
<pre>Student student = <span class="kwrd">new</span> Student(<span class="str">"Shahed"</span>, <span class="str">"Khan"</span>);
<span class="kwrd">string</span> fullname = student.GetFullName();</pre>
<p>&lt;!&#8211; </p>
<p>and we can create as many objects as we want and call its methods, each of the object will maintain its own state, and all objects will use the same copy of the GetFullName()  method.</p>
<p>But Javascript has different behaviour when we do the following on the above Javascript class.</p>
<pre><span class="kwrd">var</span> student = <span class="kwrd">new</span> Student(<span class="str">"Shahed"</span>,<span class="str">"Khan"</span>);
car fullname = student.GetFullName();</pre>
<p>&lt;!&#8211;<br />
In Javascript, functions are treated as variables as a result when we create a new object of Student it creates  new sets of firstname, lastname and also a new copy of GetFullname method, as a result we are creating memoryleak.</p>
<p>Do not worry too much, there is a workaround for this, lets redefine the class in a different way.</p>
<pre><span class="kwrd">function</span> Student ( firstname, lastname)
{
  <span class="kwrd">this</span>.FirstName = firstname;
  <span class="kwrd">this</span>.LastName = lastname;

  <span class="kwrd">this</span>.GetFullName = GetFullName;

}

<span class="kwrd">function</span> GetFullName()
{
  <span class="kwrd">return</span> <span class="kwrd">this</span>.FirstName + <span class="kwrd">this</span>.LastName;
}</pre>
<p>&lt;!&#8211; </p>
<p>Notice I have moved the GetFullName function out of the class, and for this tweaking all new objects of the Student class will share the same instance of of GetFullName method and avoid memory leak.</p>
<p>Thank you for being with me so far.</p>
<p>Updated 24th Feb</p>
<p>===============</p>
<p>Laurent from Galasoft gave some good feedback,</p>
<p>JavaScript object oriented should be done by modifying the prototype property of the object, and never by storing methods using the &#8220;this&#8221; keyword. The workaround provided above is not good practice, as it forces the use of a global function. We should always declare methods in JavaScript object like this:</p>
<p>function Student(firstName, lastName)</p>
<p>{</p>
<p>this.firstName = firstName;</p>
<p>this.lastName = lastName;</p>
<p>}</p>
<p>Student.prototype =</p>
<p>{</p>
<p>getFullName : function()</p>
<p>{</p>
<p>return this.firstName + &#8221; &#8221; + this.lastName;</p>
<p>}</p>
<p>}</p>
<p>also note correct naming convension, ( Javascript follows Java notation not C#). For JavaScript best practices please refer to the work of Microsoft Silverlight team.</p>
<p class="postfoot">posted @ <a title="Permanent link to this post" href="/shahed/archive/2008/02/21/119884.aspx">Thursday, February 21, 2008 5:38 PM</a> | <a title="comments, pingbacks, trackbacks" href="/shahed/archive/2008/02/21/119884.aspx#feedback">Feedback (1)</a> |</p>
</div>
<p class="date">
<p><span><br />
<a id="_a838cec9bce_HomePageDays_DaysList_ctl11_DayItem_ImageLink" title="Click to see entries for this day." href="/shahed/archive/2008/02/19.aspx">Tuesday, February 19, 2008</a><br />
</span></p>
<div class="post">
<h2><a id="_a838cec9bce_HomePageDays_DaysList_ctl11_DayItem_DayList_ctl00_TitleUrl" title="Click To View Entry." href="/shahed/archive/2008/02/19/119788.aspx">Solving DNN deployment issues, Redirecting to localhost and Running DNN in a different port</a></h2>
<p>I was trying to host a small DNN application in one of our Server and I was facing couple of  issues.</p>
<p><strong>Problem 1:</strong><br />
The first problem I faced is it was always redirecting to localhost, whenever I tried <a href="http://domain.com/dnn">http://domain.com/dnn</a> it was redirecting to <a href="http://localhost/dnn">http://localhost/dnn</a> as a result the site was un-accessible from outside.</p>
<p><strong>Solution</strong></p>
<p>This was easy to solve.<br />
1. I needed to log in as host account.<br />
2. Then I needed to go to the Admin &gt; Site Settings page<br />
3. And finally In the Portal Alias section I added a new Http Alias &#8220;domain.com/dnn&#8221;</p>
<p>This solved my problem when I hosted the site in port 80.</p>
<p><a href="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/SolvingDNNdeploymentissuesRedirectintolo_E27A/clip_image002%5B14%5D.jpg"><img style="border-width:0;" src="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/SolvingDNNdeploymentissuesRedirectintolo_E27A/clip_image002%5B14%5D_thumb.jpg" border="0" alt="clip_image002[14]" width="404" height="247" /></a></p>
<p><strong>Problem 2:</strong></p>
<p>Now I tried to host the application in a different port 8080. I.e. <a href="http://domain.com:8080/dnn">http://domain.com:8080/dnn</a>. and somehow when I clicking to redirect to any other page the port started to disappear. The <a href="http://domain.com:8080/">http://domain.com:8080/</a> automatically turned to http://domain.com/ .</p>
<p><strong>Solution</strong></p>
<p>After googling and looking at the web.config carefully I found, its clearly documented in web.config that</p>
<p>&lt;!&#8211; set UsePortNumber to true to preserve the port number if you&#8217;re using a port number other than 80 (the standard)<br />
&lt;add key=&#8221;UsePortNumber&#8221; value=&#8221;true&#8221; /&gt; &#8211;&gt;</p>
<p><a href="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/SolvingDNNdeploymentissuesRedirectintolo_E27A/clip_image002%5B12%5D.jpg"><img style="border-width:0;" src="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/SolvingDNNdeploymentissuesRedirectintolo_E27A/clip_image002%5B12%5D_thumb.jpg" border="0" alt="clip_image002[12]" width="404" height="301" /></a></p>
<p>I tweaked my appsettings section  and added the magic key</p>
<p>&lt;add key=&#8221;UsePortNumber&#8221; value=&#8221;true&#8221; /&gt;</p>
<p>Also I had to add a new Http Alias &#8220;domain.com:8080&#8243;</p>
<p>This solved my problem and started retaining the port for my <a href="http://localhost:8080">http://localhost:8080</a> but not <a href="http://domain.com:8080">http://domain.com:8080</a>.  The <a href="http://domain.com:8080">http://domain.com:8080</a> was still turning to <a href="http://domain.com">http://domain.com</a></p>
<p>Note: I later discovered this was not a problem of DNN and the issue happened because of the setup of our router settings and port forwarding, which I&#8217;ll discuss next.</p>
<p><strong>Problem 3:</strong><br />
Even after adding the &#8220;UsePortNumber&#8221; key it did not solve my problem</p>
<p><strong>Solution</strong></p>
<p>Our Router was Port Forwarding all traffic of 8080 to the port 80 of the machine where DNN app is hosted. I.e. 8080 &#8211;&gt; 80. As a result even from a browser I as typing <a href="http://domain.com:8080">http://domain.com:8080</a> , the DNN Request object was getting <a href="http://domain.com">http://domain.com</a> and when DNN handlers and url rewriters spitting the reformatted url it was spitting <a href="http://domain.com">http://domain.com</a>.</p>
<p>This was a big problem for me, initially I thought I would write a HttpHandler for 404 page not found, but soon realized it will never hit the server with the spitted Url so that didn&#8217;t work. Then I thought I would tweak the DNN handlers to handle this scenario, but later tweaked the IIS and Router to handle this.</p>
<p>1. In IIS I added, support for 8080  to my Default Website.</p>
<p><a href="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/SolvingDNNdeploymentissuesRedirectintolo_E27A/clip_image002_2.jpg"><img style="border-width:0;" src="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/SolvingDNNdeploymentissuesRedirectintolo_E27A/clip_image002_thumb.jpg" border="0" alt="clip_image002" width="404" height="454" /></a></p>
<p>2. In Router instead of forwarding to port 80 I started forwarding 8080 to 8080.<br />
3. Made sure that in my DNN Site Settings, I have added Http Alias &#8220;domain.com:8080/dnn&#8221;.</p>
<p>Waaa la, This solved my issue.</p>
<p>Hope this helps and Thank you for being with me so far.</p>
<p class="postfoot">posted @ <a title="Permanent link to this post" href="/shahed/archive/2008/02/19/119788.aspx">Tuesday, February 19, 2008 5:14 PM</a> | <a title="comments, pingbacks, trackbacks" href="/shahed/archive/2008/02/19/119788.aspx#feedback">Feedback (2)</a> |</p>
</div>
<p class="date"><span><br />
<a id="_a838cec9bce_HomePageDays_DaysList_ctl12_DayItem_ImageLink" title="Click to see entries for this day." href="/shahed/archive/2008/02/14.aspx">Thursday, February 14, 2008</a></span></p>
<div class="post">
<h2><a id="_a838cec9bce_HomePageDays_DaysList_ctl12_DayItem_DayList_ctl00_TitleUrl" title="Click To View Entry." href="/shahed/archive/2008/02/14/119587.aspx">Dotnet Nuke Tips: Two common error while writing the SqlDataProvider</a></h2>
<p>Two common errors done while writing the SqlDataProvider SQL for Dotnet Nuke Modules are</p>
<p>1. Not saving the file that contains SqlDataProvider SQL codes in the correct format. A quick trick is to open the files in NotePad and save them as &#8220;Unicode&#8221;.</p>
<p>2. Not putting atleast 2 line breaks after each GO statement in the SQLDataProvider SQL code.</p>
<p>Hope this helps.</p>
<p class="postfoot">posted @ <a title="Permanent link to this post" href="/shahed/archive/2008/02/14/119587.aspx">Thursday, February 14, 2008 1:00 PM</a> | <a title="comments, pingbacks, trackbacks" href="/shahed/archive/2008/02/14/119587.aspx#feedback">Feedback (0)</a> |</p>
</div>
<p class="date"><span><br />
<a id="_a838cec9bce_HomePageDays_DaysList_ctl13_DayItem_ImageLink" title="Click to see entries for this day." href="/shahed/archive/2008/02/06.aspx">Wednesday, February 06, 2008</a><br />
</span></p>
<div class="post">
<h2><a id="_a838cec9bce_HomePageDays_DaysList_ctl13_DayItem_DayList_ctl00_TitleUrl" title="Click To View Entry." href="/shahed/archive/2008/02/06/119363.aspx">LINQ Tips: Implementing IQueryable Provider</a></h2>
<p>Check out the following from Matt Warrens blog posts, if you are interested on how to implement IQueryable Provider.</p>
<p>source: <a title="http://blogs.msdn.com/mattwar/archive/2007/07/30/linq-building-an-iqueryable-provider-part-i.aspx" href="http://blogs.msdn.com/mattwar/archive/2007/07/30/linq-building-an-iqueryable-provider-part-i.aspx">http://blogs.msdn.com/mattwar/archive/2007/07/30/linq-building-an-iqueryable-provider-part-i.aspx</a></p>
<p><a href="http://blogs.msdn.com/mattwar/archive/2007/07/30/linq-building-an-iqueryable-provider-part-i.aspx">Part I &#8211; Reusable IQueryable base classes</a><br />
<a href="http://blogs.msdn.com/mattwar/archive/2007/07/31/linq-building-an-iqueryable-provider-part-ii.aspx">Part II &#8211; Where and reusable Expression tree visitor</a><br />
<a href="http://blogs.msdn.com/mattwar/archive/2007/08/01/linq-building-an-iqueryable-provider-part-iii.aspx">Part II &#8211; Local variable references</a><br />
<a href="http://blogs.msdn.com/mattwar/archive/2007/08/02/linq-building-an-iqueryable-provider-part-iv.aspx">Part IV &#8211; Select</a><br />
<a href="http://blogs.msdn.com/mattwar/archive/2007/08/03/linq-building-an-iqueryable-provider-part-v.aspx">Part V &#8211; Improved Column binding</a><br />
<a href="http://blogs.msdn.com/mattwar/archive/2007/08/09/linq-building-an-iqueryable-provider-part-vi.aspx">Part VI &#8211; Nested queries</a><br />
<a href="http://blogs.msdn.com/mattwar/archive/2007/09/04/linq-building-an-iqueryable-provider-part-vii.aspx">Part VII &#8211; Join and SelectMany</a></p>
<p class="postfoot">posted @ <a title="Permanent link to this post" href="/shahed/archive/2008/02/06/119363.aspx">Wednesday, February 06, 2008 5:50 PM</a> | <a title="comments, pingbacks, trackbacks" href="/shahed/archive/2008/02/06/119363.aspx#feedback">Feedback (0)</a> |</p>
</div>
<p class="date"><span><br />
<a id="_a838cec9bce_HomePageDays_DaysList_ctl14_DayItem_ImageLink" title="Click to see entries for this day." href="/shahed/archive/2008/02/05.aspx">Tuesday, February 05, 2008</a><br />
</span></p>
<div class="post">
<h2><a id="_a838cec9bce_HomePageDays_DaysList_ctl14_DayItem_DayList_ctl00_TitleUrl" title="Click To View Entry." href="/shahed/archive/2008/02/05/119321.aspx">LINQ Tips: Querying ArrayList via LINQ</a></h2>
<p><strong>Problem</strong><br />
If you try to query an ArrayList via LINQ you might be surprised to see that its not supported and throwing an exception. In other words the following query will not work at all.</p>
<p>ArrayList students = GetStudents();<br />
var query =<br />
from student in students<br />
where student.Score &gt; 80<br />
select new { student.ID, student.Name };</p>
<p><strong>Cause</strong><br />
The problem comes from the fact that LINQ to Objects has been designed to query generic collections that implement the System.Collections.Generic.IEnumerable&lt;T&gt; interface. Where an ArrayList is a nongeneric collection that contains a list of untyped objects and also does not implement IEnumerable&lt;T&gt;.</p>
<p><strong>Solution</strong><br />
Cast operator comes into rescue.</p>
<p>Here is the signature of the Cast operator:<br />
public static IEnumerable&lt;T&gt; Cast&lt;T&gt;(this IEnumerable source)</p>
<p>Cast can take a nongeneric IEnumerable and returns a generic IEnumerable&lt;T&gt;.<br />
A modification of the above query like this will solve the problem and you will be able to query ArrayList via LINQ.</p>
<p>ArrayList students = GetStudents();<br />
var query =<br />
from student in students.Cast&lt;Student&gt;()<br />
where student.Score &gt; 80<br />
select new { student.ID, student.Name };</p>
<p class="postfoot">posted @ <a title="Permanent link to this post" href="/shahed/archive/2008/02/05/119321.aspx">Tuesday, February 05, 2008 4:30 PM</a> | <a title="comments, pingbacks, trackbacks" href="/shahed/archive/2008/02/05/119321.aspx#feedback">Feedback (1)</a> |</p>
</div>
</div>
</td>
</tr>
<tr>
<td class="FooterCell">
<p class="powererdby">Powered by:</p>
<p><a id="Footer1_Hyperlink2" title="Powered By Subtext" name="Hyperlink1" href="http://sourceforge.net/projects/subtext/"><img style="border-width:0;" src="../images/PoweredBySubtext85x33.png" alt="" /></a><br />
<a id="Footer1_Hyperlink3" title="Powered By ASP.NET" href="http://ASP.NET"><img style="border-width:0;" src="../images/PoweredByAsp.Net.gif" alt="" /></a></p>
<p class="copyright">Copyright © Shahed Khan</p>
</td>
</tr>
</tbody>
</table>
<div>
</div>
<p>&lt;!&#8211;<br />
//</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/irfanmunir.wordpress.com/37/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/irfanmunir.wordpress.com/37/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/irfanmunir.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/irfanmunir.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/irfanmunir.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/irfanmunir.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/irfanmunir.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/irfanmunir.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/irfanmunir.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/irfanmunir.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/irfanmunir.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/irfanmunir.wordpress.com/37/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanmunir.wordpress.com&blog=853136&post=37&subd=irfanmunir&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://irfanmunir.wordpress.com/2008/07/05/aspnet-user-control-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/97ab84ac30aa08332253c3302cb86efd?s=96&#38;d=identicon" medium="image">
			<media:title type="html">irfanmunir</media:title>
		</media:content>

		<media:content url="../images/xml.gif" medium="image">
			<media:title type="html">RSS 2.0 Feed</media:title>
		</media:content>

		<media:content url="http://www.msbdusers.net/smartmassemail/sk.jpg" medium="image" />

		<media:content url="http://www.msbdusers.net/shahed/o_mvp_logo.jpg" medium="image" />

		<media:content url="http://www.msbdusers.net/smartmassemail/mcad.gif" medium="image" />

		<media:content url="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETtipsGoldenrulesforDynamicControl_14FD2/controllifecycle_thumb.png" medium="image">
			<media:title type="html">controllifecycle</media:title>
		</media:content>

		<media:content url="http://apcmag.com/images/apcapc/news/imcup_map_625.jpg" medium="image" />

		<media:content url="http://apcmag.com/images/apcapc/news/imcup_team625.jpg" medium="image" />

		<media:content url="http://apcmag.com/images/apcapc/news/imcup_judges_625.jpg" medium="image" />

		<media:content url="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image1_thumb_1.gif" medium="image">
			<media:title type="html">Image1</media:title>
		</media:content>

		<media:content url="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image2_thumb_1.gif" medium="image">
			<media:title type="html">Image2</media:title>
		</media:content>

		<media:content url="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image3_thumb.gif" medium="image">
			<media:title type="html">Image3</media:title>
		</media:content>

		<media:content url="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image5_thumb.gif" medium="image">
			<media:title type="html">Image5</media:title>
		</media:content>

		<media:content url="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image4_thumb.gif" medium="image">
			<media:title type="html">Image4</media:title>
		</media:content>

		<media:content url="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image6_thumb.gif" medium="image">
			<media:title type="html">Image6</media:title>
		</media:content>

		<media:content url="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image8_thumb.gif" medium="image">
			<media:title type="html">Image8</media:title>
		</media:content>

		<media:content url="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image9_thumb_1.gif" medium="image">
			<media:title type="html">Image9</media:title>
		</media:content>

		<media:content url="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image7_thumb.gif" medium="image">
			<media:title type="html">Image7</media:title>
		</media:content>

		<media:content url="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/ASP.NETTipsEmbedding.NETCustomControldll_F412/Image10_thumb.gif" medium="image">
			<media:title type="html">Image10</media:title>
		</media:content>

		<media:content url="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/VisualStudio2005DebugginginVista_BFF5/vs05run_thumb.jpg" medium="image">
			<media:title type="html">vs05run</media:title>
		</media:content>

		<media:content url="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/SolvingDNNdeploymentissuesRedirectintolo_E27A/clip_image002%5B14%5D_thumb.jpg" medium="image">
			<media:title type="html">clip_image002[14]</media:title>
		</media:content>

		<media:content url="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/SolvingDNNdeploymentissuesRedirectintolo_E27A/clip_image002%5B12%5D_thumb.jpg" medium="image">
			<media:title type="html">clip_image002[12]</media:title>
		</media:content>

		<media:content url="http://geekswithblogs.net/images/geekswithblogs_net/shahed/WindowsLiveWriter/SolvingDNNdeploymentissuesRedirectintolo_E27A/clip_image002_thumb.jpg" medium="image">
			<media:title type="html">clip_image002</media:title>
		</media:content>

		<media:content url="../images/PoweredBySubtext85x33.png" medium="image" />

		<media:content url="../images/PoweredByAsp.Net.gif" medium="image" />
	</item>
		<item>
		<title>Oracle Techniques by Sameer Wadhwa ( Analytic Functions)</title>
		<link>http://irfanmunir.wordpress.com/2008/06/12/oracle-techniques-by-sameer-wadhwa-analytic-functions/</link>
		<comments>http://irfanmunir.wordpress.com/2008/06/12/oracle-techniques-by-sameer-wadhwa-analytic-functions/#comments</comments>
		<pubDate>Thu, 12 Jun 2008 12:45:47 +0000</pubDate>
		<dc:creator>Irfan Munir</dc:creator>
				<category><![CDATA[General Concepts]]></category>

		<guid isPermaLink="false">http://irfanmunir.wordpress.com/?p=36</guid>
		<description><![CDATA[<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanmunir.wordpress.com&blog=853136&post=36&subd=irfanmunir&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><!--CTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//E-->borrowed from : <a href="http://www.samoratech.com/topicofinterest/swAnalyticalFuntions.htm#Ranked_func_bk">http://www.samoratech.com/topicofinterest/swAnalyticalFuntions.htm#Ranked_func_bk</a><br />
<!-- saved from url=(0059)http://www.geocities.com/samoracle/swAnalyticalFuntions.htm --><br />
xmlns:o=&#8221;urn:schemas-microsoft-com:office:office&#8221;<br />
xmlns:w=&#8221;urn:schemas-microsoft-com:office:word&#8221;<br />
xmlns=&#8221;http://www.w3.org/TR/REC-html40&#8243;&gt;</p>
<p> </p>
<div class="Section1">
<p class="MsoNormal" style="margin-left:-0.25in;">id=&#8221;_x0000_t136&#8243; coordsize=&#8221;21600,21600&#8243; o:spt=&#8221;136&#8243; adj=&#8221;10800&#8243; path=&#8221;m@7,0l@8,0m@5,21600l@6,21600e&#8221;&gt;</p>
<p>o:connectangles=&#8221;270,180,90,0&#8243;/&gt;</p>
<p>strokeweight=&#8221;1.5pt&#8221;&gt;</p>
<p>fitpath=&#8221;t&#8221; string=&#8221;Analytical functions&#8221;/&gt;<br />
<span>      </span></p>
<p class="MsoNormal" style="margin-left:-0.25in;">style=&#8217;mso-tab-count:13&#8242;&gt;                                                                                                                                                     </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"><span>                                                                                    </span>style=&#8217;color:maroon&#8217;&gt;SAMEER WADHWA</p>
<p class="MsoNormal"><span style="color:#800000;"><span>                                                                        </span>style=&#8221;mso-spacerun: yes&#8221;&gt;       </span><a href="mailto:Wadhwa_S@Hotmail.com">Wadhwa_S@Hotmail.com</a></p>
<p class="MsoNormal"><span>                                                            </span></p>
<div style="border:none;border-top:solid windowtext .5pt;padding:1pt 0 0;">
<p class="MsoBlockText"><strong><em><span style="font-size:11pt;color:#ff0000;">In this article I have<span> <br />
</span>tried to aware you about some of the analytic functions provided by oracle<br />
8i.These funtions are very powerful and ease to use.</span></em></strong></p>
<p class="MsoBlockText"><strong><em><span style="font-size:11pt;color:#ff0000;"> </span></em></strong></p>
</div>
<div class="MsoBlockText" style="margin-left:1.75in;text-indent:-0.25in;">style=&#8217;font-size:11.0pt;mso-bidi-font-size:12.0pt;font-family:Symbol;<br />
color:blue;mso-bidi-font-weight:bold&#8217;&gt;·<span style="font-size:11pt;color:#0000ff;">        <br />
</span><strong><span style="font-size:11pt;color:#0000ff;">href=&#8221;http://www.samoratech.com/topicofinterest/swAnalyticalFuntions.htm#Rollup_and_cube_bk&#8221;&gt;ROLLUP<br />
AND CUBE AGGREGATE FUNCTIONS</span></strong></div>
<div class="MsoBlockText" style="margin-left:1.75in;text-indent:-0.25in;">style=&#8217;mso-bidi-font-weight:normal&#8217;&gt;<span style="font-size:11pt;color:#0000ff;font-family:Symbol;">·</span><strong><span style="font-size:11pt;color:#0000ff;">        <br />
</span></strong><strong><span style="font-size:11pt;color:#0000ff;">href=&#8221;http://www.samoratech.com/topicofinterest/swAnalyticalFuntions.htm#Ranked_func_bk&#8221;&gt;RANKED<br />
FUNCTION</span></strong></div>
<div class="MsoBlockText" style="margin-left:1.75in;text-indent:-0.25in;">style=&#8217;mso-bidi-font-weight:normal&#8217;&gt;<span style="font-size:11pt;color:#0000ff;font-family:Symbol;">·</span><strong><span style="font-size:11pt;color:#0000ff;">        <br />
</span></strong><strong><span style="font-size:11pt;color:#0000ff;">href=&#8221;http://www.samoratech.com/topicofinterest/swAnalyticalFuntions.htm#Case_bk&#8221;&gt;CASE</span></strong></div>
<div class="MsoBlockText" style="margin-left:1.75in;text-indent:-0.25in;">style=&#8217;font-size:11.0pt;mso-bidi-font-size:12.0pt;font-family:Symbol;<br />
color:blue;mso-bidi-font-weight:bold&#8217;&gt;·<span style="font-size:11pt;color:#0000ff;">        <br />
</span><strong><span style="font-size:11pt;color:#0000ff;">href=&#8221;http://www.samoratech.com/topicofinterest/swAnalyticalFuntions.htm#Lag_and_lead_bk&#8221;&gt;LAG<br />
AND LEAD FUNCTION</span></strong></div>
<div class="MsoBlockText" style="margin-left:1.75in;text-indent:-0.25in;">style=&#8217;font-size:11.0pt;mso-bidi-font-size:12.0pt;font-family:Symbol;<br />
color:blue;mso-bidi-font-weight:bold&#8217;&gt;·<span style="font-size:11pt;color:#0000ff;">        <br />
</span><strong><span style="font-size:11pt;color:#0000ff;">href=&#8221;http://www.samoratech.com/topicofinterest/swAnalyticalFuntions.htm#Ratio_to_report_bk&#8221;&gt;RATIO_TO_REPORT</span></strong></div>
<div class="MsoBlockText" style="margin-left:1.5in;"><strong><span style="color:#0000ff;"><span> </span></span></strong><strong></strong></div>
<div style="border:none;border-top:solid windowtext .5pt;padding:1pt 0 0;">
<div class="MsoNormal" style="margin:0 141pt 0 1.25in;padding:0;"><span style="font-size:11pt;"> </span></div>
<div class="MsoNormal" style="margin:0 141pt 0 1.25in;padding:0;"> </div>
</div>
<p class="MsoNormal"><span>                                    </span>name=&#8221;Rollup_and_cube_bk&#8221;&gt;<strong><span style="text-decoration:underline;"><span style="color:#ff0000;">ROLLUP AND CUBE<br />
AGGREGATE FUNCTIONS</span></span></strong><strong><span style="text-decoration:underline;"></span></strong></p>
<p class="MsoNormal" style="margin-left:99pt;text-indent:-99pt;"><strong><span style="text-decoration:underline;"> </span></strong></p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-family:&quot;">To understand the power of ROLLUP and CUBE functions ,consider the<br />
following SQL statement :-</span></p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-family:&quot;">ora816 SamSQL :&gt; compute sum of totsal on deptno</span></p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-family:&quot;">ora816 SamSQL :&gt; break on deptno</span></p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-family:&quot;">ora816 SamSQL :&gt; select deptno,job,sum(sal) totsal from emp group<br />
by deptno,job;</span></p>
<p class="MsoNormal" style="margin-left:1.5in;"><span> </span></p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;    </span>DEPTNO JOB<span>           </span>TOTSAL</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">&#8212;&#8212;&#8212;-<br />
&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;-</span></p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>10 CLERK<span>           </span>1300</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;           </span>MANAGER<span>         </span>2450</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;           </span>PRESIDENT<span>       </span>5000</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">********** style=&#8221;mso-spacerun: yes&#8221;&gt;           </span>&#8212;&#8212;&#8212;-</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">sum style=&#8221;mso-spacerun: yes&#8221;&gt;                        </span>8750</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>20 ANALYST<span>         </span>6000</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;           </span>CLERK<span>           </span>1900</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;           </span>MANAGER<span>         </span>2975</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">********** style=&#8221;mso-spacerun: yes&#8221;&gt;           </span>&#8212;&#8212;&#8212;-</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">sum style=&#8221;mso-spacerun: yes&#8221;&gt;                       </span>10875</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>30 CLERK<span>            </span>950</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;           </span>MANAGER<span>         </span>2850</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;           </span>SALESMAN<span>        </span>5600</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">********** style=&#8221;mso-spacerun: yes&#8221;&gt;           </span>&#8212;&#8212;&#8212;-</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">sum style=&#8221;mso-spacerun: yes&#8221;&gt;                        </span>9400</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span> </span></p>
<h1><span style="color:#ff0000;">Now see the use of ROLLUP Function </span></h1>
<p class="MsoNormal" style="margin-left:1.5in;"><span> </span></p>
<p class="MsoNormal" style="margin-left:1.5in;"><strong><span style="font-family:&quot;">ora816 SamSQL :&gt; select deptno,job,sum(sal) totsal from emp<br />
group by ROLLUP(deptno,job);</span></strong></p>
<p class="MsoNormal" style="margin-left:1.5in;"><strong><span style="font-family:&quot;"> </span></strong></p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;    </span>DEPTNO JOB<span>           </span>TOTSAL</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">&#8212;&#8212;&#8212;-<br />
&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;-</span></p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>10 CLERK<span>           </span>1300</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>10 MANAGER<span>         </span>2450</p>
<p class="MsoNormal" style="margin-left:1.5in;">id=&#8221;_x0000_t88&#8243; coordsize=&#8221;21600,21600&#8243; o:spt=&#8221;88&#8243; adj=&#8221;1800,10800&#8243; path=&#8221;m0,0qx10800@0l10800@2qy21600@11,10800@3l10800@1qy0,21600e&#8221;<br />
filled=&#8221;f&#8221;&gt;</p>
<p>textboxrect=&#8221;0,@4,7637,@5&#8243;/&gt;</p>
<p>style=&#8217;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:&#8221;Courier New&#8221;;<br />
color:#3366FF&#8217;&gt;<span>        </span>10 PRESIDENT style=&#8221;mso-spacerun: yes&#8221;&gt;       5000</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>10<span>                 </span><span style="font-size:10pt;color:#ff0000;font-family:&quot;">8750<span>   </span>Total of Deptno 10</span></p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>20 ANALYST<span>         </span>6000</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>20 CLERK<span>           </span>1900</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>20 MANAGER<span>         </span>2975</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>20<span>        </span><span>        </span> style=&#8217;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:&#8221;Courier New&#8221;;<br />
color:red&#8217;&gt;10875</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>30 CLERK<span>            </span>950</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>30 MANAGER<span>         </span>2850</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>30 SALESMAN<span>        </span>5600</p>
<p class="MsoNormal" style="margin-left:1.5in;">type=&#8221;#_x0000_t88&#8243; style=&#8217;position:absolute;left:0;text-align:left;<br />
margin-left:297pt;margin-top:5.55pt;width:9pt;height:18pt;z-index:6&#8242;&gt;</p>
<p>style=&#8217;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:&#8221;Courier New&#8221;;<br />
color:#3366FF&#8217;&gt;<span>        </span>30 style=&#8221;mso-spacerun: yes&#8221;&gt;                 9400</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;                          </span>style=&#8217;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:&#8221;Courier New&#8221;;<br />
color:red&#8217;&gt;29025<span>   </span>Grand Total</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin-left:1.5in;"><span> </span></p>
<p class="MsoNormal" style="margin-left:1.5in;"><span style="font-family:&quot;">So if you compare the two output you will notice that you are getting<br />
the same output.<span>  </span><strong><em>By using rollup<br />
you can avoid compute and break clausesfrom SQL</em></strong>. style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>This will mostly helpful in style=&#8221;mso-spacerun: yes&#8221;&gt;  PL/SQL<span> <br />
</span>.<span>  </span>We do not have to put logic<br />
for computing values on break of groups.</p>
<p class="MsoNormal" style="margin-left:1.5in;"><span> </span></p>
<p class="MsoNormal" style="margin-left:1.5in;"><span> </span></p>
<h1><span>Now see the use of<br />
CUBE<span>  </span>Function</span></h1>
<p class="MsoNormal"> </p>
<p class="MsoNormal" style="margin-left:99pt;"><strong><span style="font-size:11pt;color:#3366ff;font-family:&quot;">ora816<br />
SamSQL :&gt; select deptno,job,sum(sal) totsal from emp group by<br />
CUBE(deptno,job);</span></strong></p>
<p class="MsoNormal" style="margin-left:99pt;"><strong><span style="font-size:11pt;color:#3366ff;font-family:&quot;"> </span></strong></p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">Fri Mar 23</span></p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun:<br />
yes&#8221;&gt;                                                          </span>NuGenesis<br />
Report</p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;    </span>DEPTNO JOB<span>           </span>TOTSAL</p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">&#8212;&#8212;&#8212;-<br />
&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;-</span></p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>10 CLERK<span>           </span>1300</p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span><span>      </span>10 MANAGER<span>        <br />
</span>2450</p>
<p class="MsoNormal" style="margin-left:99pt;">type=&#8221;#_x0000_t88&#8243; style=&#8217;position:absolute;left:0;text-align:left;<br />
margin-left:4in;margin-top:8.25pt;width:9pt;height:18pt;z-index:4&#8242;&gt;</p>
<p>style=&#8217;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:&#8221;Courier New&#8221;;<br />
color:#3366FF&#8217;&gt;<span>        </span>10 PRESIDENT style=&#8221;mso-spacerun: yes&#8221;&gt;       5000</p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>10<span>                 </span><span style="font-size:10pt;color:#ff0000;font-family:&quot;">8750<span>   </span>Total of Deptno 10</span></p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>20 ANALYST<span>         </span>6000</p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>20 CLERK<span>           </span>1900</p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>20 MANAGER<span>         </span>2975</p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>20<span>                </span><span style="font-size:10pt;color:#ff0000;font-family:&quot;">10875</span></p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>30 CLERK<span>            </span>950</p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>30 MANAGER<span>         </span>2850</p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>30 SALESMAN<span>        </span>5600</p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>30<span>                 </span><span style="font-size:10pt;color:#ff0000;font-family:&quot;">9400</span></p>
<p class="MsoNormal" style="margin-left:99pt;">type=&#8221;#_x0000_t88&#8243; style=&#8217;position:absolute;left:0;text-align:left;<br />
margin-left:4in;margin-top:2.95pt;width:18pt;height:54pt;z-index:2&#8242;&gt;</p>
<p>style=&#8217;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:&#8221;Courier New&#8221;;<br />
color:#3366FF&#8217;&gt;<span>           </span>ANALYST style=&#8221;mso-spacerun: yes&#8221;&gt;         <span style="font-size:10pt;color:#800000;font-family:&quot;">6000</span> style=&#8217;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:&#8221;Courier New&#8221;;<br />
color:#3366FF&#8217;&gt;</p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;           </span>CLERK<span>           </span><span style="font-size:10pt;color:#800000;font-family:&quot;">4150</span> style=&#8217;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:&#8221;Courier New&#8221;;<br />
color:#3366FF&#8217;&gt;</p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;           </span>MANAGER<span>         </span><span style="font-size:10pt;color:#800000;font-family:&quot;">8275<span>    </span>Total w.r.t JOB</span></p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;           </span>PRESIDENT<span>    </span><span>   </span> style=&#8217;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:&#8221;Courier New&#8221;;<br />
color:maroon&#8217;&gt;5000</p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt;           </span>SALESMAN<span>        </span><span style="font-size:10pt;color:#800000;font-family:&quot;">5600</span> style=&#8217;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:&#8221;Courier New&#8221;;<br />
color:#3366FF&#8217;&gt;</p>
<p class="MsoNormal" style="margin-left:99pt;">id=&#8221;_x0000_t87&#8243; coordsize=&#8221;21600,21600&#8243; o:spt=&#8221;87&#8243; adj=&#8221;1800,10800&#8243; path=&#8221;m21600,0qx10800@0l10800@2qy0@11,10800@3l10800@1qy21600,21600e&#8221;<br />
filled=&#8221;f&#8221;&gt;</p>
<p>textboxrect=&#8221;13963,@4,21600,@5&#8243;/&gt;</p>
<p>style=&#8217;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:&#8221;Courier New&#8221;;<br />
color:#3366FF&#8217;&gt;<span>            </span>style=&#8217;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:&#8221;Courier New&#8221;;<br />
color:red&#8217;&gt;Grand Total<span style="font-size:10pt;color:#3366ff;font-family:&quot;"><span>   </span></span><span style="font-size:10pt;color:#ff0000;">29025</span></p>
<p class="MsoNormal" style="margin-left:99pt;"><span style="font-size:10pt;color:#3366ff;font-family:&quot;"> </span></p>
<p class="MsoBodyTextIndent">Cube also do a total with respect to second group<br />
for example JOB in our case . Also at end you will see the grand total</p>
<p class="MsoBodyTextIndent"> </p>
<p class="MsoBodyTextIndent"> </p>
<p class="MsoBodyTextIndent"><span style="color:#993300;">Conclusion : Rollup and<br />
Cube are the aggregate function which allows developers and dbas to avoid<br />
compute and break clauses and simplify logic of programming</span></p>
<p class="MsoBodyTextIndent"><span style="color:#993300;"> </span></p>
<p class="MsoPlainText" style="margin-left:63pt;text-indent:.5in;">name=&#8221;Ranked_func_bk&#8221;&gt;<strong><span style="text-decoration:underline;"><span style="font-size:12pt;font-family:&quot;">Ranked Function in 8i (816)</span></span></strong><strong><span style="text-decoration:underline;"> style=&#8217;font-size:12.0pt;mso-bidi-font-size:10.0pt;font-family:&#8221;Times New Roman&#8221;;<br />
mso-fareast-font-family:&#8221;MS Mincho&#8221;;color:red&#8217;&gt;</span></strong></p>
<p class="MsoPlainText"><strong><span style="text-decoration:underline;"><span style="font-size:12pt;font-family:&quot;"> </span></span></strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:12pt;color:#3366ff;font-family:&quot;">Suppose</span><span style="font-size:12pt;color:#0000ff;font-family:&quot;"> you have a data in table which you want to rank in a specified<br />
order for example you have a table test and you want to rank a value of repcol.</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:12pt;color:#0000ff;font-family:&quot;"> </span></p>
<p class="MsoPlainText"><span style="color:#0000ff;font-family:&quot;"><span>                                               </span></span><strong>style=&#8217;font-size:12.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt;Ora816 SamSQL</strong><span style="font-size:12pt;color:#0000ff;">&gt; select * from test;</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">REPCOL<span>         <br />
</span>VALUE</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">&#8212;&#8212;&#8212;-<span>   <br />
</span>&#8212;&#8212;&#8212;-</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>                <br />
</span>100</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>            </span>style=&#8221;mso-spacerun: yes&#8221;&gt;     </span>200</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>                <br />
</span>300</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>               <br />
</span>1000</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>                <br />
</span>900</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>                <br />
</span>800</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>                <br />
</span>500</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>                <br />
</span>400</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>                <br />
</span>500</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:12pt;color:#0000ff;font-family:&quot;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="font-size:11pt;color:#0000ff;">Ora816<br />
SamSQL</span></strong><span style="font-size:11pt;color:#0000ff;">&gt; select repcol,value,</span><strong> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:red&#8217;&gt;rank() over ( partition by repcol</strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span><span>              </span>2 style=&#8221;mso-spacerun: yes&#8221;&gt;  <strong><span style="font-size:11pt;color:#ff0000;">order<br />
by value desc )</span></strong><span style="font-size:11pt;color:#0000ff;"> ranked_value</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt; </span><span>          </span>style=&#8221;mso-spacerun: yes&#8221;&gt;     3<span> <br />
</span>from test;</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:12pt;color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">REPCOL<span>         <br />
</span>VALUE RANKED_VALUE</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>                <br />
</span>500<span>            </span>1</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>                <br />
</span>300<span>            </span>2</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>                <br />
</span>200<span>            </span>3</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>                <br />
</span>100<span>            </span>4</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>  </span>style=&#8221;mso-spacerun: yes&#8221;&gt;              </span>1000<span>            </span>1</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>                <br />
</span>900<span>            </span>2</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>                <br />
</span>800<span>            </span>3</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>                <br />
</span>500<span>            </span>4</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>                <br />
</span>400<span>            </span>5</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt;</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;font-family:&quot;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">The<br />
above value is ranked by the rank function provided by 8.1.6</span> style=&#8217;font-size:12.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt;</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:12pt;color:#0000ff;font-family:&quot;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:12pt;color:#0000ff;font-family:&quot;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><a name="Case_bk"><strong><span style="text-decoration:underline;">style=&#8217;font-size:12.0pt;mso-bidi-font-size:10.0pt;font-family:&#8221;Times New Roman&#8221;;<br />
mso-fareast-font-family:&#8221;MS Mincho&#8221;;color:red&#8217;&gt;Use of Case in SELECT </span></strong></a><strong><span style="text-decoration:underline;">style=&#8217;font-size:12.0pt;mso-bidi-font-size:10.0pt;font-family:&#8221;Times New Roman&#8221;;<br />
mso-fareast-font-family:&#8221;MS Mincho&#8221;;color:red&#8217;&gt;</span></strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="text-decoration:underline;"><span style="color:#0000ff;font-family:&quot;"> </span></span></strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="text-decoration:underline;"><span style="color:#0000ff;font-family:&quot;">Case Statement are similar to decode , it is more<br />
flexible and gives better performace</span></span></strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="text-decoration:underline;"><span style="color:#0000ff;font-family:&quot;"> </span></span></strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="font-size:11pt;color:#0000ff;">Ora816<br />
SamSQL</span></strong><span style="font-size:11pt;color:#0000ff;">&gt;<span>  </span>ed</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">Wrote<br />
file afiedt.buf</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>1<span> <br />
</span>select sum(<span style="font-size:11pt;color:#ff0000;">case</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; <span style="font-size:11pt;color:#ff0000;">when</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; repcol=&#8217;A&#8217; <span style="font-size:11pt;color:#ff0000;">then</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; value <span style="font-size:11pt;color:#ff0000;">else</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; 0 <span style="font-size:11pt;color:#ff0000;">end</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt;) sum_of_A,</p>
<p class="MsoPlainText" style="margin-left:.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt; </span><span>          </span>style=&#8221;mso-spacerun: yes&#8221;&gt; 2<span>        <br />
</span>sum(<span style="font-size:11pt;color:#ff0000;">Case</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; <span style="font-size:11pt;color:#ff0000;">when</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; repcol=&#8217;B&#8217; <span style="font-size:11pt;color:#ff0000;">then</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; value <span style="font-size:11pt;color:#ff0000;">else</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; 0 <span style="font-size:11pt;color:#ff0000;">end</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt;) Sum_of_B,</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>3<span>        <br />
</span>sum(<span style="font-size:11pt;color:#ff0000;">case</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; <span style="font-size:11pt;color:#ff0000;">when </span>style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt;value = 500 <span style="font-size:11pt;color:#ff0000;">then</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; 1 <span style="font-size:11pt;color:#ff0000;">else</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; 0 <span style="font-size:11pt;color:#ff0000;">end</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt;) Value_Eq_500,</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>4<span>        <br />
</span>sum(<span style="font-size:11pt;color:#ff0000;">case</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; <span style="font-size:11pt;color:#ff0000;">when</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; value &gt; 100 <span style="font-size:11pt;color:#ff0000;">then </span>style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt;1 <span style="font-size:11pt;color:#ff0000;">else</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; 0 <span style="font-size:11pt;color:#ff0000;">end</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt;) Value_Gre_100</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>5*<span> <br />
</span>from test</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="font-size:11pt;color:#0000ff;">Ora816<br />
SamSQL</span></strong><span style="font-size:11pt;color:#0000ff;">&gt;<span>  </span>/</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;font-family:&quot;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;"><span>  </span>SUM_OF_A style=&#8221;mso-spacerun: yes&#8221;&gt;   </span>SUM_OF_B VALUE_EQ_500 VALUE_GRE_100</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;-</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;"><span>      </span>1100 style=&#8221;mso-spacerun: yes&#8221;&gt;       </span>3600<span>            </span>2<span>             </span>8</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#000080;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="text-decoration:underline;"><span style="color:#ff0000;font-family:&quot;">Use of Group by in CASE</span></span></strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="text-decoration:underline;"><span style="color:#ff0000;font-family:&quot;"> </span></span></strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="font-size:11pt;color:#0000ff;">Ora816<br />
SamSQL</span></strong><span style="font-size:11pt;color:#0000ff;">&gt; ed</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">Wrote<br />
file afiedt.buf</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>1<span> <br />
</span>select repcol,sum(<span style="font-size:11pt;color:#ff0000;">case when</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; repcol=&#8217;A&#8217; <span style="font-size:11pt;color:#ff0000;">then</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; value <span style="font-size:11pt;color:#ff0000;">else</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; 0 <span style="font-size:11pt;color:#ff0000;">end</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt;) sum_of_A,</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>2<span>        <br />
</span>sum(<span style="font-size:11pt;color:#ff0000;">Case when</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; repcol=&#8217;B&#8217; <span style="font-size:11pt;color:#ff0000;">then</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; value <span style="font-size:11pt;color:#ff0000;">else</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; 0 <span style="font-size:11pt;color:#ff0000;">end</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt;) Sum_of_B,</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>3<span>        <br />
</span>sum(<span style="font-size:11pt;color:#ff0000;">case when</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; value = 500 <span style="font-size:11pt;color:#ff0000;">then</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; 1 <span style="font-size:11pt;color:#ff0000;">else </span>style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt;0 <span style="font-size:11pt;color:#ff0000;">end</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt;) Value_Eq_500,</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>4<span>        <br />
</span>sum(<span style="font-size:11pt;color:#ff0000;">case when</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; value &gt; 100 <span style="font-size:11pt;color:#ff0000;">then </span>style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt;1 <span style="font-size:11pt;color:#ff0000;">else</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; 0 <span style="font-size:11pt;color:#ff0000;">end</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt;) Value_Gre_100</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>5<span>  <br />
</span>from test</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>6* <span style="font-size:11pt;color:#ff0000;">group<br />
by</span><span style="font-size:11pt;color:#0000ff;"> repcol</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="color:#0000ff;">Ora816 SamSQL</span></strong><span style="color:#0000ff;">&gt; /</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">REPCOL<span>      <br />
</span>SUM_OF_A<span>   </span>SUM_OF_B VALUE_EQ_500<br />
VALUE_GRE_100</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;<br />
&#8212;&#8212;&#8212;&#8212;-</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>               <br />
</span>1100<span>          </span>0 style=&#8221;mso-spacerun: yes&#8221;&gt;            </span>1<span>             </span>3</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>                  <br />
</span>0<span>       </span>3600 style=&#8221;mso-spacerun: yes&#8221;&gt;            </span>1<span>             </span>5</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:12pt;color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="font-size:11pt;color:#0000ff;">Ora816<br />
SamSQL</span></strong><span style="font-size:11pt;color:#0000ff;">&gt; ed</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">Wrote<br />
file afiedt.buf</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>1<span> <br />
</span>select (<span style="font-size:11pt;color:#ff0000;">case</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; <span style="font-size:11pt;color:#ff0000;">when</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; value between 100 and 300 <span style="font-size:11pt;color:#ff0000;">then</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; &#8216;100-300&#8242;</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>2<span>      <br />
</span><span style="font-size:11pt;color:#ff0000;">when</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; value between 400 and 700 <span style="font-size:11pt;color:#ff0000;">then</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; &#8216;400-700&#8242;</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>3<span>      <br />
</span><span style="font-size:11pt;color:#ff0000;">when</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; value between 800 and 900 <span style="font-size:11pt;color:#ff0000;">then</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; &#8216;800-900&#8242;</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>4<span>      <br />
</span><span style="font-size:11pt;color:#ff0000;">when</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; value &gt; 900 <span style="font-size:11pt;color:#ff0000;">then</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; &#8216;&gt;900&#8242; <span style="font-size:11pt;color:#ff0000;">end</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt;) VALUE_RANGE,</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>5<span>       <br />
</span>count(*) as VALUE_COUNT</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>6<span>      <br />
</span>from test</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>7<span> <br />
</span>group by</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>8<span> <br />
</span>(case when value between 100 and 300 then &#8216;100-300&#8242;</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>9<span>       <br />
</span>when value between 400 and 700 then &#8216;400-700&#8242;</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt; </span>10<span>       <br />
</span>when value between 800 and 900 then &#8216;800-900&#8242;</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt; </span>11*<span>      <br />
</span>when value &gt; 900 then &#8216;&gt;900&#8242; end )</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="font-size:11pt;color:#0000ff;">Ora816<br />
SamSQL</span></strong><span style="font-size:11pt;color:#0000ff;">&gt; /</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">VALUE_R VALUE_COUNT</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">&#8212;&#8212;- &#8212;&#8212;&#8212;&#8211;</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">100-300<span>          <br />
</span>3</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">400-700<span>          <br />
</span>3</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">800-900<span>          <br />
</span>2</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">&gt;900<span>             <br />
</span>1</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="font-size:11pt;color:#0000ff;">Ora816<br />
SamSQL</span></strong><span style="font-size:11pt;color:#0000ff;">&gt; ed</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">Wrote<br />
file afiedt.buf</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>1<span>  </span>select<br />
(case when value between 100 and 300 then &#8216;100-300&#8242;</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>2<span>      <br />
</span>when value between 400 and 700 then &#8216;400-700&#8242;</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>3<span>      <br />
</span>when value between 800 and 900 then &#8216;800-900&#8242;</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>4<span>      <br />
</span>when value &gt; 900 then &#8216;&gt;900&#8242; end) VALUE_RANGE,value</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>5*<span>     <br />
</span>from test</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="font-size:11pt;color:#0000ff;">Ora816<br />
SamSQL</span></strong><span style="font-size:11pt;color:#0000ff;">&gt; /</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">VALUE_R<span>     <br />
</span>VALUE</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">&#8212;&#8212;- &#8212;&#8212;&#8212;-</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">100-300<span>       <br />
</span>100</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">100-300<span>       <br />
</span>200</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">100-300<span>       <br />
</span>300</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">&gt;900<span>         <br />
</span>1000</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">800-900<span>       <br />
</span>900</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">800-900<span>       <br />
</span>800</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">400-700<span>       <br />
</span>500</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">400-700<span>       <br />
</span>400</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">400-700<span>       <br />
</span>500</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">9 rows selected.</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:12pt;color:#0000ff;font-family:&quot;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="text-decoration:underline;"><span style="color:#ff0000;font-family:&quot;">style=&#8221;mso-spacerun: yes&#8221;&gt; </span><a name="Lag_and_lead_bk">Lag and Lead<br />
Functions</a></span></strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="text-decoration:underline;"><span style="color:#330099;font-family:&quot;"> </span></span></strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="text-decoration:underline;"><span style="color:#0000ff;font-family:&quot;"> </span></span></strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="font-size:11pt;color:#0000ff;">Ora816<br />
SamSQL</span></strong><span style="font-size:11pt;color:#0000ff;">&gt; ed</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">Wrote<br />
file afiedt.buf</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>1<span> <br />
</span>select repcol,</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>2<span> <br />
</span>value,</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>3<span>  </span>style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:red&#8217;&gt;lag<span style="font-size:11pt;color:#0000ff;">(value,</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:red&#8217;&gt;1<span style="font-size:11pt;color:#0000ff;">) </span>style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:red&#8217;&gt;over<span style="font-size:11pt;color:#0000ff;"> (</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:red&#8217;&gt;order by<span style="font-size:11pt;color:#0000ff;"> repcol) lag_value ,</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>4<span>  </span>style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:red&#8217;&gt;lead<span style="font-size:11pt;color:#0000ff;">(value,</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:red&#8217;&gt;1<span style="font-size:11pt;color:#0000ff;">) </span>style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:red&#8217;&gt;over<span style="font-size:11pt;color:#0000ff;"> (</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:red&#8217;&gt;order by<span style="font-size:11pt;color:#0000ff;"> repcol) lead_value</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>5* from test</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="font-size:11pt;color:#0000ff;">Ora816<br />
SamSQL</span></strong><span style="font-size:11pt;color:#0000ff;">&gt; /</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">REPCOL<span>         <br />
</span>VALUE<span>  </span>LAG_VALUE LEAD_VALUE</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>                <br />
</span>100<span>                   </span>200</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>                <br />
</span>200<span>        </span>100 style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>500</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>                <br />
</span>500<span>        </span>200 style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>300</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>                <br />
</span>300<span>        </span>500 style=&#8221;mso-spacerun: yes&#8221;&gt;       </span>1000</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>              </span>style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>1000<span>       <br />
</span>300<span>        </span>500</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>                <br />
</span>500<span>       </span>1000 style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>900</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>                <br />
</span>900<span>        </span>500 style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>400</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>                <br />
</span>400<span>        </span>900 style=&#8221;mso-spacerun: yes&#8221;&gt;        </span>800</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>                <br />
</span>800<span>        </span>400</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">9 rows selected.</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:12pt;color:#0000ff;font-family:&quot;"> </span></p>
<p class="bp" style="margin-left:1.5in;"><strong><em><span style="font-size:11pt;font-family:&quot;">The LAG function provides access<br />
to a row at a given offset prior to the position and the LEAD function provides<br />
access to a row at a given offset after the current position. </span></em></strong></p>
<p class="bp" style="margin-left:1.5in;"><strong><em><span style="font-size:11pt;font-family:&quot;">The functions have the<br />
following syntax</span></em></strong><strong><span style="font-size:11pt;font-family:&quot;">: </span></strong></p>
<p><strong><span style="font-size:11pt;">{LAG | LEAD}</span></strong><strong><span style="font-size:11pt;"><span>   </span>(, [ [, ]]) OVER </span></strong><strong><span style="font-size:11pt;"><span>      </span>([PARTITION BY [,...]]</span></strong><strong><span style="font-size:11pt;"><span>      </span>ORDER BY <span> </span>[collate clause&gt;]</span></strong><strong><span style="font-size:11pt;"><span>      </span>[<span style="text-decoration:underline;">ASC</span> | DESC] [NULLS FIRST | NULLS LAST] [,...])</span></strong><strong><span style="font-size:11pt;"> </span></strong></p>
<p class="bp" style="margin-left:1.5in;"><strong><em>style=&#8217;font-size:11.0pt;mso-bidi-font-size:12.0pt;font-family:&#8221;Courier New&#8221;&#8216;&gt;is<br />
an optional parameter and defaults to 1. is an optional parameter and<br />
is the value returned if the falls outside the bounds of the table or<br />
partition</em></strong><strong><span style="font-size:11pt;font-family:&quot;">.</span></strong><strong><span style="font-size:11pt;"> </span></strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:12pt;color:#0000ff;font-family:&quot;"> </span></p>
<h4 style="margin-left:1.5in;"><a name="Ratio_to_report_bk"><span style="text-decoration:underline;">style=&#8217;font-size:12.0pt;mso-bidi-font-size:14.0pt;color:red&#8217;&gt;Ratio_to_report</span></a><span style="text-decoration:underline;"> style=&#8217;font-size:12.0pt;mso-bidi-font-size:14.0pt;color:red&#8217;&gt;</span></h4>
<p class="bp" style="margin-left:1.5in;"><strong><em><span style="font-size:11pt;font-family:&quot;">The RATIO_TO_REPORT<br />
function computes the ratio of a value to the sum of a set of values. If the<br />
expression </span></em></strong><em><strong><span style="font-size:11pt;font-style:normal;font-family:&quot;">value expression</span></strong></em><strong><em> style=&#8217;font-size:11.0pt;mso-bidi-font-size:12.0pt;font-family:&#8221;Courier New&#8221;&#8216;&gt;<br />
evaluates to NULL, RATIO_TO_REPORT also evaluates to NULL, but it is treated as<br />
zero for computing the sum of values for the denominator. Its syntax is: </em></strong></p>
<p><strong><span style="font-size:11pt;">RATIO_TO_REPORT</span></strong><strong><span style="font-size:11pt;">() OVER</span></strong><strong><span style="font-size:11pt;"><span>        </span>([PARTITION BY [,...]])</span></strong><strong><span style="font-size:11pt;"> </span></strong></p>
<p class="bp" style="margin-left:1.5in;"><strong><em>style=&#8217;font-size:11.0pt;mso-bidi-font-size:12.0pt;font-family:&#8221;Courier New&#8221;&#8216;&gt;where<br />
</em></strong></p>
<div class="MsoNormal" style="text-indent:-0.25in;">style=&#8217;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:Symbol;<br />
mso-bidi-font-weight:bold;mso-bidi-font-style:italic&#8217;&gt;· style=&#8217;font-size:7.0pt;mso-bidi-font-weight:bold;mso-bidi-font-style:italic&#8217;&gt;        <br />
<strong><em><span style="font-size:11pt;font-family:&quot;">and can be any valid<br />
expression involving column references or aggregates. </span></em></strong></div>
<div class="MsoNormal" style="text-indent:-0.25in;">style=&#8217;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:Symbol;<br />
mso-bidi-font-style:italic&#8217;&gt;·<span style="font-size:7pt;">         </span><strong><em>style=&#8217;font-size:11.0pt;mso-bidi-font-size:12.0pt;font-family:&#8221;Courier New&#8221;&#8216;&gt;The<br />
PARTITION BY clause defines the groups on which the RATIO_TO_REPORT function is<br />
to be computed. If the PARTITION BY clause is absent, then the function is<br />
computed over the whole query result set</em></strong><em> style=&#8217;font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:&#8221;Courier New&#8221;&#8216;&gt;.</em><em> style=&#8217;font-size:11.0pt;mso-bidi-font-size:12.0pt;font-family:&#8221;Courier New&#8221;&#8216;&gt; </em></div>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:12pt;color:#0000ff;font-family:&quot;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="font-size:11pt;color:#0000ff;">Ora816<br />
SamSQL</span></strong><span style="font-size:11pt;color:#0000ff;">&gt; ed</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">Wrote<br />
file afiedt.buf</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>1<span> <br />
</span>select repcol,</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>2<span> <br />
</span>value,</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>3<span> <br />
</span>sum(value) <span style="font-size:11pt;color:#ff0000;">over()</span> style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:blue&#8217;&gt; sumofvalue,</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>4<span>  </span>style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:red&#8217;&gt;ratio_to_report<span style="font-size:11pt;color:#0000ff;"> (sum(value)) </span>style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:red&#8217;&gt;over()<span style="font-size:11pt;color:#0000ff;"> RATIO</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>5<span> <br />
</span>from test</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>6* group by repcol ,value</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="font-size:11pt;color:#0000ff;">Ora816<br />
SamSQL</span></strong><span style="font-size:11pt;color:#0000ff;">&gt; /</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">REPCOL<span>         <br />
</span>VALUE SUMOFVALUE<span>      </span>RATIO</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>                <br />
</span>100<span>       </span>4700 .021276596</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>                <br />
</span>200<span>       </span>4700 .042553191</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>                <br />
</span>300<span>       </span>4700 .063829787</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>                <br />
</span>500<span>       </span>4700 .106382979</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>                <br />
</span>400<span>       </span>4700 .085106383</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>                <br />
</span>500<span>       </span>4700 .106382979</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>                <br />
</span>800<span>       </span>4700 .170212766</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>            </span>style=&#8221;mso-spacerun: yes&#8221;&gt;     </span>900<span>      <br />
</span>4700 .191489362</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>               <br />
</span>1000<span>       </span>4700 .212765957</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">9 rows selected.</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="font-size:11pt;color:#0000ff;">Ora816<br />
SamSQL</span></strong><span style="font-size:11pt;color:#0000ff;">&gt; ed</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">Wrote<br />
file afiedt.buf</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>1<span> <br />
</span>select repcol,</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>2<span> <br />
</span>value,</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>3<span>  </span>style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:red&#8217;&gt;sum<span style="font-size:11pt;color:#0000ff;">(value) </span>style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:red&#8217;&gt;over<span style="font-size:11pt;color:#0000ff;">(</span><span>partition by</span><span style="font-size:11pt;color:#0000ff;"> repcol) sumofvalue,</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>4<span>  </span>style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:red&#8217;&gt;ratio_to_report<span style="font-size:11pt;color:#0000ff;"> (sum(value)) </span>style=&#8217;font-size:11.0pt;mso-bidi-font-size:10.0pt;mso-fareast-font-family:&#8221;MS Mincho&#8221;;<br />
color:red&#8217;&gt;over<span style="font-size:11pt;color:#0000ff;">(</span><span>partition by </span><span style="font-size:11pt;color:#0000ff;">repcol) RATIO</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>5<span> <br />
</span>from test</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:11pt;color:#0000ff;">style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>6* group by repcol ,value</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="font-size:11pt;color:#0000ff;">Ora816<br />
SamSQL</span></strong><span style="font-size:11pt;color:#0000ff;">&gt; /</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">REPCOL<span>         <br />
</span>VALUE SUMOFVALUE<span>      </span>RATIO</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>                <br />
</span>100<span>       </span>1100 .090909091</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>                <br />
</span>200<span>       </span>1100 .181818182</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>                <br />
</span>300<span>       </span>1100 .272727273</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">A<span>                <br />
</span>500<span>       </span>1100 .454545455</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>                <br />
</span>400<span>       </span>3600 .111111111</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>                <br />
</span>500<span>       </span>3600 .138888889</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>                <br />
</span>800<span>       </span>3600 .222222222</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>                <br />
</span>900<span>  </span><span>     </span>3600<span>        </span>.25</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">B<span>               <br />
</span>1000<span>       </span>3600 .277777778</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;">9 rows selected.</span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="color:#0000ff;font-family:&quot;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><em><span style="color:#ff0000;font-family:&quot;">Conclusion </span></em></strong><strong><em><span style="color:#0000ff;font-family:&quot;">: These analytic functions are very powerful and very<br />
useful.<span>  </span>Thanks to Oracle to provides us<br />
such a great tool.</span></em></strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><em><span style="color:#0000ff;font-family:&quot;"> </span></em></strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><em><span style="color:#0000ff;font-family:&quot;"> </span></em></strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><span style="font-size:12pt;color:#ff0000;font-family:&quot;">References:</span></strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:12pt;color:#0000ff;font-family:&quot;"> </span></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><em><span style="color:#ff0000;font-family:&quot;">Oracle Server concept manual</span></em></strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><em><span style="color:#ff0000;font-family:&quot;">Oracle Datawarehouse manual.</span></em></strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><em><span style="color:#ff0000;font-family:&quot;"> </span></em></strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><em><span style="color:#ff0000;font-family:&quot;">Please feel free to send<span>  </span>comments or<span>  </span>feedback at </span></em></strong><strong><em>style=&#8217;mso-fareast-font-family:&#8221;MS Mincho&#8221;;color:red&#8217;&gt; href=&#8221;mailto:wadhwa_s@hotmail.com&#8221;&gt;<span style="color:#ff0000;">wadhwa_s@hotmail.com</span></em></strong><strong><em> style=&#8217;font-size:12.0pt;mso-bidi-font-size:10.0pt;font-family:&#8221;Times New Roman&#8221;;<br />
mso-fareast-font-family:&#8221;MS Mincho&#8221;;color:red&#8217;&gt;. </em></strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><em><span style="color:#ff0000;font-family:&quot;">Thanks for reading this article</span></em></strong> style=&#8217;font-size:12.0pt;mso-bidi-font-size:10.0pt;font-family:&#8221;Times New Roman&#8221;;<br />
mso-fareast-font-family:&#8221;MS Mincho&#8221;;color:blue&#8217;&gt;.</p>
<p class="MsoPlainText" style="margin-left:1.5in;"><strong><em><span style="color:#ff0000;font-family:&quot;">SAMEER WADHWA</span></em></strong></p>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:12pt;color:#0000ff;font-family:&quot;"> </span></p>
<table style="background:navy;border-collapse:collapse;" border="1" cellspacing="0" cellpadding="0" bgcolor="#000080">
<tbody>
<tr>
<td style="width:6.15in;border:windowtext 0.5pt solid;" width="590" valign="top">
<p class="MsoPlainText"><em><span style="font-size:12pt;font-family:&quot;">Copyright<span>  </span>2001 style=&#8221;mso-spacerun: yes&#8221;&gt;  </span>Sameer Wadhwa (All right reserved)</em></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoPlainText" style="margin-left:1.5in;"><span style="font-size:12pt;color:#0000ff;font-family:&quot;"> </span></p>
<p class="MsoBodyTextIndent" style="margin-left:1.5in;"><span style="color:#993300;"> </span></p>
<p class="MsoBodyTextIndent" style="margin-left:1.5in;"><span style="color:#993300;">style=&#8221;mso-spacerun: yes&#8221;&gt; </span></p>
<p class="MsoNormal"><!-- text below generated by server. PLEASE REMOVE --><img border="0" alt="" width="1" /> height=1 id=&#8221;_x0000_i1030&#8243; src=&#8221;swAnalyticalFuntions_files\serv.gif&#8221; alt=1&gt;</div>
<p> </p>
<p> </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/irfanmunir.wordpress.com/36/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/irfanmunir.wordpress.com/36/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/irfanmunir.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/irfanmunir.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/irfanmunir.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/irfanmunir.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/irfanmunir.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/irfanmunir.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/irfanmunir.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/irfanmunir.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/irfanmunir.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/irfanmunir.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanmunir.wordpress.com&blog=853136&post=36&subd=irfanmunir&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://irfanmunir.wordpress.com/2008/06/12/oracle-techniques-by-sameer-wadhwa-analytic-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/97ab84ac30aa08332253c3302cb86efd?s=96&#38;d=identicon" medium="image">
			<media:title type="html">irfanmunir</media:title>
		</media:content>
	</item>
		<item>
		<title>Enhanced Aggregation, Cube, Grouping and Rollup &#124; Oracle FAQ</title>
		<link>http://irfanmunir.wordpress.com/2008/06/12/enhanced-aggregation-cube-grouping-and-rollup-oracle-faq/</link>
		<comments>http://irfanmunir.wordpress.com/2008/06/12/enhanced-aggregation-cube-grouping-and-rollup-oracle-faq/#comments</comments>
		<pubDate>Thu, 12 Jun 2008 12:23:54 +0000</pubDate>
		<dc:creator>Irfan Munir</dc:creator>
				<category><![CDATA[General Concepts]]></category>

		<guid isPermaLink="false">http://irfanmunir.wordpress.com/?p=34</guid>
		<description><![CDATA[<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanmunir.wordpress.com&blog=853136&post=34&subd=irfanmunir&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><!--CTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt--><br />
borrowed from the site: <a href="http://www.orafaq.com/node/56">http://www.orafaq.com/node/56</a></p>
<p> </p>
<p> </p>
<p><a title="Skip navigation." href="#content"></a></p>
<table id="Table_01" style="height:117px;" border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td height="6" bgcolor="#85a1c1"> </td>
</tr>
<tr>
<td height="111">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="236"><a href="/"><img src="/forum/banner/logo.jpg" alt="" width="236" height="111" /></a></td>
<td style="background-image:url('/forum/banner/back2.jpg');background-repeat:no-repeat;" align="center" valign="middle"> </td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<table id="content" style="min-width:400px;" border="0" cellspacing="0" cellpadding="5" width="100%">
<tbody>
<tr>
<td>
<div id="block-fudforum-0" class="block block-fudforum">
<div class="title">
<h3>User login</h3>
</div>
<div class="content">
<div>
<div class="form-item">Login: <span class="form-required" title="This field is required.">*</span>
</div>
<div class="form-item">Password: <span class="form-required" title="This field is required.">*</span>
</div>
<div class="item-list">
<ul>
<li><a title="Create a new user account." href="http://www.orafaq.com/forum/re/0/">Create new account</a></li>
<li><a title="Request new password via e-mail." href="http://www.orafaq.com/forum/rst/0/">Request new password</a></li>
</ul>
</div>
</div>
</div>
</div>
<div id="block-orafaq_search-0" class="block block-orafaq_search">
<div class="title">
<h3>Search</h3>
</div>
<div class="content">
<div class="search-form">
<div class="container-inline">
<div>
<div class="form-item"></div>
</div>
</div>
</div>
<p><span>[ <a href="/about/search">Advanced</a> ] [ <a href="/about/search-help">Help</a> ]</span></div>
<div id="block-menu-184" class="block block-menu">
<div class="title">
<h3>Site navigation</h3>
</div>
<div class="content">
<ul class="menu">
<li class="collapsed"><a title="About this site" href="/about">About</a></li>
<li class="expanded"><a title="Local blogs - Technical and News posts" href="/articles">Articles / Blogs</a>
<ul class="menu">
<li class="leaf"><a title="Oracle News" href="/news">News</a></li>
<li class="leaf"><a title="E-Business Suite Articles" href="/articles/applications">Applications</a></li>
<li class="leaf"><a title="Internet Developer Suite and Programmer Articles" href="/articles/developer">Developer Suite</a></li>
<li class="leaf"><a title="Enterprise Manager Articles" href="/articles/enterprise_manager">Enterprise Manager</a></li>
<li class="leaf"><a title="JDevloper and XML Articles" href="/articles/java">Java</a></li>
<li class="leaf"><a title="Operating System Articles" href="/articles/operating_system">Operating Systems</a></li>
<li class="leaf"><a title="Database Server Articles" href="/articles/server">RDBMS Server</a></li>
<li class="leaf"><a title="SQL and PL/SQL Articles" href="/articles/sql">SQL &amp; PL/SQL</a></li>
<li class="leaf"><a title="Warehous and OLAP Articles" href="/articles/warehouse">Warehousing</a></li>
</ul>
</li>
<li class="collapsed"><a title="Oracle Weblog Aggregator" href="/aggregator">Blog Aggregator</a></li>
<li class="collapsed"><a title="Oracle Books and Magazines" href="/books">Books</a></li>
<li class="leaf"><a title="Links to Oracle Resources on the Net" href="http://www.orafaq.com/links">Directories</a></li>
<li class="leaf"><a title="Oracle Calendar of Events" href="http://www.orafaq.com/wiki/Events">Events</a></li>
<li class="leaf"><a title="Frequently Asked Questions Knowledge Base" href="http://www.orafaq.com/wiki/Category:Frequently_Asked_Questions">FAQ&#8217;s</a></li>
<li class="leaf"><a title="Oracle Message Boards" href="http://www.orafaq.com/forum">Forums</a></li>
<li class="leaf"><a title="Oracle E-Mail Lists" href="/maillist">Mailing Lists</a></li>
<li class="leaf"><a title="Oracle White Papers and Presentations" href="http://www.orafaq.com/wiki/Papers">Papers</a></li>
<li class="collapsed"><a title="Oracle Scripts and Code Library" href="http://www.orafaq.com/wiki/Scripts">Scripts</a></li>
<li class="collapsed"><a title="Oracle DBA and Developer Tools" href="/tools">Tools</a></li>
<li class="leaf"><a title="Collaborative Document Editing" href="http://www.orafaq.com/wiki/Main_Page">Wiki</a></li>
<li class="leaf"><a title="XML/RSS News Feeds (Syndication)" href="/xml">XML Feeds</a></li>
</ul>
</div>
</div>
<div id="block-amazon-0" class="block block-amazon">
<div class="title">
<h3>Featured book</h3>
</div>
<div class="content">
<div class="amazontools_block"><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0131018574%26tag=oraclefaq%26lcode=xm2%26cID=2025%26ccmID=165953%26location=/Database-Systems-Using-Oracle-2nd/dp/0131018574%253FSubscriptionId=1XFK01HK9NZWGPENWGG2" target="_blank"><img src="http://ecx.images-amazon.com/images/I/512YP257C9L._SL160_.jpg" alt="cover of Database Systems Using Oracle (2nd Edition)" width="121" height="160" /><br />
</a><a href="http://www.amazon.com/gp/redirect.html%3FASIN=0131018574%26tag=oraclefaq%26lcode=xm2%26cID=2025%26ccmID=165953%26location=/Database-Systems-Using-Oracle-2nd/dp/0131018574%253FSubscriptionId=1XFK01HK9NZWGPENWGG2" target="_blank">Database Systems Using Oracle (2nd Edition)</a></div>
</div>
</div>
<div id="block-similar-0" class="block block-similar">
<div class="title">
<h3>Similar entries</h3>
</div>
<div class="content">
<div class="item-list">
<ul>
<li><a href="/faq/how_does_one_code_a_matrix_crosstab_pivot_report_in_sql">How does one code a matrix/crosstab/pivot report in SQL?</a></li>
<li><a href="/node/75">Drilling from OLAP to Relational using Discoverer 10.1.2</a></li>
<li><a href="/faq/how_does_one_select_insert_update_and_delete_data_from_php">How does one SELECT, INSERT, UPDATE and DELETE data from PHP?</a></li>
<li><a href="/faq/how_does_one_implement_autonumber_and_identity_columns_in_oracle">How does one implement AutoNumber and Identity columns in Oracle?</a></li>
<li><a href="/node/34">Oracle 10g New Features: DML Enhancements</a></li>
</ul>
</div>
</div>
</div>
</div>
</td>
<td valign="top">
<div id="main">
<div class="breadcrumb"><a href="/">Home</a> » <a title="Local blogs - Technical and News posts" href="/articles">Articles / Blogs</a> » <a href="/blog/shouvik_basu">Shouvik Basu&#8217;s blog</a></div>
<h1 class="title">Enhanced Aggregation, Cube, Grouping and Rollup</h1>
<p><!-- start main content --></p>
<div class="node"><span class="submitted">Submitted by Shouvik Basu on Tue, 2005-03-01 00:00.</span><br />
<span class="taxonomy"></p>
<ul class="links inline">
<li class="first last taxonomy_term_10"><a class="taxonomy_term_10" title="SQL and PL/SQL Articles" rel="tag" href="/articles/sql">SQL &amp; PL/SQL</a></li>
</ul>
<p> </p>
<p></span></p>
<div class="picture"><img src="http://www.orafaq.com/files/pictures/picture-9.jpg" alt="Shouvik Basu's picture" /></div>
<div class="content">
<h3><a name="OLAP_reporting_embedded_in_SQL">(OLAP reporting embedded in SQL)</a></h3>
</div>
<p>Much of the OLAP reporting feature embedded in Oracle SQL is ignored. People turn to expensive OLAP reporting tools in the market &#8211; even for simple reporting needs. This article outlines some of the common OLAP reporting needs and shows how to meet them by using the enhanced aggregation features of Oracle SQL.</p>
<p>The article is divided in two sections. The first introduces the GROUP BY extensions of SQL, and the second uses them to generate some typical reports. A section at the end introduces the common OLAP terminologies.</p>
<p>The enhanced SQL aggregation features are available across all flavors of Oracle including Oracle Standard Edition One. It might be worth mentioning here, that Oracle OLAP, the special OLAP package of Oracle, is not available with Oracle Standard Edition and Standard Edition One. Enhanced aggregation features discussed here have been tested on Oracle 9i and Oracle 10g.</p>
<h4><a name="Advanced_Aggregation_Extensions_of_GROUP_BY">Advanced Aggregation Extensions of GROUP BY</a></h4>
<p><span style="font-style:italic;"><span style="text-decoration:underline;"><span style="font-weight:bold;">GROUPING SETS clause, GROUPING function and GROUPING_ID function</span></span></span></p>
<p>The fundamental concept of enhanced aggregation features of Oracle is that of GROUPING SETS. All other aggregation features can be expressed in terms of it. With GROUPING SETS clause comes the functions GROUPING, GROUPING_ID and GROUP_ID.</p>
<p>The GROUPING SETS clause in GROUP BY allows us to specify more than one GROUP BY options in the same record set. All GROUPING clause query can be logically expressed in terms of several GROUP BY queries connected by UNION. Table-1 shows several such equivalent statements. This is helpful in forming the idea of the GROUPING SETS clause. A blank set ( ) in the GROUPING SETS clause calculates the overall aggregate.</p>
<p><span style="font-weight:bold;">Table 1 &#8211; GROUPING SET queries and the equivalent GROUP BY queries</span></p>
<p>Set A &#8211; Aggregate Query with GROUPING SETS Set B &#8211; Equivalent Aggregate Query with GROUP BY A1. SELECT a, b, SUM(c) FROM tab1 GROUP BY GROUPING SETS ( (a,b) ) B1. SELECT a, b, SUM(c) FROM tab1 GROUP BY a, b A2. SELECT a, b, SUM( c ) FROM tab1 GROUP BY GROUPING SETS ( (a,b), a) B2. SELECT a, b, SUM( c ) FROM tab1 GROUP BY a, b UNION SELECT a, null, SUM( c ) FROM tab1 GROUP BY a A3. SELECT a,b, SUM( c ) FROM tab1 GROUP BY GROUPING SETS (a,b) B3. SELECT a, null, SUM( c ) FROM tab1 GROUP BY a UNION SELECT null, b, SUM( c ) FROM tab1 GROUP BY b A4. SELECT a, b, SUM( c ) FROM tab1 GROUP BY GROUPING SETS ( (a, b), a, b, ( ) ) B4. SELECT a, b, SUM( c ) FROM tab1 GROUP BY a, b UNION SELECT a, null, SUM( c ) FROM tab1 GROUP BY a, null UNION SELECT null, b, SUM( c ) FROM tab1 GROUP BY null, b UNION SELECT null, null, SUM( c ) FROM tab1<br />
Example (<span style="font-weight:bold;">Table-1</span> Set 4) is like a superset of all the above cases and also includes an overall aggregate by the use of ( ). We will see latter that this result is similar to that of CUBE (a, b). The first 3 columns of <span style="font-weight:bold;">Table-2</span> show the result of a query of this type.</p>
<p>GROUPING clause uses a single scan to compute all the required aggregates. So the performance is better than its logical equivalent of <span style="font-style:italic;">several GROUP BY and UNION</span>.</p>
<p>The general syntax of a SQL with GROUPING SETS is -</p>
<p>SELECT &lt;grouping_columns&gt;, &lt;aggregate_functions&gt; FROM &lt;table_list&gt; WHERE &lt;where_condition&gt; GROUP BY GROUPING SETS (&lt;column_set_1&gt;, &#8230; , &lt;column_set_N&gt;<br />
The &#8220;column sets&#8221; can have none, one or more &#8220;grouping column&#8221; from SELECT. However, all columns from the select should be present in at least one of the column sets. In mathematical terms -</p>
<p><span style="font-style:italic;"><span style="font-weight:bold;">UNION UNION should be</p>
<p>equal to </span></span></p>
<p>So the following two queries below will return error -</p>
<p>(1) SELECT a, b, c, SUM(d ) FROM tab1 GROUP BY GROUPING SETS ( (a,b), b) &#8212; Reason (a,b) U ( b ) is not equal to (a,b,c) (2) SELECT a, b, SUM( c ) FROM tab1 GROUP BY GROUPING SETS (a, ( ) ) &#8212; Reason (a) U ( ) is not equal to ( a, b )</p></div>
<p><span style="font-weight:bold;">Table 2 &#8211; A GROUPING SET query with GROUPING and GROUPING_ID Function on EMP</span></p>
<p>SELECT deptno, job, SUM(sal), GROUPING(deptno) GDNO, GROUPING (job) GJNO, GROUPING_ID(deptno, job) GID_DJ, GROUPING_ID(job, deptno) GID_JD FROM EMP GROUP BY GROUPING SETS ( (deptno, job), deptno, job, ( )) DEPTNO JOB SUM(SAL) GDNO GJNO GID_DJ GID_JD &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- 10 CLERK 1300 0 0 0 0 10 MANAGER 2450 0 0 0 0 10 PRESIDENT 5000 0 0 0 0 20 CLERK 1900 0 0 0 0 20 ANALYST 6000 0 0 0 0 20 MANAGER 2975 0 0 0 0 30 CLERK 950 0 0 0 0 30 MANAGER 2850 0 0 0 0 30 SALESMAN 5600 0 0 0 0 10 8750 0 1 1 2 20 10875 0 1 1 2 30 9400 0 1 1 2 ANALYST 6000 1 0 2 1 CLERK 4150 1 0 2 1 MANAGER 8275 1 0 2 1 PRESIDENT 5000 1 0 2 1 SALESMAN 5600 1 0 2 1 29025 1 1 3 3 18 rows selected.</p></div>
<p><span style="text-decoration:underline;"><span style="font-style:italic;"><span style="font-weight:bold;">GROUPING Function and GROUPING_ID Function</span></span></span></p>
<p>From <span style="font-weight:bold;">Table-2</span> we see that when aggregates are displayed for a column its value is null. This may conflict in case the column itself has some null values. There needs to be some way to identify NULL in column, which means aggregate and NULL in column, which means value. GROUPING function is the solution to that.</p>
<p>This function returns a flag &#8220;1&#8243; for a row in the result set if that column has been aggregated in that row. Otherwise the value is &#8220;0&#8243;. There can be only one column expression as the argument of the GROUPING function and that column should also be in the SELECT. GROUPING function can be used to substitute the NULL value, which usually appears in columns at the aggregation level by something meaningful like Total.</p>
<p><span style="font-weight:bold;">GROUPING</span> function has the general syntax of <span style="font-weight:bold;">GROUPING ( )</span>. It is used only in SELECT clause. It takes only a single column expression as argument.</p>
<p><span style="font-weight:bold;">GROUPING_ID </span>takes a set of columns. It applies the GROUPING function on each column in its argument and composes a bit vector with the &#8220;0&#8243; and &#8220;1&#8243; values. It returns the decimal equivalent of the bit vector. The columns GID_DJ and GID_JD show the use of GROUPING_ID function and also show how interchanging the order of the columns inside the GROUPING_ID function might impact the result.</p>
<p><span style="text-decoration:underline;"><span style="font-style:italic;"><span style="font-weight:bold;">CUBE</span></span></span></p>
<p>This is the most generalized aggregation clause. The general syntax is <span style="font-weight:bold;">CUBE ( )</span>. It is used with the GROUP BY only. CUBE creates a subtotal of all possible combinations of the set of column in its argument. Once we compute a CUBE on a set of dimension, we can get answer to all possible aggregation questions on those dimensions. <span style="font-weight:bold;">Table-3</span> shows a cube building.</p>
<p>It might be also worth mentioning here that</p>
<p>GROUP BY CUBE( a, b, c) is equivalent to</p>
<p>GROUP BY GROUPING SETS ( (a, b, c), (a, b), (b, c), (a, c), (a), (b), (c), ( )).</p>
<p><span style="text-decoration:underline;"><span style="font-style:italic;"><span style="font-weight:bold;">ROLLUP</span></span></span></p>
<p>ROLLUP clause is used with GROUP BY to compute the aggregate at the hierarchy levels of a dimension.</p>
<p>ROLLUP(a, b, c) assumes that the hierarchy is &#8220;a&#8221; drilling down to &#8220;b&#8221; drilling down to &#8220;c&#8221;.</p>
<p>ROLLUP (a, b, c) is equivalent to GROUPING SETS ( (a, b, c), (a, b), (a), ( )).</p>
<p>The general syntax of ROLLUP is <span style="font-weight:bold;">ROLLUP( )</span></p>
<p><span style="text-decoration:underline;"><span style="font-style:italic;"><span style="font-weight:bold;">Composite Columns</span></span></span></p>
<p>A composite column is a collection of columns that can be used in CUBE or ROLLUP. They are treated as unit before computing the aggregate.Composite columns usage in CUBE and ROLLUP and the equivalent GROUPING SETS -</p>
<p>. CUBE( (a, b), c) is equivalent to GROUPING SETS ( (a, b, c), (a, b) , c, ( )) . ROLLUP ( a, (b, c) ) is equivalent to GROUPING SETS ( (a, b, c), ( a ), ( ) )</p>
<p><span style="font-weight:bold;"><span style="font-style:italic;"><span style="text-decoration:underline;">Partial GROUPING SETS, CUBE or ROLLUP</span></span></span></p>
<p>If any column appears in GROUP BY but outside the aggregation clauses discussed above. It can be thought of as being first column of the resulting GROUPING SET equivalent. The following examples make this clear.</p>
<p>GROUP BY a, CUBE( b, c) is equivalent to GROUP BY GROUPING SETS ( (a, b, c), (a, b), (a, c), (a) ) GROUP BY a, ROLLUP( b, c) is equivalent to GROUP BY GROUPING SETS ( (a, b, c), (a, b), (a) )</p>
<p><span style="font-size:6px;"><span style="text-decoration:underline;"><span style="font-weight:bold;">OLAP Reporting using enhanced aggregation features</span></span></span></p>
<p>While the queries on the EMP table are used to illustrate the GROUPING SETS they will be poor examples for discussing the next sections. The reason is that the tables are not in a Star-Schema format. Please run the script (<span style="font-weight:bold;">Script A</span>) to get a simple Star Schema.</p>
<p>The tables of the Sample Schema are</p>
<p>Product(prdid, prd_name, prd_family)</p>
<p>TimeByDay(datekey, td_month, td_quarter, td_year)</p>
<p>Location( Loc_id, City, State, Country)</p>
<p>Customer(cust_id, cust_name, cust_type);</p>
<p>Sales(sales_id, cust_id, loc_id, prdid, sales_date, amount);</p>
<p>The schema is about a fictitious Art Trader that supplies remakes of statues of famous historical figures (like ALEXANDER, BUDDHA, etc) or landscape paintings of places (like SIKKIM, etc). They sell to museums, resellers or individuals.</p>
<p>The dimensions are Product, TimeByDay, Location and Customer. The fact is Sales.</p>
<p>The hierarchies are -</p>
<p>(1) Product_Name (prd_name) -&gt; Product Family (prd_family)</p>
<p>(2) Date (datekey) -&gt; Month (td_month) -&gt; Quarter (td_quarter) -&gt; Year (td_year)</p>
<p>(3) City -&gt; State -&gt; Country</p>
<p>(4) Customer_Name (cust_name) -&gt; Customer_Type (cust_type)</p>
<p>The two approaches used for generating OLAP reports are as follows -</p>
<p>(1) Get the most generalized possible CUBE built with the dimensions, or</p>
<p>(2) Use on the fly aggregation queries to get the real-time report.</p>
<p><span style="text-decoration:underline;"><span style="font-weight:bold;">Using generalized pre-built CUBE for CUBE, ROLLUP, Drill Down and Slicing Queries.</span></span></p>
<p>This approach consists of building a table or a materialized view with the CUBE of the dimensions. <span style="font-weight:bold;">Table-3</span> shows the SQL to build such a cube. The generalized CUBE keeps all possible meaningful aggregation pre-computed. We need to query some of the rows of the CUBE to get the desired values. Since the CUBE stores all possible permutations of the dimensions there is a chance that the number or records in the cube itself might be large. Intelligent use of composite columns might help a great deal here. Note the use of composite columns (City, State) in the CUBE. This is because each state has got only one city with the office of our demo organization.</p>
<p>The GROUPING_ID function helps to achieve the ROLLUP. For example, take the combination (cust_name, cust_type). It is meaningless to make the cube perform aggregations for customer types across customer names. So we include only the bit vectors (1,1), (1, 0) and (0,0) that is GROUPING_ID of 3, 2 and 0 on the customer dimension.</p>
<p><span style="font-weight:bold;">Table 3 &#8211; Building a cube</span></p>
<p>CREATE TABLE sales_cube AS SELECT prd_name, prd_family, datekey, td_month, td_quarter, td_year, cust_name, cust_type, city, state, country, GROUPING_ID (prd_name, prd_family) GID_product, GROUPING_ID (datekey, td_month, td_quarter, td_year) GID_DATE, GROUPING_ID (cust_name, cust_type) GID_CUST, GROUPING_ID (city, state, country) GID_LOC, sum(amount) amount FROM sales, product, timebyday, location, customer WHERE sales.cust_id = customer.cust_id and sales.loc_id = location.loc_id and sales.sales_date = timebyday.datekey and sales.prdid = product.prdid GROUP BY CUBE ( prd_name, prd_family, datekey, td_month, td_quarter, td_year, cust_name, cust_type, (city, state), country ) HAVING ( GROUPING_ID (prd_name, prd_family) = 0 or GROUPING_ID (prd_name, prd_family) = 2 or GROUPING_ID (prd_name, prd_family) = 3) and ( GROUPING_ID (datekey, td_month, td_quarter, td_year) = 0 or GROUPING_ID (datekey, td_month, td_quarter, td_year) = 8 or GROUPING_ID (datekey, td_month, td_quarter, td_year) = 12 or GROUPING_ID (datekey, td_month, td_quarter, td_year) = 14 or GROUPING_ID (datekey, td_month, td_quarter, td_year) = 15) and ( GROUPING_ID (cust_name, cust_type) = 0 or GROUPING_ID (cust_name, cust_type) = 2 or GROUPING_ID (cust_name, cust_type) = 3) and ( GROUPING_ID (city, state, country) = 0 or GROUPING_ID (city, state, country) = 6 or GROUPING_ID (city, state, country) = 7 );The next table (<span style="font-weight:bold;">Table-4</span>) shows a typical crosstab query of sales for Product and Location. It shows the query and also how to generate a crosstab report out of it by using the function CROSSTAB (<span style="font-weight:bold;">Script-B</span>). The next examples show the query and cross-tab report and skips the PLSQL portion. The WHERE condition is determined by the bit vectors. We need -</p>
<ul class="bb-list" style="list-style-type:circle;">
<li>Details of product and details of customer &#8211; Both Product and Customer dimensions are all details. So GID_Product = bit vector (0,0) = 0. Same for GID_Cust.</li>
<li>Summary of product and details of customer &#8211; Product is summarized fully, so GID_Product = bit vector (1,1) = 3.</li>
<li>Details of product and summary of customer &#8211; Customer is summarized fully, GID_Customer = bit vector (1,1) = 3.</li>
<li>Summary of product and summary of customer &#8211; Both Customer and products are summarized.</li>
<li>Along with any of the above 4 conditions we need full summary or the rest of the dimensions. So GID_date = bit vector (1,1, 1,1) = 15 and GID_Loc = bit vector (1,1,1) = 7.</li>
</ul>
<p><span style="font-weight:bold;">Table-4 Crosstab Query on Product and Location (Query, Generation Routine and Result)</span></p>
<p>/*********** The Query ***********/ SELECT prd_name, cust_name, amount FROM sales_cube WHERE ((GID_Product = 0 and GID_Cust = 0) or (GID_Product = 0 and GID_Cust = 3) or (GID_Product = 3 and GID_Cust = 0) or (GID_Product = 3 and GID_Cust = 3)) and GID_date = 15 and GID_LOC = 7; /*********** Generating the crosstab report ********/ set serveroutput on set lines 120 var tempstr varchar2(500) exec :tempstr := &#8221;||- &#8216;SELECT cust_name, prd_name, amount&#8217;||chr(10)||- &#8216;FROM sales_cube&#8217;||chr(10)||- &#8216;WHERE ((GID_Product = 0 and GID_Cust = 0) or&#8217;||chr(10)||- &#8216; (GID_Product = 0 and GID_Cust = 3) or&#8217;||chr(10)||- &#8216; (GID_Product = 3 and GID_Cust = 0) or&#8217;||chr(10)||- &#8216; (GID_Product = 3 and GID_Cust = 3)) and&#8217;||chr(10)||- &#8216; GID_date = 15 and&#8217;||chr(10)||- &#8216; GID_LOC = 7&#8242;; exec crosstab(:tempstr); *Customers * *&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- Products &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;* ************ ALEXANDER BUDDHA CHANDRAGUPTA PURI BEACH SIKKIM &#8211;Total&#8211; ART HOUSE 0 0 0 500 750 1250 BARKER 5100 0 0 0 0 5100 JONES 0 0 0 2050 3500 5550 MAHAJATI 0 0 0 1000 0 1000 RATAN 0 5000 0 0 4000 9000 SMITH 9500 9000 900 0 0 19400 STONEWORK 850 800 6000 0 0 7650 &#8211;Total&#8211; 15450 14800 6900 3550 8250 48950Tables <span style="font-weight:bold;">Table-5</span>, <span style="font-weight:bold;">Table-6</span> and <span style="font-weight:bold;">Table-7</span> show TimeSales report and drill-down to the quarters of year 2003. Slicing is achieved by including WHERE condition in the query with desired values of the dimensions. Drill down is achieved by selection of proper value of GID_ type columns and by deciding the proper GROUPING value of all the dimensions at the particular level of drill down. Dicing is achieved by merely interchanging the first two columns of SELECT.</p>
<p><span style="font-weight:bold;">Table-5 Year-Product Sales Report: Main (Query and Result)</span></p>
<p>SELECT prd_name, td_year, amount FROM Sales_cube WHERE ((GID_Product = 0 and GID_date = 14) or (GID_Product = 0 and GID_date = 15) or (GID_Product = 3 and GID_date = 14) or (GID_Product = 3 and GID_date = 15)) and GID_Cust = 3 and GID_Loc = 7; ************ 2002 2003 &#8211;Total&#8211; ALEXANDER 5100 10350 15450 BUDDHA 6800 8000 14800 CHANDRAGUPTA 0 6900 6900 PURI BEACH 3550 0 3550 SIKKIM 0 8250 8250 &#8211;Total&#8211; 15450 33500 48950<span style="font-weight:bold;">Table-6 Year-Product Sales Report:Drill Down to Quarters and Dicing Product and Time Dimensions (Query and Result)</span></p>
<p>SELECT td_year||td_quarter, prd_name, amount FROM Sales_cube WHERE ((GID_Product = 0 and GID_date = 12) or (GID_Product = 0 and GID_date = 15) or (GID_Product = 3 and GID_date = 12) or (GID_Product = 3 and GID_date = 15)) and GID_Cust = 3 and GID_Loc = 7; ************ ALEXANDER BUDDHA CHANDRAGUPTA PURI BEACH SIKKIM &#8211;Total&#8211; 2002Q1 0 1000 0 2050 0 3050 2002Q2 5100 0 0 500 0 5600 2002Q4 0 5800 0 1000 0 6800 2003Q1 10350 0 6000 0 0 16350 2003Q2 0 0 0 0 750 750 2003Q3 0 8000 0 0 3500 11500 2003Q4 0 0 900 0 4000 4900 &#8211;Total&#8211; 15450 14800 6900 3550 8250 48950<span style="font-weight:bold;">Table-6 Year-Product Sales Report:Slice of year 2003, Quarter level drill down (Query and Result)</span></p>
<p>SELECT td_year||td_quarter, prd_name, amount FROM Sales_cube WHERE ((GID_Product = 0 and GID_date = 12) or (GID_Product = 0 and GID_date = 14) or (GID_Product = 3 and GID_date = 12) or (GID_Product = 3 and GID_date = 14)) and GID_Cust = 3 and GID_Loc = 7 and td_year = 2003; ************ ALEXANDER BUDDHA CHANDRAGUPTA SIKKIM &#8211;Total&#8211; 2003 10350 8000 6900 8250 33500 2003Q1 10350 0 6000 0 16350 2003Q2 0 0 0 750 750 2003Q3 0 8000 0 3500 11500 2003Q4 0 0 900 4000 4900<span style="text-decoration:underline;"><span style="font-weight:bold;">Using on-the-fly aggregation queries for CUBE, ROLLUP, Drill Down and Slicing</span></span></p>
<p>While using on-the-fly aggregation queries the cube is not pre-computed and we get the real time summary. However the performance is slower than querying pre-computed cubes. Several features (CUBE, ROLLUP, Composite Columns) discussed here can be used to generate the required aggregation levels. An important thing to ensure during executing on-the-fly queries is that, the query should not perform any useless aggregation. Proper use of the GROUPING functions is important.</p>
<p><span style="text-decoration:underline;"><span style="font-weight:bold;">Conclusion</span></span></p>
<p>Most of the OLAP tools will provide several additional features other than just reporting. There are user-friendly drag and drop interfaces which make drill-down, rollup, slicing, dicing happen on a mouse-click. Report generation and formatting is easier for someone who is not familiar with SQL. There are security features that restrict specific users from drilling down specific sections of the cube or viewing some specific cubes.</p>
<p>When the requirements are just few canned OLAP reports or when simple custom GUI can be made to mask the SQLs, use of the enhanced aggregation features can be really effective. A large portion of the requirements do fall in the second category.</p>
<p><span style="text-decoration:underline;"><span style="font-weight:bold;">Glossary and Scripts</span></span></p>
<p><span style="font-weight:bold;">Script A Script to create Sample Tables for Reporting examples</span></p>
<p>drop table product; drop table timebyday; drop table location; drop table customer; drop table sales; create table product (prdid number(2), prd_name varchar2(12), prd_family varchar2(10)); create table timebyday (datekey date, td_month char(3), td_quarter char(2), td_year char(4)); create table location (loc_id number(2), city varchar2(10), state varchar2(10), country varchar2(10)); create table customer (cust_id number(2), cust_name varchar2(10), cust_type varchar2(4)); create table sales (sales_id number(6), cust_id number(2), loc_id number(2), prdid number(2), sales_date date, amount number); insert into product values (1,&#8217;BUDDHA&#8217;,'STATUE&#8217;); insert into product values (2,&#8217;ALEXANDER&#8217;,'STATUE&#8217;); insert into product values (3,&#8217;CHANDRAGUPTA&#8217;,'STATUE&#8217;); insert into product values (4,&#8217;SIKKIM&#8217;,'PAINTING&#8217;); insert into product values (5,&#8217;PURI BEACH&#8217;,'PAINTING&#8217;); insert into location values (1, &#8216;KOLKATA&#8217;, &#8216;WB&#8217;,'INDIA&#8217;); insert into location values (2, &#8216;MUMBAI&#8217;,'MH&#8217;,'INDIA&#8217;); insert into location values (3, &#8216;SYDNEY&#8217;,'SA&#8217;,'AUSTRALIA&#8217;); insert into location values (4, &#8216;CHICAGO&#8217;,'IL&#8217;,'USA&#8217;); insert into customer values (1, &#8216;SMITH&#8217;, &#8216;INDV&#8217;); insert into customer values (2, &#8216;JONES&#8217;, &#8216;INDV&#8217;); insert into customer values (3, &#8216;BARKER&#8217;,'INDV&#8217;); insert into customer values (4, &#8216;ART HOUSE&#8217;,'ORGN&#8217;); insert into customer values (5, &#8216;STONEWORK&#8217;,'ORGN&#8217;); insert into customer values (6, &#8216;MAHAJATI&#8217;,'ORGN&#8217;); insert into customer values (7, &#8216;RATAN&#8217;,'INDV&#8217;); insert into sales values (1, 1, 4, 1, &#8216;05-JAN-02&#8242;, 1000); insert into sales values (2, 2, 3, 5, &#8216;1-MAR-02&#8242;, 2050); insert into sales values (3, 3, 4, 2, &#8216;14-MAY-02&#8242;, 5100); insert into sales values (4, 4, 3, 5, &#8216;22-JUN-02&#8242;, 500); insert into sales values (5, 5, 3, 1, &#8216;15-OCT-02&#8242;, 800); insert into sales values (6, 6, 1, 5, &#8216;10-NOV-02&#8242;, 1000); insert into sales values (7, 7, 1, 1, &#8216;25-DEC-02&#8242;, 5000); insert into sales values (8, 1, 4, 2, &#8216;18-FEB-03&#8242;, 9500); insert into sales values (9, 5, 3, 2, &#8216;28-FEB-03&#8242;, 850); insert into sales values (10, 5, 4, 3, &#8216;15-MAR-03&#8242;,6000); insert into sales values (11, 4, 4, 4, &#8216;12-JUN-03&#8242;, 750); insert into sales values (12, 1, 4, 1, &#8216;18-JUL-03&#8242;,8000); insert into sales values (13, 2, 3, 4, &#8216;5-AUG-03&#8242;,3500); insert into sales values (14, 1, 4, 3, &#8216;8-NOV-03&#8242;, 900); insert into sales values (15, 7, 2, 4, &#8216;23-NOV-03&#8242;,4000); insert into timebyday select distinct sales_date, to_char(sales_date,&#8217;MON&#8217;), &#8216;Q&#8217;||to_char(sales_date,&#8217;Q'), to_char(sales_date,&#8217;YYYY&#8217;) from sales; commit;<span style="font-weight:bold;">Script B Script to create procedure CROSSTAB</span></p>
<p>drop table temp_tab1; create table temp_tab1 (col1 varchar2(12), col2 varchar2(12), col3 number); create or replace procedure crosstab(ip_qstr varchar2) is type c1_rec is record (col1 varchar2(14), col2 varchar2(14), col3 number); type c1_tab is table of c1_rec; c1_tab1 c1_tab; varstr1 varchar2(200) := &#8221;; ho_value number; begin dbms_output.enable(1000000); execute immediate(&#8216;truncate table temp_tab1&#8242;); execute immediate ip_qstr bulk collect into c1_tab1; for ii in 1..c1_tab1.LAST loop insert into temp_tab1 values (nvl(c1_tab1(ii).col1,&#8217;&#8211;Total&#8211;&#8217;),nvl(c1_tab1(ii).col2,&#8217;&#8211;Total&#8211;&#8217;),c1_tab1(ii).col3); end loop; varstr1 := &#8216;************ &#8216;; for jj in (select distinct nullif(col2,&#8217;&#8211;Total&#8211;&#8217;) col2 from temp_tab1 order by 1 nulls last) loop varstr1 := varstr1||lpad(nvl(jj.col2,&#8217;&#8211;Total&#8211;&#8217;), 12)||&#8217; &#8216;; end loop; dbms_output.put_line(varstr1); for ii in (select distinct nullif(col1,&#8217;&#8211;Total&#8211;&#8217;) col1 from temp_tab1 order by 1 nulls last) loop varstr1 := rpad(nvl(ii.col1,&#8217;&#8211;Total&#8211;&#8217;),12); for jj in (select distinct nullif(col2,&#8217;&#8211;Total&#8211;&#8217;) col2 from temp_tab1 order by 1 nulls last) loop begin select col3 into ho_value from temp_tab1 where col1 = nvl(ii.col1,&#8217;&#8211;Total&#8211;&#8217;) and col2 = nvl(jj.col2,&#8217;&#8211;Total&#8211;&#8217;); exception when no_data_found then ho_value := 0; end; varstr1 := varstr1||&#8217; &#8216;||lpad(ho_value,12); end loop; dbms_output.put_line(varstr1); end loop; return; end crosstab; /<span style="text-decoration:underline;"><span style="font-weight:bold;">OLAP Terminologies</span></span></p>
<p>I am not considering in this article familiarity with OLAP terms as a prerequisite. Readers are advised to skip this section in case they are familiar with OLAP terminologies.</p>
<ul class="bb-list" style="list-style-type:circle;">
<li><span style="font-weight:bold;">Data Warehouse</span> Huge Store of historical transaction data from various sources. Gradually keeps on growing as more and more data is loaded into it (history increases). Logical Table structure of a data warehouse is designed keeping in mind the parameters we would like to analyze them with. As such, the logical design has special forms like Star Schema or Snowflake Schema. The physical design is done kept in mind the ease of query. As such warehouse table structures are de-normalized and heavily indexed.</li>
<li><span style="font-weight:bold;">ETL</span> Stands Extract, Transform and Load. This is the technique to load the huge store of point (1) from the various sources.</li>
<li><span style="font-weight:bold;">OLAP Engine</span> OLAP stands for Online Analytical Processing, the technique of reporting from the data warehouse.</li>
<li><span style="font-weight:bold;">Dimension and Measures</span> Take the function F (a, b, c) = (x, y, z) where a, b, c, x, y, and z are several attributes. Function F can be thought of as a business behavior where (x, y, z) are measures of that behavior. The business needs to know how the measure of behavior F, i.e. x, y, z, varies with categories (a, b, c). Probably, with that knowledge the business will try to manipulate (a,b,c) to get the desired (x, y, z), or it might take several other decisions not expressible in such simple terms. (a, b, c) are relatively static well defined categories known as Dimensions. The measures (x, y, z) are also known as Facts.</li>
<li><span style="font-weight:bold;">Dimension Table and Hierarchies</span> Each dimension has a fixed (or slowly changing) domain of values, which is stored in the dimension table. Each dimension can have aggregate attributes defined at several levels known as hierarchy. Hierarchies of a given dimension are also stored in dimension tables. Let &#8220;a&#8221; be a dimension, let &#8220;a1&#8243; be a collection of &#8220;a&#8221;, let &#8220;a2&#8243; be a collection of &#8220;a1&#8243;. The dimension table can be (a, a1, a2).</li>
<li><span style="font-weight:bold;">Fact Table</span> The table where dimensions are linked to the measures is known as Fact table. In our example we can take the fact table as (a, b, c, x, y, z). The dimension attributes mentioned in the fact tables are the ones with lowest granularity. So the fact table, in our example, will not have a1 or a2, which are aggregates.</li>
<li><span style="font-weight:bold;">Cube</span> Cube stores pre-computed aggregations, such as sums and counts, across all dimensions. It is useful in answering multidimensional questions by avoiding frequent summary from the flood of detailed data.</li>
<li><span style="font-weight:bold;">Drill Down </span>Frequently the business user will start with the highest aggregation of the hierarchy and ask for details on one or some selected dimensions. This is known as drill down.</li>
<li><span style="font-weight:bold;">Rollup</span> The requirement might also be to start from the lower granularity of a particular dimension and then move to the higher aggregates. This activity is known as rollup. If the requirement is to view the aggregation across all the level of hierarchies of any given dimension, then such a report is also known as rollup report.</li>
<li><span style="font-weight:bold;">Slice</span> Selecting some values of a dimension based on a filtering condition and then applying aggregation is known as slicing.</li>
<li><span style="font-weight:bold;">Dice</span> Changing the outlook of the report table, i.e., interchanging the row labels and column labels is known as dicing. It might be mentioned here that dicing does not affect the values of the aggregate columns.</li>
</ul>
<div class="links">»</p>
<ul class="links inline">
<li class="first blog_usernames_blog"><a class="blog_usernames_blog" title="Read Shouvik Basu's latest blog entries." href="/blog/shouvik_basu">Shouvik Basu&#8217;s blog</a></li>
<li class="last comment_forbidden"><span class="comment_forbidden"><a href="/user/login?destination=node/56%2523comment-form">Login</a> to post comments</span></li>
</ul>
</div>
<div id="comments"><a id="comment-179"></a></div>
<div class="comment">
<h3 class="title"><a class="active" href="/node/56#comment-179"></a></h3>
<div class="submitted">Submitted by Arnab (not verified) on Thu, 2005-04-28 13:05.</div>
<div class="content">
<p>This is an extremely good &amp; useful article. However I have a few points to make. I have personally worked in a few OLAP tools like Cognos. In Cognos the Transformer is used for creating a multidimensional cube. The rolled up data is same as that using Oracle Provided CUBE function. However the difference is that it uses multipass queries instead of a single query. There are several complex business rules which are either impossible or really difficult to implement in a single query. Also OLAP tools have lots of other reporting features including dashboard, graphs, drill through etc.</p></div>
<p><!-- BEGIN: links --></p>
<div class="links">»</p>
<ul class="links">
<li class="first last comment_forbidden"><span class="comment_forbidden"><a href="/user/login?destination=node/56%2523comment-form">Login</a> to post comments</span></li>
</ul>
</div>
<p><!-- END: links --></p>
<p><a id="comment-180"></a></p>
<div class="comment">
<h3 class="title"><a class="active" href="/node/56#comment-180"></a></h3>
<div class="submitted">Submitted by ila (not verified) on Thu, 2005-06-02 19:19.</div>
<div class="content">
<p>This is a very good artilcle. Any one looking for OLAP should try to use the oracle provided features before they look for other expensive OLAP softwares in the market.</p></div>
<p><!-- BEGIN: links --></p>
<div class="links">»</p>
<ul class="links">
<li class="first last comment_forbidden"><span class="comment_forbidden"><a href="/user/login?destination=node/56%2523comment-form">Login</a> to post comments</span></li>
</ul>
</div>
<p><!-- END: links --></p>
<p><a id="comment-181"></a></p>
<div class="comment">
<h3 class="title"><a class="active" href="/node/56#comment-181"></a></h3>
<div class="submitted">Submitted by shouvik (not verified) on Sat, 2005-04-30 23:21.</div>
<div class="content">
<p>Indeed Arnab, I do not disagree with you. You can refer the last line of my article. But the tradeoff here is the cost of Cognos vs. the cost of native SQL PLSQL crosstab and graph in XL.</p></div>
<p><!-- BEGIN: links --></p>
<div class="links">»</p>
<ul class="links">
<li class="first last comment_forbidden"><span class="comment_forbidden"><a href="/user/login?destination=node/56%2523comment-form">Login</a> to post comments</span></li>
</ul>
</div>
<p><!-- END: links --></p>
<p><a id="comment-257"></a></p>
<div class="comment">
<h3 class="title"><a class="active" href="/node/56#comment-257">&#8220;Taken the bull by the</a></h3>
<div class="submitted">Submitted by Ashwani Sehgal (not verified) on Fri, 2005-10-14 11:27.</div>
<div class="content">
<p>&#8220;Taken the bull by the horn&#8221; &#8211; Indeed</p></div>
<p><!-- BEGIN: links --></p>
<div class="links">»</p>
<ul class="links">
<li class="first last comment_forbidden"><span class="comment_forbidden"><a href="/user/login?destination=node/56%2523comment-form">Login</a> to post comments</span></li>
</ul>
</div>
<p><!-- END: links --></p>
<p><a id="comment-1933"></a></p>
<div class="comment">
<h3 class="title"><a class="active" href="/node/56#comment-1933">Explanation on extension to sql for aggregate</a></h3>
<div class="submitted">Submitted by angelo cutolo (not verified) on Tue, 2006-09-26 09:10.</div>
<div class="content">
<p>EXCELLENT!</p>
<p>You should do the same work with other obscure topics!</p>
<p>Grazie.</p>
<p>a.c.</p></div>
<p><!-- BEGIN: links --></p>
<div class="links">»</p>
<ul class="links">
<li class="first last comment_forbidden"><span class="comment_forbidden"><a href="/user/login?destination=node/56%2523comment-form">Login</a> to post comments</span></li>
</ul>
</div>
<p><!-- END: links --></div>
<p><!-- end main content --></div>
<p><!-- main --></div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
<table id="footer-menu" border="0" cellspacing="0" cellpadding="0" width="100%" summary="Navigation elements.">
<tbody>
<tr>
<td align="center" valign="middle">
<div class="secondary-links">.::<br />
<a title="Go to Home Page" href="http://www.orafaq.com/">Site Home</a> :: <a title="OraFAQ Wiki Home" href="http://www.orafaq.com/wiki">Wiki Home</a> :: <a title="Oracle Message Boards" href="http://www.orafaq.com/forum">Forum Home</a> :: <a title="Privace Policy Statement" href="http://www.orafaq.com/about/privacy">Privacy</a> :: <a title="Send feedback to the site's maintainers" href="http://www.orafaq.com/feedback">Contact</a> ::.</div>
</td>
</tr>
</tbody>
</table>
<p> </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/irfanmunir.wordpress.com/34/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/irfanmunir.wordpress.com/34/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/irfanmunir.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/irfanmunir.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/irfanmunir.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/irfanmunir.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/irfanmunir.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/irfanmunir.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/irfanmunir.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/irfanmunir.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/irfanmunir.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/irfanmunir.wordpress.com/34/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanmunir.wordpress.com&blog=853136&post=34&subd=irfanmunir&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://irfanmunir.wordpress.com/2008/06/12/enhanced-aggregation-cube-grouping-and-rollup-oracle-faq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/97ab84ac30aa08332253c3302cb86efd?s=96&#38;d=identicon" medium="image">
			<media:title type="html">irfanmunir</media:title>
		</media:content>

		<media:content url="/forum/banner/logo.jpg" medium="image" />

		<media:content url="http://ecx.images-amazon.com/images/I/512YP257C9L._SL160_.jpg" medium="image">
			<media:title type="html">cover of Database Systems Using Oracle (2nd Edition)</media:title>
		</media:content>

		<media:content url="http://www.orafaq.com/files/pictures/picture-9.jpg" medium="image">
			<media:title type="html">Shouvik Basu's picture</media:title>
		</media:content>
	</item>
		<item>
		<title>Start of SSAS</title>
		<link>http://irfanmunir.wordpress.com/2008/06/02/start-of-ssas/</link>
		<comments>http://irfanmunir.wordpress.com/2008/06/02/start-of-ssas/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 11:57:25 +0000</pubDate>
		<dc:creator>Irfan Munir</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://irfanmunir.wordpress.com/?p=30</guid>
		<description><![CDATA[ 
Being an implementer of custom data warehouse and query engine ; i just required an erge to learn and develop the SSAS . In post a head i will suppose to post some basic concpets regrading SSAS.
Any help will be appreciable
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanmunir.wordpress.com&blog=853136&post=30&subd=irfanmunir&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p> </p>
<p>Being an implementer of custom data warehouse and query engine ; i just required an erge to learn and develop the SSAS . In post a head i will suppose to post some basic concpets regrading SSAS.</p>
<p>Any help will be appreciable</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/irfanmunir.wordpress.com/30/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/irfanmunir.wordpress.com/30/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/irfanmunir.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/irfanmunir.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/irfanmunir.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/irfanmunir.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/irfanmunir.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/irfanmunir.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/irfanmunir.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/irfanmunir.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/irfanmunir.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/irfanmunir.wordpress.com/30/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanmunir.wordpress.com&blog=853136&post=30&subd=irfanmunir&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://irfanmunir.wordpress.com/2008/06/02/start-of-ssas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/97ab84ac30aa08332253c3302cb86efd?s=96&#38;d=identicon" medium="image">
			<media:title type="html">irfanmunir</media:title>
		</media:content>
	</item>
		<item>
		<title>Sql Server Login fro sa enable</title>
		<link>http://irfanmunir.wordpress.com/2008/05/28/sql-server-login-fro-sa-enable/</link>
		<comments>http://irfanmunir.wordpress.com/2008/05/28/sql-server-login-fro-sa-enable/#comments</comments>
		<pubDate>Wed, 28 May 2008 14:55:34 +0000</pubDate>
		<dc:creator>Irfan Munir</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://irfanmunir.wordpress.com/?p=29</guid>
		<description><![CDATA[http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=1292357&#38;SiteID=1
open SQL Server Management Studio Express and log in as a local administrator with a trusted connection&#8230;
navigate to the Security-&#62;Logins node of the Object Browser and select the &#8220;sa&#8221; login&#8230; rx click-&#62;Properties&#8230;. in the &#8220;Status&#8221; tab verify the &#8220;Login: Enabled&#8221; property has been set..
 
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanmunir.wordpress.com&blog=853136&post=29&subd=irfanmunir&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=1292357&amp;SiteID=1">http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=1292357&amp;SiteID=1</a></p>
<p>open SQL Server Management Studio Express and log in as a local administrator with a trusted connection&#8230;</p>
<p>navigate to the Security-&gt;Logins node of the Object Browser and select the &#8220;sa&#8221; login&#8230; rx click-&gt;Properties&#8230;. in the &#8220;Status&#8221; tab verify the &#8220;Login: Enabled&#8221; property has been set..</p>
<p> </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/irfanmunir.wordpress.com/29/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/irfanmunir.wordpress.com/29/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/irfanmunir.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/irfanmunir.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/irfanmunir.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/irfanmunir.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/irfanmunir.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/irfanmunir.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/irfanmunir.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/irfanmunir.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/irfanmunir.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/irfanmunir.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanmunir.wordpress.com&blog=853136&post=29&subd=irfanmunir&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://irfanmunir.wordpress.com/2008/05/28/sql-server-login-fro-sa-enable/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/97ab84ac30aa08332253c3302cb86efd?s=96&#38;d=identicon" medium="image">
			<media:title type="html">irfanmunir</media:title>
		</media:content>
	</item>
		<item>
		<title>Avoid casting to improve code performance .. Boxing UnBoxing</title>
		<link>http://irfanmunir.wordpress.com/2008/05/21/avoid-casting-to-improve-code-performance-boxing-unboxing/</link>
		<comments>http://irfanmunir.wordpress.com/2008/05/21/avoid-casting-to-improve-code-performance-boxing-unboxing/#comments</comments>
		<pubDate>Wed, 21 May 2008 05:52:24 +0000</pubDate>
		<dc:creator>Irfan Munir</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://irfanmunir.wordpress.com/?p=28</guid>
		<description><![CDATA[


 
 
 










 





Introduction: 


Question to Mr. C# Corner:
Hello. Mr. C# Corner. I&#8217;m Developer, I want to know why you advice me to use Generic instead of Casting Objects and what is the meaning of a Generic?


Answer: One of the important issues in the code development is the [Coding Quality], because your Coding Quality seperates you from other [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanmunir.wordpress.com&blog=853136&post=28&subd=irfanmunir&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><table style="width:1006px;height:124px;" border="0">
<tbody>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="3">
<table id="TABLE1" class="ArticleContent" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<table style="margin:15px 5px 10px 10px;" border="0" cellspacing="0" cellpadding="0" align="right">
<tbody>
<tr>
<td align="left"> </td>
</tr>
</tbody>
</table>
<div id="div2" class="PaddingLeft5"><span style="font-size:x-small;"><br />
</span></div>
<p align="justify"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><strong><span style="font-size:small;">Introduction:</span></strong> </span></span></p>
<p align="justify"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><br />
</span></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><strong>Question to Mr. C# Corner:</strong><br />
Hello. Mr. C# Corner. I&#8217;m Developer, I want to know why you advice me to use Generic instead of Casting Objects and what is the meaning of a Generic?<br />
</span></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><br />
<strong>Answer:</strong> One of the important issues in the code development is the [Coding Quality], because your Coding Quality seperates you from other developers. So let us see what are the basics of the coding quality:</span></span></p>
<div><span style="font-size:x-small;"></span></div>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"></p>
<li>Application Performance.</li>
<li>Reducing of Casting Object-based data structures.</li>
<li>Reuse data processing Algorithms (code).</li>
<div><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"></p>
<li><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><br />
<span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><strong>Question to Mr. C# Corner!</strong> You say &#8220;reduce Casting&#8221; of Objects. So what about casting Objects when using Collections (Boxing in general)?<br />
<strong>Answer:</strong> Ooh&#8230;I would like to see the following example which explains the advantage of using generics and how it is more efficient than using non-generic code and how does this matter in coding quality.</span></span></span></span></li>
<p> </p>
<p></span></span></div>
<div><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><strong><span style="font-size:small;">Getting Started</span></strong></span></span></span></span></span></span></div>
<p></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><strong>What is a Generic:</strong> Generics are a new feature in version 2.0 of the C# language and the common language runtime (CLR).</span></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><br />
</span></span></p>
<li>Generics introduce you to the .NET Framework the concept of type parameters, which makes it possible to design classes, and methods that defer the specification of one or more types until the class or method is declared and instantiated by client code.</li>
<li>Generics allow you to define type-safe data structures, without committing to actual data types.</li>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><strong>Let us see Simple Example about Using and benefits of Generics:</strong> </span></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">Let us see the difference between a non-generic class and a generic class with your eyes only:</span></span></p>
<p><span style="font-size:x-small;"><img src="Images/Generic.jpg" border="0" alt="" align="bottom" /></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">In Figure 1: </span></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><strong>Tip!! :</strong><br />
ArrayList is a highly convenient collection class that can be used without modification to store any reference or value type.</span></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><strong>Disadvantage of Casting (Boxing)</strong></span></span></p>
<p> </p>
<div></div>
<p><span style="font-size:x-small;"></p>
<li><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">Any reference or value type that is added to an ArrayList is implicitly upcast to the Object. If the items are value types, they must be boxed when added to the list, and unboxed when they are retrieved. Both the casting and the boxing and un-boxing operations degrade the code performance; the effect of boxing and un-boxing can be quite significant in scenarios where you must iterate over large collections of data.</span></li>
<li><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">The other limitation is lack of compile-time type checking; since an ArrayList casts everything to Object.</span></li>
<div><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">So if you think about generalizing you collection class, what you will do in C# 1.1?</span></span></div>
<div><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">You could avoid the dangers of generalized code in the .NET Framework base class library collection classes by writing your own type specific collections. Of course, since such a class is not reusable for more than one data type, you lose the benefits of generalization, and you have to rewrite the class for each type that will be stored.</span></span></div>
<div><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">In Figure 2:</span></span></span></span></div>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><span style="font-size:x-small;"><span style="font-size:small;font-family:Verdana,Arial,Helvetica,sans-serif;"><strong>Let us see what is happen in C# 2.0 to solve these problems:</strong></span></span></p>
<p></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">What ArrayList and other similar classes really need is:</span></span></p>
<p> </p>
<div></div>
<p></span><span style="font-size:x-small;"></p>
<li><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">A way for client code to specify, on a per-instance basis, the particular data type that they intend to use. That would eliminate the need for the upcast to T:System.Object and would also make it possible for the compiler to do type checking. In other words, ArrayList needs a type parameter. That is precisely what generics provide. In the generic List&lt;T&gt; collection, in the N:System.Collections.Generic namespace.</span></li>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">static</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> <span style="color:#0000ff;">void</span> GenericTest()</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">{</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#008000;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">// The .NET Framework 2.0 way to create a list</span></span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#2b91af;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">List</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">&lt;<span style="color:#0000ff;">int</span>&gt; list1 = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:#0000ff;">int</span>&gt;();</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#008000;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">// No boxing, no casting:</span></span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">list1.Add(3);</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#008000;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">// Compile-time error:</span></span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#008000;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">// list1.Add(&#8220;It is raining in Redmond.&#8221;);</span></span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">}</span></span></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">For example using a <strong><em>generic type parameter T</em></strong> you can write a single class that other client code can use without incurring the cost or risk of runtime casts or boxing operations.</span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#008000;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">// Declare the generic class</span></span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">public</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">GenericList</span>&lt;T&gt;</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">{</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">void</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> Add(T input) </span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">{ </span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">}</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">}</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">class</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> <span style="color:#2b91af;">TestGenericList</span></span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">{</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">private</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">ExampleClass</span> </span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">{</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">}</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">static</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> <span style="color:#0000ff;">void</span> Main()</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">{</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#008000;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">// Declare a list of type int</span></span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#2b91af;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">GenericList</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">&lt;<span style="color:#0000ff;">int</span>&gt; list1 = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">GenericList</span>&lt;<span style="color:#0000ff;">int</span>&gt;();</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#008000;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">// Declare a list of type string</span></span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#2b91af;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">GenericList</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">&lt;<span style="color:#0000ff;">string</span>&gt; list2 = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">GenericList</span>&lt;<span style="color:#0000ff;">string</span>&gt;();</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#008000;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">// Declare a list of type ExampleClass</span></span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#2b91af;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">GenericList</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">&lt;<span style="color:#2b91af;">ExampleClass</span>&gt; list3 = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">GenericList</span>&lt;<span style="color:#2b91af;">ExampleClass</span>&gt;();</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">}</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;line-height:115%;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">}</span></span></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><strong>Get Started:</strong></span></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">The boxing and Un-Boxing:</span></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><strong>What is boxing and Un-Boxing in C#?</strong></span></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">Boxing a value type packages it inside an instance of the Object reference type.</span></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">Boxing Example: </span></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">(a) most used Boxing:</span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">int</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> i = 10;</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">object</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> Obj = i;</span></span></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">(b) It also possible to perform the boxing explicitly as in the following:</span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">int</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> i = 10;</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#008000;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">// Casting the value type [ int ] to Object Reference type boxing</span></span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">object</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> Obj = (<span style="color:#0000ff;">object</span>)i;</span></span></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><strong>How Boxing performed?</strong></span></span> </p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">1- Declare a value-type variable [i] as int</span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">int</span></span></span><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> i = 10;</span></span></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">2- then applies the boxing operation on the variable [i]</span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">object</span></span></span><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><span style="color:#000000;"> Obj = i;</span></span></span></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">3- The result of this statement is creating an object reference Obj on the stack.</span></span></p>
<div><span style="font-size:x-small;"></p>
<li><span style="font-size:x-small;"><span style="font-size:x-small;"><br />
</span></span></li>
<p> </p>
<p></span></div>
<div><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">4- This Object references a value of the type int, on the heap. This value is a copy of the value-type value assigned to the variable [i] which equal 10.</span></span></span></span></div>
<p></span><span style="font-size:x-small;"><span style="font-size:x-small;"></p>
<li><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><strong>What are the Benefits of this concept?</strong></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">To allow the value type to be stored on the garbage collected heap.</span></span>
<p> </p>
<p></span></li>
<li><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">Un-Boxing Example:</span></span>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">Obj = 10;</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#008000;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">// Unboxing extracts the value type from the object Ref Type</span></span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">i = (<span style="color:#0000ff;">int</span>)Obj;</span></span></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><strong>! Disadvantage of Boxing</strong></span></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">Boxing and un-Boxing are expensive processes because of the following: </span></span></p>
<p> </p>
<p> </p>
<p></span></li>
<li><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">when a value type is boxed, an entirely new instance object must be allocated and constructed.</span></li>
<li><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">The cast required for un-boxing is also expensive computationally.</span></li>
<li><span style="font-size:x-small;"><br />
<span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><strong>Generic is better than using Object based Solution to reducing Object casting</strong> Let us see how?</span></span></span></li>
<div><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">With using Boxing:</span></span></span></div>
<p><span style="font-size:x-small;"></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"></span> </p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><br />
<span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"><br />
readonly</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> <span style="color:#0000ff;">int</span> m_Size;</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">int</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> m_StackPointer = 0;</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">object</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">[] m_Items;</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">public</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> <span style="color:#0000ff;">void</span> Push(<span style="color:#0000ff;">object</span> item)</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">{</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">if</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> (m_StackPointer &gt;= m_Size)</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">throw</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">StackOverflowException</span>();</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">m_Items[m_StackPointer] = item;</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">m_StackPointer++;</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">}</span></span></span></p>
<p><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">With using Generic:</span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">readonly</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> <span style="color:#0000ff;">int</span> m_Size;</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">int</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> m_StackPointer = 0;</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">T[] m_Items;</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">public</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> <span style="color:#0000ff;">void</span> Push(T item)</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">{</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">if</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> (m_StackPointer &gt;= m_Size)</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="color:#0000ff;"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">throw</span></span></span><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;"> <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">StackOverflowException</span>();</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">m_Items[m_StackPointer] = item;</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">m_StackPointer++;</span></span></span></p>
<p class="MsoNormal" style="background:#f2f2f2;line-height:normal;margin:0;"><span style="font-size:10pt;line-height:115%;font-family:'Verdana','sans-serif';"><span style="font-size:x-small;"><span style="font-family:Verdana,Arial,Helvetica,sans-serif;">}</span></span></span></p>
<p> </p>
<p> </p>
<p></span> </p>
<p></span></span> </p>
<p></span></span></span></span></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/irfanmunir.wordpress.com/28/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/irfanmunir.wordpress.com/28/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/irfanmunir.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/irfanmunir.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/irfanmunir.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/irfanmunir.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/irfanmunir.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/irfanmunir.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/irfanmunir.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/irfanmunir.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/irfanmunir.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/irfanmunir.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanmunir.wordpress.com&blog=853136&post=28&subd=irfanmunir&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://irfanmunir.wordpress.com/2008/05/21/avoid-casting-to-improve-code-performance-boxing-unboxing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/97ab84ac30aa08332253c3302cb86efd?s=96&#38;d=identicon" medium="image">
			<media:title type="html">irfanmunir</media:title>
		</media:content>

		<media:content url="Images/Generic.jpg" medium="image" />
	</item>
		<item>
		<title>Nine Ways to Win at Office Politics</title>
		<link>http://irfanmunir.wordpress.com/2008/03/14/nine-ways-to-win-at-office-politics/</link>
		<comments>http://irfanmunir.wordpress.com/2008/03/14/nine-ways-to-win-at-office-politics/#comments</comments>
		<pubDate>Fri, 14 Mar 2008 05:22:21 +0000</pubDate>
		<dc:creator>Irfan Munir</dc:creator>
				<category><![CDATA[Office Dealings]]></category>

		<guid isPermaLink="false">http://irfanmunir.wordpress.com/?p=27</guid>
		<description><![CDATA[Nine Ways to Win at Office Politics

By Rachel Zupek, CareerBuilder.com writer  


Politics in the workplace can get vicious – and we’re not talking about the governmental kind. Rather, office politics, or how power and influence are managed in your company, will be a part of your career whether you choose to participate in them or not.
Some [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanmunir.wordpress.com&blog=853136&post=27&subd=irfanmunir&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><span>Nine Ways to Win at Office Politics</span></p>
<h1></h1>
<div style="border-top:#cccccc 1px solid;margin-top:7px;font-size:10px;margin-left:2px;color:#666666;padding-top:3px;font-family:tahoma;">By <span>Rachel Zupek, CareerBuilder.com writer</span>  </div>
<p><img vspace="5" width="1" src="http://img.icbdr.com/images/pixel.gif" height="1" /></p>
<p><span class="ArticleText"><span></span></span><span class="ArticleText"><span></p>
<div>Politics in the workplace can get vicious – and we’re not talking about the governmental kind. Rather, office politics, or how power and influence are managed in your company, will be a part of your career whether you choose to participate in them or not.</div>
<div>Some workers say they don’t want to get caught up in politics at work, but most experts argue that playing the game is crucial to your career success. By not getting involved, you may find your talents ignored and your success limited, and you may feel left out of the loop, says Louellen Essex, co-author of “Manager’s Desktop Consultant: Just-in-Time Solutions to the Top People Problems That Keep You Up at Night.”</div>
<div> “Politics get nasty when an employee is out for his or her personal gain alone,” Essex says. “Think of playing office politics as a game of strategy through which you are able to get the resources and influence you need to accomplish your goals. Most often those who are diplomatic, respectful and build coalitions with effective people win.”</div>
<div>Here are Essex’s nine tips to help you win at office politics and still gain others&#8217; respect. </div>
<div><strong>1. Observe how things get done in your organization.</strong><br />
Ask some key questions: What are the core values and how are they enacted? Are short- or long-term results most valued? How are decisions made? How much risk is tolerated? The answers to these questions should give you a good sense of the culture of your organization.</div>
<div><strong>2. Profile powerful individuals.</strong><br />
Pay attention to their communication style, network of relationships and what types of proposals they say “yes” to most often. Emulate those traits by drawing on the strengths you have.</div>
<div><strong>3. Determine strategic initiatives in the company.</strong><br />
Update your skills to be relevant to company initiatives. For example, don’t lag behind in technology, quality or customer service approaches that are crucial to you and your company’s success.</div>
<div><strong>4. Develop a personal track record as someone who gets results.</strong><br />
Style without substance will not gain others’ respect, especially in today’s organizations that focus on outcome.</div>
<div><strong>5. Don’t be afraid to toot your own horn.</strong><br />
If no one knows of your good work, you may lose at the game of office politics – when you really deserve to win. Let others know what you’ve accomplished whenever you get the opportunity. If you don’t know the fine art of diplomatic bragging, you might get lost in the shuffle of your co-workers.</div>
<div><strong>6. Treat everyone with respect.</strong><br />
Don’t show preferential treatment or treat co-workers badly. You never know to whom someone might be connected, and rude behavior may come back to bite you.</div>
<div><strong>7. Don’t align too strongly with one group.</strong><br />
While an alliance may be powerful for the moment, new leadership will often oust existing coalitions and surround themselves with a new team. Bridging across factions may be a more effective strategy for long-term success if you intend to stay in your current organization for some time.</div>
<div><strong>8. Learn to communicate persuasively.<br />
</strong>Develop an assertive style, backed with solid facts and examples, to focus others’ attention on your ideas and proposals. Good politicians can adjust their messages for their audience ands are always well-prepared.</div>
<div><strong>9. Be true to yourself.</strong><br />
After analyzing the political landscape in your company, if you decide the game is one you can’t play, prepare to move on. It’s not typical, but some organizations actually condone – even promote – dishonest, ruthless or unethical behavior. The game of office politics in this situation is not one worth winning.</div>
<div><em>Rachel Zupek is a writer and blogger for CareerBuilder.com. She researches and writes about job search strategy, career management, hiring trends and workplace issues.</em></div>
<p></span></span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/irfanmunir.wordpress.com/27/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/irfanmunir.wordpress.com/27/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/irfanmunir.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/irfanmunir.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/irfanmunir.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/irfanmunir.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/irfanmunir.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/irfanmunir.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/irfanmunir.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/irfanmunir.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/irfanmunir.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/irfanmunir.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanmunir.wordpress.com&blog=853136&post=27&subd=irfanmunir&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://irfanmunir.wordpress.com/2008/03/14/nine-ways-to-win-at-office-politics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/97ab84ac30aa08332253c3302cb86efd?s=96&#38;d=identicon" medium="image">
			<media:title type="html">irfanmunir</media:title>
		</media:content>

		<media:content url="http://img.icbdr.com/images/pixel.gif" medium="image" />
	</item>
		<item>
		<title>Sqlserver Cursors</title>
		<link>http://irfanmunir.wordpress.com/2008/03/04/sqlserver-cursors/</link>
		<comments>http://irfanmunir.wordpress.com/2008/03/04/sqlserver-cursors/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 06:49:47 +0000</pubDate>
		<dc:creator>Irfan Munir</dc:creator>
				<category><![CDATA[SqlServer]]></category>

		<guid isPermaLink="false">http://irfanmunir.wordpress.com/?p=26</guid>
		<description><![CDATA[DECLARE @ExpressionValue varchar(max)
DECLARE @GetExpressionValue CURSOR SET @GetExpressionValue = CURSOR  FOR SELECT  Expression FROM Expression  
OPEN @GetExpressionValue 
FETCH NEXT FROM @GetExpressionValue INTO @ExpressionValueWHILE @@FETCH_STATUS = 0 BEGIN 
            PRINT @ExpressionValue
FETCH NEXT  FROM @GetExpressionValue INTO @ExpressionValue 
END
            CLOSE @GetExpressionValue
          DEALLOCATE @GetExpressionValue
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanmunir.wordpress.com&blog=853136&post=26&subd=irfanmunir&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><font size="2" color="#0000ff">DECLARE<font size="2"> @ExpressionValue </font><font size="2" color="#0000ff">varchar</font><font size="2" color="#808080">(</font><font size="2" color="#ff00ff">max</font><font size="2" color="#808080">)</font></font></p>
<p><font size="2" color="#0000ff"><font size="2" color="#0000ff">DECLARE<font size="2"> @GetExpressionValue </font><font size="2" color="#0000ff">CURSOR</font></font></font><font size="2" color="#0000ff"> </font><font size="2" color="#0000ff"><font size="2"></font><font size="2" color="#0000ff">SET</font><font size="2"> @GetExpressionValue </font><font size="2" color="#808080">=</font><font size="2"> </font><font size="2" color="#0000ff">CURSOR</font><font size="2">  </font><font size="2" color="#0000ff">FOR </font></font><font size="2" color="#0000ff"><font size="2" color="#0000ff">SELECT <font size="2"> Expression <font size="2" color="#0000ff">FROM</font><font size="2"> Expression  </font></font></font></p>
<p></font><font size="2" color="#0000ff"><font size="2"></font><font size="2" color="#0000ff">OPEN</font><font size="2"> @GetExpressionValue </font></font></p>
<p><font size="2" color="#0000ff"><font size="2"><font size="2" color="#0000ff">FETCH</font><font size="2"> NEXT <font size="2" color="#0000ff">FROM</font><font size="2"> @GetExpressionValue </font><font size="2" color="#0000ff">INTO</font><font size="2"> @ExpressionValue</font></font></font></font><font size="2" color="#0000ff"><font size="2" color="#0000ff">WHILE</font><font size="2"> </font><font size="2" color="#ff00ff">@@FETCH_STATUS</font><font size="2"> </font><font size="2" color="#808080">=</font><font size="2"> 0 </font></font><font size="2" color="#0000ff"><font size="2"><font size="2" color="#0000ff">BEGIN </font></font></p>
<p></font><font size="2"><font color="#0000ff">            </font><font size="+0"><font size="+0"></font><font color="#0000ff">PRINT</font><font size="+0"> @ExpressionValue</font></font></font></p>
<p><font size="2"><font size="+0"><font size="+0"><font color="#0000ff">FETCH</font><font size="+0"> NEXT</font></font></font></font><font size="+0"><font size="2">  </font></font><font size="2"><font color="#0000ff">FROM</font><font size="+0"> @GetExpressionValue </font><font color="#0000ff">INTO</font><font size="+0"> @ExpressionValue </font></font></p>
<p><font size="2"><font size="+0"><font color="#0000ff">END</font></font></font></p>
<p><font size="2"><font color="#0000ff">            </font><font size="+0"><font size="+0"></font><font color="#0000ff">CLOSE</font><font size="+0"> @GetExpressionValue</font></font></font></p>
<p><font size="2"><font size="+0">          <font size="+0"><font color="#0000ff">DEALLOCATE</font><font size="+0"> @GetExpressionValue</font></font></font></font></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/irfanmunir.wordpress.com/26/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/irfanmunir.wordpress.com/26/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/irfanmunir.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/irfanmunir.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/irfanmunir.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/irfanmunir.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/irfanmunir.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/irfanmunir.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/irfanmunir.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/irfanmunir.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/irfanmunir.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/irfanmunir.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=irfanmunir.wordpress.com&blog=853136&post=26&subd=irfanmunir&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://irfanmunir.wordpress.com/2008/03/04/sqlserver-cursors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/97ab84ac30aa08332253c3302cb86efd?s=96&#38;d=identicon" medium="image">
			<media:title type="html">irfanmunir</media:title>
		</media:content>
	</item>
	</channel>
</rss>