<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5679237228171649717</id><updated>2012-02-16T16:31:20.071+08:00</updated><category term='MSSQL Tricks'/><category term='ASP.Net and C#'/><category term='Design Pattern In Action'/><category term='Client Side Programming'/><category term='Project Accomplished and Involvement'/><title type='text'>Learn IT From Vince</title><subtitle type='html'>Explore...Learn...Design...</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>32</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-6170930189274492416</id><published>2011-07-26T11:34:00.004+08:00</published><updated>2011-07-26T11:53:06.560+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MSSQL Tricks'/><title type='text'>Inserting result of Stored Procedure to a table</title><content type='html'>I haven't thought that I can use the result of a stored procedure to another stored procedure. If I have this need I usually convert the SP to user define function to return a table then use that inside the SP.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Until I came across to this search where I want to filter the result of the SP_WHO2 by adding where condition on it. SP_WHO2 is a system stored procedure to return record of threads running on the database instance.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Thanks for this code from &lt;a href="http://stackoverflow.com/questions/2234691/sql-server-filter-output-of-sp-who2"&gt;http://stackoverflow.com/questions/2234691/sql-server-filter-output-of-sp-who2&lt;/a&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="border-collapse: collapse; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; white-space: pre; "&gt;&lt;span class="kwd" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 139); background-position: initial initial; background-repeat: initial initial; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="border-collapse: collapse; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; "&gt;&lt;pre class="lang-sql prettyprint" style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(238, 238, 238); font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; overflow-x: auto; overflow-y: auto; width: auto; max-height: 600px; background-position: initial initial; background-repeat: initial initial; "&gt;&lt;code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(238, 238, 238); font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-position: initial initial; background-repeat: initial initial; "&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; "&gt;Declare @Table TABLE(SPID INT&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; "&gt;,&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;&lt;br /&gt;    Status VARCHAR&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;(&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;MAX&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;),&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;&lt;br /&gt;    LOGIN VARCHAR&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;(&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;MAX&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;),&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;&lt;br /&gt;    HostName VARCHAR&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;(&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;MAX&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;),&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;&lt;br /&gt;    BlkBy VARCHAR&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;(&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;MAX&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;),&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;&lt;br /&gt;    DBName VARCHAR&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;(&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;MAX&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;),&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;&lt;br /&gt;    Command VARCHAR&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;(&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;MAX&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;),&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;&lt;br /&gt;    CPUTime INT&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;,&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;&lt;br /&gt;    DiskIO INT&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;,&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;&lt;br /&gt;    LastBatch VARCHAR&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;(&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;MAX&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;),&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;&lt;br /&gt;    ProramName VARCHAR&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;(&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;MAX&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;),&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;&lt;br /&gt;    SPID_1 INT&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;,&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;&lt;br /&gt;    REQUESTID INT&lt;br /&gt;&lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;)&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="kwd" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 139); background-position: initial initial; background-repeat: initial initial; "&gt;INSERT&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt; &lt;/span&gt;&lt;span class="kwd" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 139); background-position: initial initial; background-repeat: initial initial; "&gt;INTO&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt; &lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;@&lt;/span&gt;&lt;span class="kwd" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 139); background-position: initial initial; background-repeat: initial initial; "&gt;Table&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt; &lt;/span&gt;&lt;span class="kwd" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 139); background-position: initial initial; background-repeat: initial initial; "&gt;EXEC&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt; sp_who2&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="kwd" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 139); background-position: initial initial; background-repeat: initial initial; "&gt;SELECT&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;  &lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;*&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="kwd" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 139); background-position: initial initial; background-repeat: initial initial; "&gt;FROM&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;    &lt;/span&gt;&lt;span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;@&lt;/span&gt;&lt;span class="kwd" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 139); background-position: initial initial; background-repeat: initial initial; "&gt;Table&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="kwd" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 139); background-position: initial initial; background-repeat: initial initial; "&gt;WHERE&lt;/span&gt;&lt;span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: rgb(0, 0, 0); background-position: initial initial; background-repeat: initial initial; "&gt; LOGIN = 'vince'&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-6170930189274492416?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/6170930189274492416/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2011/07/inserting-result-of-stored-procedure-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/6170930189274492416'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/6170930189274492416'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2011/07/inserting-result-of-stored-procedure-to.html' title='Inserting result of Stored Procedure to a table'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-753297934897770734</id><published>2011-02-08T11:11:00.007+08:00</published><updated>2011-07-19T16:40:05.770+08:00</updated><title type='text'>Simplest way to query XML in MSSQL</title><content type='html'>&lt;pre&gt;&lt;span&gt;&lt;span style="font-family:Arial;"&gt;For Accessing XML nodes:&lt;br /&gt;&lt;br /&gt;DECLARE @xml xml&lt;br /&gt;SET @xml = N'&lt;polist&gt;&lt;br /&gt;         &lt;po&gt;&lt;ponumber&gt;100&lt;/ponumber&gt;&lt;podate&gt;2008-09-10&lt;/podate&gt;&lt;/po&gt;&lt;br /&gt;         &lt;po&gt;&lt;ponumber&gt;101&lt;/ponumber&gt;&lt;podate&gt;2008-09-11&lt;/podate&gt;&lt;/po&gt;&lt;br /&gt;       &lt;/polist&gt;'&lt;br /&gt;SELECT&lt;br /&gt;doc.col.value('ponumber[1]', 'nvarchar(10)') ponumber&lt;br /&gt;,doc.col.value('podate[1]', 'datetime') podate&lt;br /&gt;FROM @xml.nodes('/polist/po') doc(col)&lt;br /&gt;&lt;br /&gt;For Accessing element attributes:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style="font-family:Arial;"&gt;DECLARE @xml xml&lt;br /&gt;SET @xml = N'&lt;polist&gt;&lt;br /&gt;         &lt;po ponumber="100" podate="2008-09-10"&gt;&lt;br /&gt;         &lt;po ponumber="101" podate="2008-09-11"&gt;&lt;br /&gt;       &lt;/po&gt;'&lt;br /&gt;SELECT&lt;br /&gt;doc.col.value('@ponumber', 'nvarchar(10)') ponumber&lt;br /&gt;,doc.col.value('@podate', 'datetime') podate&lt;br /&gt;&lt;br /&gt;FROM @xml.nodes('/polist/po') doc(col)&lt;/po&gt;&lt;/polist&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;For accessing XML arrays:&lt;br /&gt;&lt;br /&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style="font-family:Arial;"&gt;DECLARE @xml xml&lt;br /&gt;SET @xml = N'&lt;polist&gt;&lt;br /&gt;         &lt;ponumber&gt;100&lt;/ponumber&gt;&lt;br /&gt;         &lt;ponumber&gt;101&lt;/ponumber&gt;&lt;br /&gt;       &lt;/polist&gt;'&lt;br /&gt;SELECT&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-753297934897770734?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/753297934897770734/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2011/02/simplest-way-to-query-xml-in-mssql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/753297934897770734'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/753297934897770734'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2011/02/simplest-way-to-query-xml-in-mssql.html' title='Simplest way to query XML in MSSQL'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-4530889546972849749</id><published>2010-03-18T20:23:00.004+08:00</published><updated>2010-03-18T20:49:19.653+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MSSQL Tricks'/><title type='text'>Alternate Value of two fields in one column</title><content type='html'>&lt;span style="font-family:arial;"&gt;I just found a very good tool that can find and replace any files that I selected with the set of old and new values I added all at the same time. I can even select a batch of folders to look for and millions of text that needs to be replaced with just a blink of an eye. This solves our problem with Hyperion where we need to migrate all the reports from an old system to a new system where with an all new sets of account TRULY HORRIBLE. As a programmer we don't want just to sit in my computer and replace each of the account with the new account manually. So when we found a way to automate the conversion we are all so happy that a report that can be converted in one whole day now can be converted in just a few minutes.&lt;br /&gt;&lt;br /&gt;The &lt;a href="http://www.ecobyte.com/replacetext/"&gt;ReplaceText Tool&lt;/a&gt; have an 'Import Replace Table' where you can import the set of old value and new value to its table in a text format.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;a onblur="try  {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_fyjCBJzAqOM/S6If38qBjVI/AAAAAAAAC9A/UoZuF77VhrU/s1600-h/replaceEM.JPG"&gt;&lt;img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 245px; height: 275px;" src="http://1.bp.blogspot.com/_fyjCBJzAqOM/S6If38qBjVI/AAAAAAAAC9A/UoZuF77VhrU/s320/replaceEM.JPG" alt="" id="BLOGGER_PHOTO_ID_5449953545107377490" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;But the problem is the text format is just one column where the old and new values just alternates on each line.&lt;br /&gt;&lt;br /&gt;The challenge is how can I write a query where I could have one columns and the value of the old and new alternates on the row.&lt;br /&gt;&lt;br /&gt;As fast as the Replace Text tool I have write the solution in SQL script:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;SELECT Field FROM&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;((SELECT '&amp;gt;'+ OldAccount + '&amp;lt;' AS Field,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt; (((ROW_NUMBER() OVER(Order by ID))-1)*2 + 1) AS FieldOrder&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt; FROM ConvertedAccounts)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;UNION ALL&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;(SELECT '&amp;gt;'+NewAccount + '&amp;lt;' AS Field,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt; (((ROW_NUMBER() OVER(Order by ID)))*2) AS FieldOrder&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt; FROM ConvertedAccounts)) A&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;ORDER BY FieldOrder&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;span style="font-family:courier new;"&gt;END&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-4530889546972849749?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/4530889546972849749/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2010/03/alternate-value-of-two-fields-in-one.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/4530889546972849749'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/4530889546972849749'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2010/03/alternate-value-of-two-fields-in-one.html' title='Alternate Value of two fields in one column'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_fyjCBJzAqOM/S6If38qBjVI/AAAAAAAAC9A/UoZuF77VhrU/s72-c/replaceEM.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-8504660184677137050</id><published>2009-01-24T22:53:00.007+08:00</published><updated>2009-01-25T10:49:55.242+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Design Pattern In Action'/><title type='text'>Add abilities to your Objects with Decorator Pattern</title><content type='html'>&lt;div style="margin: 0px auto 10px; text-align: center;"&gt;&lt;div style="text-align: left;"&gt;From the word decorator, it adds new functionality (Decoration) to the operations of your instantiated object. If you will try to analyze the design it is like specializing a class through inheritance but here we are doing it on runtime. The Idea is to have an abstract class that will be the base type of all the components. As you instantiate the object you are passing an object of the same type and return a newly instantiated object of the same base type but has additional process on the methods that is being decorated. As you continue on decorating the object by instantiating another decorator object, the functionality accumulates. recursion happens by calling an overidden method until it goes to the first base class that was instantiated.&lt;br /&gt;&lt;br /&gt;To understand the concept, imagine += operator in C# which accumulates the sum of numbers:&lt;br /&gt;&lt;br /&gt;A = 5;&lt;br /&gt;B = 10;&lt;br /&gt;C = 15;&lt;br /&gt;&lt;br /&gt;A += B;&lt;br /&gt;A += C;&lt;br /&gt;&lt;br /&gt;on the last line A has a component of B and C (5 + 10 + 15) which we accumalate by the += operator.&lt;br /&gt;&lt;br /&gt;Let us see now the design in Action. Below is the UML diagram of the DatabaseProvider Decorator I created:&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_fyjCBJzAqOM/SXsrtqyJGlI/AAAAAAAACN0/hDDRiA_YSZ8/s1600-h/DecoratorPatern.JPG"&gt;&lt;img alt="" src="http://1.bp.blogspot.com/_fyjCBJzAqOM/SXsrtqyJGlI/AAAAAAAACN0/hDDRiA_YSZ8/s400/DecoratorPatern.JPG" border="0" /&gt;&lt;/a&gt; &lt;/div&gt;&lt;div style="clear: both; text-align: center;"&gt;Click Image to Enlarge&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;Before I adapted the Decorator Pattern here, the original purpose of the DatabaseProvider is to Provide a Template (IDatabase) of basic Database Execution for all kinds of database.  With that, I can use this with my DatabaseProviderFactory without even worrying on what connection I am using. As the need arises, I have thought of a way of discovering Parameters of the stored procedure then extracting the values for that parameter on the Entity being passed on the decorator object. Actually this design is just part of my own MVC implementation which I might also discuss in the future.&lt;br /&gt;&lt;br /&gt;Let us see now the codes :&lt;br /&gt;&lt;br /&gt;Here is the IDatabase Interface which provides the template for all kind of Database&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt; &lt;/span&gt;&lt;span style="color: rgb(255, 255, 204);font-size:85%;" &gt; public interface IDatabase : IDisposable&lt;br /&gt;{&lt;br /&gt;  string CommandText { get; set; }&lt;br /&gt;   CommandType CommandType { get; set; }&lt;br /&gt;   string ConnectionString { get; set; }&lt;br /&gt;&lt;br /&gt;   void AddParameterWithValue(string parameterName, object value);&lt;br /&gt;   void AddParameter(IDataParameter parameter);&lt;br /&gt;   IDataReader ExecuteReader();&lt;br /&gt;   int ExecuteNonQuery();&lt;br /&gt;   object ExecuteScalar();&lt;br /&gt;   DataSet ExecuteDataset();&lt;br /&gt;   List&amp;lt;T&amp;gt; ExecuteToEntity&amp;lt;T&amp;gt;(T instance) where T :  IEntity&amp;lt;T&amp;gt;;&lt;br /&gt;&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This next class is the Decorator Abstract Class which the main functionality is to save an object of IDatabase, which is also his type, that is passed on the constructor.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 102);font-size:85%;" &gt;&lt;span style="color: rgb(255, 255, 204);"&gt;   public abstract class DBDecorator : IDatabase&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;   {&lt;/span&gt;&lt;br /&gt;    &lt;span style="font-weight: bold; color: rgb(255, 255, 204);"&gt;protected IDatabase _database;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 255, 204);"&gt;        public DBDecorator(IDatabase database)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 255, 204);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 255, 204);"&gt;            _database = database;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 255, 204);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       public string CommandText&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;           get&lt;/span&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;{&lt;/span&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;return _database.CommandText;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;           set&lt;/span&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;{&lt;/span&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;_database.CommandText = value;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       public CommandType CommandType&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;           get&lt;/span&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;{&lt;/span&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;return _database.CommandType;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;           set&lt;/span&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;{&lt;/span&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;_database.CommandType = value;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       public string ConnectionString&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;           get&lt;/span&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;{&lt;/span&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;return _database.ConnectionString;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;           set&lt;/span&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;{&lt;/span&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;_database.ConnectionString = value;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       public virtual void AddParameterWithValue(string parameterName, object value)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;           _database.AddParameterWithValue(parameterName, value);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       public virtual void AddParameter(IDataParameter parameter)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;           _database.AddParameter(parameter);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       public virtual IDataReader ExecuteReader()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;         return  _database.ExecuteReader();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       public virtual int ExecuteNonQuery()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;         return  _database.ExecuteNonQuery();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       public virtual object ExecuteScalar()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;         return  _database.ExecuteScalar();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       public virtual DataSet ExecuteDataset()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;         return  _database.ExecuteDataset();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       public virtual List&amp;lt;T&amp;gt; ExecuteToEntity&amp;lt;T&amp;gt;(T instance) where T : IEntity&amp;lt;T&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;         return  _database.ExecuteToEntity(instance);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       }      &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       public void Dispose()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;           _database.Dispose();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;       }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;   }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;Now the last class adds two new private methods, DiscoverParameter and AssignParameter which is being called before the execusion of the actual Base Class.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;    public class SQLDatabaseDecorator&amp;lt;T&amp;gt; : DBDecorator&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        private List&lt;string&gt; _parameterNames = new List&lt;string&gt;();&lt;/string&gt;&lt;/string&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        private T _entity;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        public SQLDatabaseDecorator(IDatabase db, T entity) &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;            : base(db)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;            _entity = entity;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        &lt;span style="font-weight: bold;"&gt; private void DiscoverParameter()&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;            PersistenceManager&amp;lt;list&amp;lt;string&amp;gt;&amp;gt; parameterNamesPM = &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                new PersistenceManager&amp;lt;list&amp;lt;string&amp;gt;&amp;gt;(PersistIn.Application,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                                 CommandText + "_SQLDatabaseDecorator");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;            if (parameterNamesPM.Exists())&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                _parameterNames = parameterNamesPM.Get();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;            else&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                using (SqlConnection connection = new SqlConnection(this.ConnectionString))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                    connection.Open();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                    SqlCommand command = connection.CreateCommand();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                    command.CommandText = this.CommandText;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                    command.CommandType = this.CommandType;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                    SqlCommandBuilder.DeriveParameters(command);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                    foreach (SqlParameter param in command.Parameters)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                    {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                        _parameterNames.Add(param.ParameterName);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                    parameterNamesPM.Add(_parameterNames);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;        private void AssignParameters()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;            foreach (string paramName in _parameterNames)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                if (_entity.GetType().GetProperties().ToList()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                          .Exists(x =&amp;gt; ("@" + x.Name.ToUpper()) == paramName.ToUpper()))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                    PropertyInfo pi = _entity.GetType().GetProperties().ToList()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                           .Find(x =&amp;gt; ("@" + x.Name.ToUpper()) == paramName.ToUpper());&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                    base.AddParameterWithValue(paramName, pi.GetValue(_entity, null));&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;                }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204); font-weight: bold;"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        public override IDataReader  ExecuteReader()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;            DiscoverParameter();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;            AssignParameters();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;             return base.ExecuteReader();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        public override int ExecuteNonQuery()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;            DiscoverParameter();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;            AssignParameters();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;            return base.ExecuteNonQuery();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        public override object ExecuteScalar()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;            DiscoverParameter();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;            AssignParameters();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;            return base.ExecuteScalar();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        public override DataSet ExecuteDataset()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;            DiscoverParameter();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;            AssignParameters();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;            return base.ExecuteDataset();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        public override List&amp;lt;U&amp;gt;  ExecuteToEntity&amp;lt;U&amp;gt;(U instance)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;             DiscoverParameter();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;             AssignParameters();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;              return base.ExecuteToEntity(instance);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        }                   &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Now the classes are ready, here is how we use the decorator objects :&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 102);font-size:85%;" &gt;           &lt;span style="color: rgb(255, 255, 204);"&gt;Company InsertCompany = new Company();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;           InsertCompany.CompanyName = "My Company";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;           InsertCompany.Address = "Global City Taguig";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;           InsertCompany.PhoneNumber = "111-11-11";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;           InsertCompany.UserId = 1;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;           string connectionString = "Data Source=.;Initial Catalog=GE;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;                   Integrated Security=false;User Id=sa;Password=password;";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;       &lt;span style="font-weight: bold; color: rgb(255, 255, 204);"&gt; IDatabase target = new SQLDatabaseProvider(connectionString);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 255, 204);"&gt;                using (target = new SQLDatabaseDecorator&lt;company&gt;(target, InsertCompany))&lt;/company&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;               {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;                   target.CommandText = "AddCompany";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;                   target.CommandType = System.Data.CommandType.StoredProcedure;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;                   InsertCompany.CompanyId = Convert.ToInt32(target.ExecuteScalar());&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;                   System.Console.WriteLine("New Company Id was inserted with Company Id {0}",&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;                        InsertCompany.CompanyId);&lt;/span&gt;&lt;br /&gt;          &lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;               }&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you notice, I did not pass any parameters on the DatabaseProvider. The Decorator is doing it for us. It reads the parameter in the database then locate the values on the entity which in this case is the Company Object.&lt;br /&gt;&lt;br /&gt;Happy Programming!!!&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-8504660184677137050?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/8504660184677137050/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2009/01/add-abilities-to-your-objects-with.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/8504660184677137050'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/8504660184677137050'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2009/01/add-abilities-to-your-objects-with.html' title='Add abilities to your Objects with Decorator Pattern'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_fyjCBJzAqOM/SXsrtqyJGlI/AAAAAAAACN0/hDDRiA_YSZ8/s72-c/DecoratorPatern.JPG' height='72' width='72'/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-8696128783803621748</id><published>2009-01-17T13:02:00.005+08:00</published><updated>2009-01-17T23:46:35.490+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Project Accomplished and Involvement'/><title type='text'>Integrated Information Management System</title><content type='html'>Description: Monitors chassis movement and produce inventory report and billing statements per client.&lt;br /&gt;&lt;br /&gt;Type: Web Application&lt;br /&gt;&lt;br /&gt;Tools:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;C#.Net&lt;/li&gt;&lt;li&gt;MSSQL&lt;/li&gt;&lt;li&gt;AJAX&lt;/li&gt;&lt;li&gt;ASP.Net&lt;/li&gt;&lt;li&gt;Crystal Report&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;Duration: October&lt;br /&gt;&lt;br /&gt;Client: Transcom Cargo Services&lt;br /&gt;&lt;br /&gt;Function: Freelance Project&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-8696128783803621748?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/8696128783803621748/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2009/01/integrated-information-management.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/8696128783803621748'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/8696128783803621748'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2009/01/integrated-information-management.html' title='Integrated Information Management System'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-5190146743156361309</id><published>2009-01-17T11:44:00.002+08:00</published><updated>2009-01-17T11:49:17.514+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Project Accomplished and Involvement'/><title type='text'>Global Experts</title><content type='html'>Description: The Global Expert (GE) online platform is a web based collaboration package that targets consultancy service providers and gives them a convenient and intelligent means to service customers with real-time tools that include voice and imaging. As a complete collaboration package, the GE platform also offers sophisticated features like desktop and file sharing, remote desktop capabilities, white boarding, presence, and event notifications. Customers only have to use their internet browsers and go to the GE website to avail of the service.&lt;br /&gt;&lt;br /&gt;Type: Web Application&lt;br /&gt;&lt;br /&gt;Tools:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;C#.Net&lt;/li&gt;&lt;li&gt;MSSQL&lt;/li&gt;&lt;li&gt;AJAX&lt;/li&gt;&lt;li&gt;ASP.Net&lt;/li&gt;&lt;/ul&gt;Duration: November 5, 2008 to Present&lt;br /&gt;&lt;br /&gt;Function: Senior Web Developer&lt;br /&gt;&lt;br /&gt;Company Attached with : &lt;a href="http://www.venzo.dk/"&gt;Venzo Business Solution&lt;br /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-5190146743156361309?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/5190146743156361309/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2009/01/global-experts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/5190146743156361309'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/5190146743156361309'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2009/01/global-experts.html' title='Global Experts'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-6446210098894359422</id><published>2009-01-17T11:36:00.004+08:00</published><updated>2009-01-17T11:43:10.527+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Project Accomplished and Involvement'/><title type='text'>Online Vessel Sounding Report</title><content type='html'>Description: A Web application that generates report of the measurements of vessels during and after loading of oil products. It also tracks vessels of there voyage.&lt;br /&gt;&lt;br /&gt;Type: Web Application&lt;br /&gt;&lt;br /&gt;Tools:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;C#.Net&lt;/li&gt;&lt;li&gt;MSSQL&lt;/li&gt;&lt;li&gt;AJAX&lt;/li&gt;&lt;li&gt;ASP.Net&lt;/li&gt;&lt;li&gt;Crystal Report&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Client: Petron, Philippines&lt;br /&gt;&lt;br /&gt;Involvement: Free lance project&lt;br /&gt;&lt;a href="http://www.blastasia.com/"&gt;&lt;br /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-6446210098894359422?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/6446210098894359422/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2009/01/online-vessel-sounding-report.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/6446210098894359422'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/6446210098894359422'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2009/01/online-vessel-sounding-report.html' title='Online Vessel Sounding Report'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-4105386066160090155</id><published>2009-01-17T08:52:00.006+08:00</published><updated>2009-01-20T08:42:54.777+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MSSQL Tricks'/><title type='text'>Recursive Call in Stored Procedures</title><content type='html'>Recursion is a way of allowing a function to call itself. It results to an iteration of process. Let us have the simple example below that computes for the result of an exponent function:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;        static void Main(string[] args)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            double result = exponent(3,4);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            Console.WriteLine(result);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            Console.ReadKey();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        private static double exponent(double _base, double power)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            double result= _base;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            if (power &gt; 0)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;                result = result * exponent(_base, power - 1);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;                result = 1;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            return result;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        }&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This is the sample recursive call function in C#.  Take note that in recursion there should be a way to terminate the recursion through conditions or else it will bring you to an infinite loop.&lt;br /&gt;&lt;br /&gt;Now how can we implement this in SQL?  It is allowed to call a stored procedure within a stored procedure. Unfortunately Stored procedure does not return values directly. In case of User Defined Function(UDF), it is not allowed to call a function within a function. Recursions should have a return value in order to determine how the loop will terminate.&lt;br /&gt;&lt;br /&gt;The trick here is to use Temporary table to communicate with the calling stored procedure.  For simplicity, let's use the same example in getting the result of an exponent:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;ALTER PROCEDURE [dbo].[RecursiveCallExponent] (&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    @base float,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    @power float&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;AS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    IF(@power &gt; 0)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        UPDATE #Result SET Result = Result * @Base&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        SET @power = @power -1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        exec RecursiveCallExponent @base, @power&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    END&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;END&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;-------------------------&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;ALTER PROCEDURE GetExponent (&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    -- Add the parameters for the stored procedure here&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    @base float,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    @power float&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;AS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    CREATE TABLE #Result (Result float)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    insert into #Result (Result) values (1 )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    exec RecursiveCallExponent @base, @power&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    SELECT Result FROM #Result&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    DROP TABLE #Result&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;END&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;GetExponent here is the main stored procedure call. Observe that The Temporary table is created in the main stored procedure to be used by the recursive procedure (RecursiveCallExponent). We cannot create it inside the recursive procedure for it will raise  "Object exists" error since we are iterating inside it. Now we can run&lt;br /&gt;      "EXEC GetExponent(3,4)"&lt;br /&gt;and will give you a result of 81.&lt;br /&gt;&lt;br /&gt;I used recursive on my application to get all consultant with a specific skill in the Heirarchy of skillsets. The scenario is this, I have a Hierachical table which represents the Heirarchy of Skills, e.g. Words, Excel and Powerpoint under MSOffice and MSOffice, Explorer and Media Player under Windows. When I choose specific skills like MSOffice, I should be able to get all consultant under MSOffice including those consultant who has special skills for Powerpoint, Excel and Word and even those under it if it still have sub categories.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-4105386066160090155?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/4105386066160090155/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2009/01/recursive-call-in-stored-procedures.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/4105386066160090155'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/4105386066160090155'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2009/01/recursive-call-in-stored-procedures.html' title='Recursive Call in Stored Procedures'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-502699223993798608</id><published>2008-06-06T15:26:00.001+08:00</published><updated>2008-06-06T15:26:44.157+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net and C#'/><title type='text'>Think Generic</title><content type='html'>One feature I’m starting to love with C# is the use of generic classes. We usually use some classes like List&amp;lt;T&amp;gt;, Dictionary&amp;lt;key, Value&amp;gt; which uses generic types. It expands the usage of your class through polymorphism. A simple way of how Generic works, think of adding a number or adding a string or adding fractions, what if we add objects? They all have the same verb ADD but have different implementation. A sample code is written below:&lt;br /&gt;&lt;br /&gt;public interface GenericMath&amp;lt;T&amp;gt; &lt;br /&gt;{&lt;br /&gt;    T Add(T Operand1, T Operand2);&lt;br /&gt;    T Subtract(T Operand1, T Operand2);&lt;br /&gt;    T Multiply(T Operand1, T Operand2);&lt;br /&gt;    T Divide(T Operand1, T Operand2);&lt;br /&gt;   &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class IntegerMath : IGenericMath&amp;lt;int&amp;gt;&lt;br /&gt;{&lt;br /&gt;    public int Add(int Operand1, int Operand2)&lt;br /&gt;    {&lt;br /&gt;      return Operand1 + Operand2;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public  int Subtract(int Operand1, int Operand2)&lt;br /&gt;    {&lt;br /&gt;      return Operand1 - Operand2;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    int Multiply(int Operand1, int Operand2)&lt;br /&gt;{ … }&lt;br /&gt;    int Divide(int Operand1, int Operand2)&lt;br /&gt;{ … }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Although the example below is not that useful but I hope I have explained clearly how generic works.&lt;br /&gt;&lt;br /&gt;As I explore more on generics, I found out that it is so useful on database frameworks like DEV Force, CSLA.Net or ADO.Net Entity Framework. This frameworks uses entities as their records holders. Entities are classes defined automatically by those frameworks to make tables a strong type class. Meaning fields can be access directly as lastName = Customer.LastName unlike before that we uses string then cast it to its typle like this : lastName = (string)Row[“LastName”]. Since every classes that uses the Models returns different entities it is difficult to create a base class that will manipulate Different Entity. A Code below simplifies the Manipulation of data for Dev Force:&lt;br /&gt;&lt;br /&gt;public class EntityManagerBase&amp;lt;T&amp;gt;: IEntityManager&amp;lt;T&amp;gt; where T : IdeaBlade.Persistence.Entity&lt;br /&gt;    {&lt;br /&gt;        private Entity defaultEntity = null;&lt;br /&gt;        private EntityColumn primaryKeyField = null;&lt;br /&gt;      &lt;br /&gt;        private PersistenceManager data;&lt;br /&gt;        private T entityProperty= null;&lt;br /&gt;        private int numLength = 6;&lt;br /&gt;        private string uniqueIdPrefix;&lt;br /&gt;        private string uniqueNoField;&lt;br /&gt;        private bool explicitSave = false;&lt;br /&gt;      &lt;br /&gt;        #region [Properties]&lt;br /&gt;        public EntityColumn PrimaryKeyField&lt;br /&gt;        {&lt;br /&gt;            get { return primaryKeyField; }&lt;br /&gt;            set { primaryKeyField = value; }&lt;br /&gt;        }&lt;br /&gt;        public bool ExplicitSave&lt;br /&gt;        {&lt;br /&gt;            get { return explicitSave; }&lt;br /&gt;            set { explicitSave = value; }&lt;br /&gt;        }&lt;br /&gt;        public string UniqueNoField&lt;br /&gt;        {&lt;br /&gt;            get { return uniqueNoField; }&lt;br /&gt;            set { uniqueNoField = value; }&lt;br /&gt;        }&lt;br /&gt;        public int NumLength&lt;br /&gt;        {&lt;br /&gt;            get { return numLength; }&lt;br /&gt;            set { numLength = value; }&lt;br /&gt;        }             &lt;br /&gt;        public T EntityProperty&lt;br /&gt;        {&lt;br /&gt;            get { return entityProperty;}&lt;br /&gt;            set { entityProperty = value;}&lt;br /&gt;        }&lt;br /&gt;        public PersistenceManager Data&lt;br /&gt;        {&lt;br /&gt;            get { return data; }&lt;br /&gt;            set { data = value; }&lt;br /&gt;        }&lt;br /&gt;        public EntityManagerBase(PersistenceManager pData)&lt;br /&gt;        {&lt;br /&gt;            data= pData;&lt;br /&gt;            EntityProperty = (T)pData.CreateEntity(typeof(T));&lt;br /&gt;        }&lt;br /&gt;        #endregion&lt;br /&gt;        #region [Virtual Methods]&lt;br /&gt;        public virtual bool UpdateEntity(object pPrimaryKey)&lt;br /&gt;        {&lt;br /&gt;            PrimaryKey primaryKey = new PrimaryKey(typeof(T), pPrimaryKey);&lt;br /&gt;            T entity = data.GetEntity&amp;lt;T&amp;gt;(primaryKey);      &lt;br /&gt;            Initialize();&lt;br /&gt;            AssignValues(entity);&lt;br /&gt;            return CheckAndSave();  &lt;br /&gt;        }&lt;br /&gt;       &lt;br /&gt;        public virtual bool UpdateEntity(params object[] pPrimaryKeys)&lt;br /&gt;        {&lt;br /&gt;            PrimaryKey primaryKey = new PrimaryKey(typeof(T), pPrimaryKeys);&lt;br /&gt;            T entity = data.GetEntity&amp;lt;T&amp;gt;(primaryKey);&lt;br /&gt;            Initialize();&lt;br /&gt;            AssignValues(entity);  &lt;br /&gt;            return CheckAndSave();&lt;br /&gt;        }&lt;br /&gt;        public virtual T CreateEntity()&lt;br /&gt;        {&lt;br /&gt;            T entity = (T)data.CreateEntity(typeof(T));&lt;br /&gt;            uniqueNoField = "";&lt;br /&gt;            uniqueIdPrefix = "";&lt;br /&gt;            ProcessCreate(entity);&lt;br /&gt;            return entity;&lt;br /&gt;        }&lt;br /&gt;        public virtual T CreateEntity(string pUniqueNoField, string pUniqueIdPrefix)&lt;br /&gt;        {&lt;br /&gt;            T entity = (T)data.CreateEntity(typeof(T));&lt;br /&gt;            uniqueNoField = pUniqueNoField;&lt;br /&gt;            uniqueIdPrefix = pUniqueIdPrefix;&lt;br /&gt;&lt;br /&gt;            ProcessCreate(entity);&lt;br /&gt;            return entity;&lt;br /&gt;        }&lt;br /&gt;        public virtual bool DeleteEntity(object pPrimaryKey)&lt;br /&gt;        {&lt;br /&gt;            SaveResult result;&lt;br /&gt;            PrimaryKey pk = new PrimaryKey(typeof(T), pPrimaryKey);&lt;br /&gt;            Entity ent = Data.GetEntity(pk);&lt;br /&gt;            ent.Delete();&lt;br /&gt;            result = Data.SaveChanges();&lt;br /&gt;            Data.Clear();&lt;br /&gt;            return result.Ok;&lt;br /&gt;        }&lt;br /&gt;        public virtual bool DeleteEntity(params object[] pPrimaryKeys)&lt;br /&gt;        {&lt;br /&gt;            SaveResult result;&lt;br /&gt;            PrimaryKey pk = new PrimaryKey(typeof(T), pPrimaryKeys);&lt;br /&gt;            Entity ent = Data.GetEntity(pk);&lt;br /&gt;            ent.Delete();&lt;br /&gt;            result = Data.SaveChanges();&lt;br /&gt;            Data.Clear();&lt;br /&gt;            return result.Ok;&lt;br /&gt;        }&lt;br /&gt;        public virtual T GetEntityByPrimaryKey(object pPrimaryKey)&lt;br /&gt;        {&lt;br /&gt;            PrimaryKey primaryKey = new PrimaryKey(typeof(T), pPrimaryKey);&lt;br /&gt;            T entity = data.GetEntity&amp;lt;T&amp;gt;(primaryKey);      &lt;br /&gt;            return entity;&lt;br /&gt;        }&lt;br /&gt;        public virtual T GetEntityByPrimaryKey(params object[] pPrimaryKeys)&lt;br /&gt;        {&lt;br /&gt;            PrimaryKey primaryKey = new PrimaryKey(typeof(T), pPrimaryKeys);&lt;br /&gt;            T entity = data.GetEntity&amp;lt;T&amp;gt;(primaryKey);      &lt;br /&gt;            return entity;&lt;br /&gt;        }&lt;br /&gt;        public virtual EntityList&amp;lt;T&amp;gt; GetEntityList(EntityColumn pColumn, EntityQueryOp pQueryOp, object pValue)&lt;br /&gt;        {&lt;br /&gt;            RdbQuery rdbQ = new RdbQuery(typeof(T));&lt;br /&gt;            EntityList&amp;lt;T&amp;gt; aList;&lt;br /&gt;            rdbQ.AddClause(pColumn, pQueryOp, pValue);&lt;br /&gt;            aList = data.GetEntities&amp;lt;T&amp;gt;(rdbQ);&lt;br /&gt;            return aList;&lt;br /&gt;        }&lt;br /&gt;        public virtual EntityList&amp;lt;T&amp;gt; GetEntityList(List&amp;lt;Clause&amp;gt; Clauses)&lt;br /&gt;        {&lt;br /&gt;            RdbQuery rdbQ = new RdbQuery(typeof(T));&lt;br /&gt;            EntityList&amp;lt;T&amp;gt; aList;&lt;br /&gt;                       &lt;br /&gt;            int counter = Clauses.Count;&lt;br /&gt;            for(counter = 0; counter &amp;lt; Clauses.Count; counter ++)&lt;br /&gt;            {&lt;br /&gt;              rdbQ.AddClause(Clauses[counter].FilterColumn, Clauses[counter].QueryOperator, Clauses[counter].PassedValue);&lt;br /&gt;              if(counter &amp;lt; Clauses.Count -1 )&lt;br /&gt;              {&lt;br /&gt;                  rdbQ.AddOperator(Clauses[counter].ClauseOperator);&lt;br /&gt;              }&lt;br /&gt;            }&lt;br /&gt;            aList = data.GetEntities&amp;lt;T&amp;gt;(rdbQ);&lt;br /&gt;            return aList;&lt;br /&gt;        }&lt;br /&gt;        private bool CheckAndSave()&lt;br /&gt;        {&lt;br /&gt;            if(!explicitSave)&lt;br /&gt;            {&lt;br /&gt;                if (Data.HasChanges())&lt;br /&gt;                {&lt;br /&gt;                    Data.SaveChanges();&lt;br /&gt;                    return true;&lt;br /&gt;                }&lt;br /&gt;             }&lt;br /&gt;            return false;&lt;br /&gt;        }&lt;br /&gt;        public bool SaveChanges()&lt;br /&gt;        { &lt;br /&gt;                if (Data.HasChanges())&lt;br /&gt;                {&lt;br /&gt;                    Data.SaveChanges();&lt;br /&gt;                    return true;&lt;br /&gt;                }&lt;br /&gt;         &lt;br /&gt;            return false;&lt;br /&gt;        }&lt;br /&gt;        #endregion&lt;br /&gt;        private void AssignValues(T entity)&lt;br /&gt;        {&lt;br /&gt;            foreach (EntityColumn column in Data.GetEntityColumns(typeof(T)))&lt;br /&gt;            {&lt;br /&gt;                if (!column.IsPrimaryKeyColumn &amp;amp;&amp;amp; EntityProperty[column.ColumnName] != defaultEntity[column.ColumnName])&lt;br /&gt;                {&lt;br /&gt;                    entity[column.ColumnName] = EntityProperty[column.ColumnName];&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        public string GenerateNo(string prefix )&lt;br /&gt;        {               &lt;br /&gt;            EntityList&amp;lt;T&amp;gt; aList = data.GetEntities&amp;lt;T&amp;gt;();&lt;br /&gt;            string maxNo;&lt;br /&gt;            if (aList.Count &amp;gt; 0)&lt;br /&gt;            {&lt;br /&gt;                maxNo = (Convert.ToString(Convert.ToInt32(((aList[aList.Count - 1])[primaryKeyField.ColumnName])) + 1));&lt;br /&gt;            }&lt;br /&gt;            else&lt;br /&gt;            {&lt;br /&gt;                maxNo = "1";&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            int len = maxNo.Length;&lt;br /&gt;            int padLength = numLength - len;&lt;br /&gt;            string padZero = new string('0',padLength);&lt;br /&gt;                       &lt;br /&gt;            return string.Format("{0}-{1}{2}", prefix, padZero, maxNo);&lt;br /&gt;        }&lt;br /&gt;        private void ProcessCreate(T entity)&lt;br /&gt;        {&lt;br /&gt;            foreach (EntityColumn column in Data.GetEntityColumns(typeof(T)))&lt;br /&gt;            {&lt;br /&gt;                if (column.IsPrimaryKeyColumn)&lt;br /&gt;                {&lt;br /&gt;                    primaryKeyField = column;&lt;br /&gt;                    break;&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;             if(uniqueNoField != "")&lt;br /&gt;             {&lt;br /&gt;                entity[uniqueNoField] = GenerateNo(uniqueIdPrefix);              &lt;br /&gt;             }&lt;br /&gt;            entity.AddToManager();&lt;br /&gt;            Initialize();&lt;br /&gt;            AssignValues(entity);&lt;br /&gt;            CheckAndSave();&lt;br /&gt;        }&lt;br /&gt;         private void Initialize()&lt;br /&gt;        {           &lt;br /&gt;            defaultEntity = data.CreateEntity(typeof(T));&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    public struct Clause&lt;br /&gt;    {&lt;br /&gt;        public EntityColumn FilterColumn;&lt;br /&gt;        public EntityQueryOp QueryOperator;&lt;br /&gt;        public object PassedValue;&lt;br /&gt;        public EntityBooleanOp ClauseOperator;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;We used it on MAN Project and it works!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-502699223993798608?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/502699223993798608/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/06/think-generic.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/502699223993798608'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/502699223993798608'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/06/think-generic.html' title='Think Generic'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-5540794105500987901</id><published>2008-05-09T18:06:00.002+08:00</published><updated>2008-05-09T18:13:33.578+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net and C#'/><title type='text'>The Wonder of SQLCacheDependency Class</title><content type='html'>The Wonder of SQLCacheDependency Class&lt;br /&gt;&lt;br /&gt;Here’s a new exciting lesson I learned when working with my recent project. The challenge is to create a Price Screen for Commodity Trading that will update on real time. This should be done as optimize as possible for this will be shown over the Net. We usually save reusable data in Application variable or in Session variable for optimization purpose. Here is a sample code that we usually did to persist data.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public static DataTable ExecuteDataTable(persistIn persistence, string&lt;br /&gt;storedProcedureName, params object[] parameterValues)&lt;br /&gt;{&lt;br /&gt;DataTable&lt;br /&gt;returnTable = null;&lt;br /&gt;switch (persistence)&lt;br /&gt;{&lt;br /&gt;case persistIn.Session:&lt;br /&gt;returnTable = (DataTable)HttpContext.Current.Session&lt;br /&gt;[storedProcedureName.ToUpper()];&lt;br /&gt;if (returnTable == null)&lt;br /&gt;{&lt;br /&gt;returnTable = db.ExecuteDataSet(storedProcedureName,&lt;br /&gt;parameterValues).Tables[0];&lt;br /&gt;HttpContext.Current.Session&lt;br /&gt;[storedProcedureName.ToUpper()] = returnTable;&lt;br /&gt;}&lt;br /&gt;break;&lt;br /&gt;case&lt;br /&gt;persistIn.Application:&lt;br /&gt;returnTable =&lt;br /&gt;(DataTable)HttpContext.Current.Application [storedProcedureName.ToUpper()];&lt;br /&gt;if (returnTable == null)&lt;br /&gt;{&lt;br /&gt;returnTable =&lt;br /&gt;db.ExecuteDataSet(storedProcedureName, parameterValues).Tables[0];&lt;br /&gt;HttpContext.Current.Application [storedProcedureName.ToUpper()] =&lt;br /&gt;returnTable;&lt;br /&gt;}&lt;br /&gt;break;&lt;br /&gt;case persistIn.NoPersistence:&lt;br /&gt;returnTable&lt;br /&gt;= db.ExecuteDataSet(storedProcedureName, parameterValues).Tables[0];&lt;br /&gt;break;&lt;br /&gt;default:&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;return returnTable;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Here, the result returned by a call to a stored procedure is saved in Server Memory, either in Session of Application. When the Data already exists there is no need to call for the stored procedure again, it just fetches the data in Server Memory and return it. The problem here is when there are changes on the data from the database the application won’t fetch the new item unless you force to change the value stored on the Server Variable, this can be done by calling this function and passing persistIn.NoPersistence as parameter.&lt;br /&gt;&lt;br /&gt;The solution here is use SQLCacheDependency. SQLCacheDependency has the capability to detect changes on Database and delete specific data on memory that depends on it. What you need to do is to add dependency on table that will tell the application that its time to fetch a new data. So when someone updates that table the application will fetch a new data for the variable is lost on the memory.&lt;br /&gt;&lt;br /&gt;But you need to configure your database and add some code for this to work. I listed below the steps to do to be able to use SQLCacheDependency:&lt;br /&gt;&lt;br /&gt;1. Update your database by Running the script in SQL.&lt;br /&gt;ALTER DATABASE YourDatabase SET ENABLE_BROKER; GO&lt;br /&gt;This will enable Service Broker that will raise notification to ASP for changes on database&lt;br /&gt;&lt;br /&gt;2. On your Global.asax, you should add one if you don’t have this yet, add the following line:&lt;br /&gt;&lt;blockquote&gt;1: string connectionString = ConfigurationManager.&lt;br /&gt;ConnectionStrings[0].ConnectionString;&lt;br /&gt;2:&lt;br /&gt;System.Data.SqlClient.SqlDependency.Start(connectionString);&lt;br /&gt;3:&lt;br /&gt;SqlCacheDependencyAdmin. EnableNotifications(connectionString);&lt;br /&gt;4:&lt;br /&gt;SqlCacheDependencyAdmin. EnableTableForNotifications (connectionString,&lt;br /&gt;"TableName");&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Line 1 will retrieve the connection string that you are using in your web app. The user you used on the Connection string should have the full access in your database.&lt;br /&gt;Line 2 Starts the listening in the event&lt;br /&gt;Line 3 Adds some stored procedure needed for notifications&lt;br /&gt;Line 4 Adds Trigger to table that you are watching&lt;br /&gt;&lt;br /&gt;3. Add the following on your web.config inside &amp;lt;system.web&amp;gt;:&lt;br /&gt;&lt;blockquote&gt;&amp;lt;caching&amp;gt;&lt;br /&gt;&amp;lt;sqlCacheDependency enabled = "true" pollTime&lt;br /&gt;= "1000" &amp;gt;&lt;br /&gt;&amp;lt;databases&amp;gt;&lt;br /&gt;&amp;lt;add name="Database"&lt;br /&gt;connectionStringName="MyConnection"&lt;br /&gt;pollTime="1000"/&amp;gt;&lt;br /&gt;&amp;lt;/databases&amp;gt;&lt;br /&gt;&amp;lt;/sqlCacheDependency&amp;gt;&lt;br /&gt;&amp;lt;/caching&amp;gt; &lt;/blockquote&gt;&lt;br /&gt;The Name attribute will be used by the SQLCacheDependency to know how it will connect to the database.&lt;br /&gt;The ConnectionStringName attribute will map the connection you are using in web.config.&lt;br /&gt;&lt;br /&gt;4. Now you are ready to use SQLCacheDependency on your code as written bellow:&lt;br /&gt;&lt;blockquote&gt;public static DataSet ExecuteDataTable(string storedProcedureName, params&lt;br /&gt;object[] parameterValues)&lt;br /&gt;{&lt;br /&gt;DataSet myDataset = new DataSet();&lt;br /&gt;if&lt;br /&gt;(HttpContext.Current.Cache[storedProcedureName.ToUpper()] == null)&lt;br /&gt;{&lt;br /&gt;SqlCommand command = new SqlCommand();&lt;br /&gt;command.CommandType =&lt;br /&gt;CommandType.StoredProcedure;&lt;br /&gt;command.CommandText = " MyStoredProcedure";&lt;br /&gt;SqlCacheDependency dependency = new SqlCacheDependency("Database",&lt;br /&gt;"TableName");&lt;br /&gt;myDataset = db.ExecuteDataSet(storedProcedureName,&lt;br /&gt;parameterValues);&lt;br /&gt;HttpContext.Current.Cache.Insert(storedProcedureName.ToUpper(),&lt;br /&gt;myDataset,&lt;br /&gt;dependency);&lt;br /&gt;}&lt;br /&gt;return myDataset;&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Then that’s it. You will experience the magic of it! If you will check your database once you have run your application, there are several new stored procedures and tables added by ASP. This is use for notification purpose, don’t erase those.&lt;br /&gt;&lt;br /&gt;Now what I did on my Project is Add an AJAX Timer that will check if the Cache still exists, if not it will update the screen to display new data. It is a real-time base on web. Amazing!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-5540794105500987901?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/5540794105500987901/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/05/wonder-of-sqlcachedependency-class.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/5540794105500987901'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/5540794105500987901'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/05/wonder-of-sqlcachedependency-class.html' title='The Wonder of SQLCacheDependency Class'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-2458105913834485576</id><published>2008-04-26T06:35:00.001+08:00</published><updated>2008-04-26T06:37:51.466+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net and C#'/><title type='text'>When To Disable and Enable The Viewstate on a control</title><content type='html'>Viewstate has a big impact on web performance. If you will not pay attention to it, your website will become a large junk.&lt;br /&gt;&lt;br /&gt;How Viewstate does affect performance? Remember that Client and Server Communicates via a postback. And posting a web page as large as 50KB is like uploading a file on youtube or attaching a file on yahoo mail, imagine that. You can check how large is your viewstate when you look at the rendered page by clicking View Source for IE, the part that is garbage looking that occupies almost the whole part of your notepad. Just look at the tag saying __VIEWSTATE.&lt;br /&gt;&lt;br /&gt;What really is the function of viewstate? Viewstate is used by ASP.Net to remember the state of the control before a postback occur. One good example is how ASP.Net know that a text has changed when a postback occur or if you have enabled autopostback of the control. It is very simple with the use of viewstate, the value of the textbox is saved on the viewstate, when user changes the value of it and a postback occurs it compares the new value of the textbox and the viewstate if it matches if it does not it raises onChange event.&lt;br /&gt;&lt;br /&gt;Now imagine how many controls you have and all of them have viewstate. Each control occupies at list 20 bytes multiply it by the number of your controls. Aside from those, templated and bounded controls like Gridview, Datalist or dropdownlist occupies a very large size of viewstate. But wait we cannot just disable all of them or put enableViewState = false on page directives. What we can do is to use Viewstate wisely.&lt;br /&gt;&lt;br /&gt;Here are some pointers I think would help you decide when to disable viewstate.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt; Dynamically inserted value on the controls (By binding or programmatically assigning) &lt;/strong&gt;– The values of this controls will not retain when it is rerendered, e.g. Switching from view1 to view2. But you have to consider two things, if you think repopulating the values for every render is to heavy to implement then don’t disable the viewstate, if not then you may disable it and reinitialize your controls on render event. Why am I suggesting this? It’s because processing serverside code is much faster than transferring a large junk of data back to the server and unto the client on roundtrips.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;On Datalist and DropDownList &lt;/strong&gt;– If you are not using the OnSelectedIndex Change event then you may disable the viewstate.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;On Gridviews&lt;/strong&gt; – This is the hardest part to decide whether to disable viewstate or retain it. If you are just displaying data on it or even using it just for selection, then disable the viewstate. If you are using paging, edit or delete functionality then don’t. Gridview has the largest viewstate capacity so you should use it wisely. If you have to update as many as 5 columns then why not just open another view then set the values there to be updated rather than updating it on the gridview directly.&lt;br /&gt;&lt;br /&gt;These are just some of my tips, but you should always test the effect of it so you can see if controls behaves as expected even without viewstate.&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-2458105913834485576?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/2458105913834485576/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/04/when-to-disable-and-enable-viewstate-on.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/2458105913834485576'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/2458105913834485576'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/04/when-to-disable-and-enable-viewstate-on.html' title='When To Disable and Enable The Viewstate on a control'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-2427759393034354627</id><published>2008-04-18T14:36:00.003+08:00</published><updated>2008-04-24T14:13:11.296+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net and C#'/><title type='text'>Calling A Method By Name</title><content type='html'>Sometimes we are developing a system that is very much dependent in the database. I call this style as Data Driven Development where everything depends on the database. Even for Buttons that should be available on screen. I have develop a Touch Screen System before using Delphi where Buttons are created Dynamically depending on the set of data returned by the database. This means that each buttons calls its method by function name. To achieve this we set a centralize Event Handler for all Buttons Created Dynamically and then call the routine by Name. That is easy in Delphi for you can call routines of a protected method by Name.&lt;br /&gt;When I shifted to C# I wonder how will I achieve that same functionality. Atlast with some few trials and hard work, I have created a class to handle this. The code is as follows:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;p&gt;public delegate void methodDelegate();&lt;br /&gt;public class FunctionByName&lt;br /&gt;{&lt;br /&gt;private ArrayList&lt;br /&gt;ListOfMethodAddress = new&lt;br /&gt;ArrayList();&lt;br /&gt;private ArrayList&lt;br /&gt;ListOfMethodName = new ArrayList();&lt;br /&gt;public void&lt;br /&gt;AddMethod(methodDelegate&lt;br /&gt;MethodAddress)&lt;br /&gt;{&lt;br /&gt;ListOfMethodName.Add(MethodAddress.Method.Name);&lt;br /&gt;ListOfMethodAddress.Add(MethodAddress);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void ExecMethod(string&lt;br /&gt;MethodName)&lt;br /&gt;{&lt;br /&gt;if&lt;br /&gt;(ListOfMethodName.Contains(MethodName))&lt;br /&gt;{&lt;br /&gt;int MethodIndex =&lt;br /&gt;ListOfMethodName.IndexOf(MethodName);&lt;br /&gt;methodDelegate toExec = new&lt;br /&gt;methodDelegate((methodDelegate)ListOfMethodAddress[MethodIndex]);&lt;br /&gt;toExec();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;The difference is that you should add all delegates that you want to be called by name using AddMethod, Then to execute it you call ExecMethod("MyFunction"), Here you are calling MyFunction Method but it should be added initially before you can call it.&lt;br /&gt;&lt;br /&gt;Updated: Below is a new version of my CallFunctionByName Class it. It uses Dictionary rather than ArrayList:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public delegate void methodDelegate();&lt;br /&gt;public class&lt;br /&gt;FunctionByName&lt;br /&gt;{&lt;br /&gt;private Dictionary&lt;string,methoddelegate&gt;&lt;br /&gt;ListOfMethod = new Dictionary&lt;string,methoddelegate&gt;();&lt;br /&gt;public void&lt;br /&gt;AddMethod(methodDelegate&lt;br /&gt;MethodAddress)&lt;br /&gt;{&lt;br /&gt;ListOfMethod.Add(MethodAddress.Method.Name,&lt;br /&gt;MethodAddress);&lt;br /&gt;}&lt;br /&gt;public void ExecMethod(string MethodName)&lt;br /&gt;{&lt;br /&gt;if&lt;br /&gt;(ListOfMethod.ContainsKey(MethodName))&lt;br /&gt;{&lt;br /&gt;methodDelegate toExec =&lt;br /&gt;(ListOfMethod[MethodName]);&lt;br /&gt;toExec();&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;throw new&lt;br /&gt;Exception("Not yet Implemented");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-2427759393034354627?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/2427759393034354627/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/04/calling-method-by-name.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/2427759393034354627'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/2427759393034354627'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/04/calling-method-by-name.html' title='Calling A Method By Name'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-9039062075650032695</id><published>2008-04-15T11:21:00.002+08:00</published><updated>2008-04-15T11:35:15.971+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MSSQL Tricks'/><title type='text'>Adding a ROWID() for tables that are linked by UNION ALL</title><content type='html'>ROW_NUMBER() inserts a virtual ROWID  for your query. But how can we create a ROWID for two tables continuously when they are linked using UNION ALL?&lt;br /&gt;&lt;br /&gt;Here is How:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;p&gt;&lt;span style="font-family:courier new;"&gt;(SELECT PartsID AS ItemID, PartsDesc as ItemDesc, ROW_NUMBER()OVER (ORDER&lt;br /&gt;BY PartsID)FROM dbo.Parts)&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new;"&gt;UNION ALL &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new;"&gt;SELECT AssemblyID as ItemID, AssemblyDesc,count(PartsID) +  ROW_NUMBER() OVER (ORDER BY AssemblyID)FROM dbo.[Assembly],dbo.Parts group by&lt;br /&gt;AssemblyID, AssemblyDesc&lt;br /&gt;&lt;/p&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;Here is how it works:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;The first Select Statement inserts a ROW ID for the Parts Table&lt;/li&gt;&lt;li&gt;The Second Select Statement uses two tables (FROM dbo.[Assembly],dbo.Parts). JOINING two tables using From Table1, Table2 multiplies the number of records.&lt;/li&gt;&lt;li&gt;The Second Select Statement was then Grouped By Fields needed for Assembly. This will select the distinct records needed for the query.&lt;/li&gt;&lt;li&gt;count(PartsID) gives the last number of the first query then add it to the ROW_NUMBER() of the second select statement to continue the numbering.&lt;/li&gt;&lt;/ol&gt;Another way to optimize this is to create a view for the UNION ALL statement then treat it as a single table in your ROW_NUMBER statement.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-9039062075650032695?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/9039062075650032695/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/04/adding-rowid-for-tables-that-are-linked.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/9039062075650032695'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/9039062075650032695'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/04/adding-rowid-for-tables-that-are-linked.html' title='Adding a ROWID() for tables that are linked by UNION ALL'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-287749155026419036</id><published>2008-03-31T12:40:00.004+08:00</published><updated>2008-03-31T12:58:33.039+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net and C#'/><title type='text'>Conditionally add a control on Markup during Databinding</title><content type='html'>There are cases that we want to add a control conditionally if the field agrees on some condition. This is common on dataaware controls were we present our data. I come accross with this problem where I need to render a Hyperlink button when HistoryId is not null in the database. We usually write the code to bind controls like as follows:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&amp;lt;asp:LinkButton CommandName = '&amp;lt;%#&lt;br /&gt;string.Format("History{0}",Eval("CustomerHistoryId")) %&amp;gt;' runat= "server"&lt;br /&gt;OnClick= "ViewCustomerHistory"&amp;gt; View ... &amp;lt;/asp:LinkButton&amp;gt; &lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;The following code above will just add linkbutton controls on all records fetch, but this is not the desired output. What I did is to use tertiary operator and set the style to none if HistoryId is null. The code below shows how I did it:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&amp;lt;asp:LinkButton CommandName = '&amp;lt;%#&lt;br /&gt;string.Format("History{0}",Eval("CustomerHistoryId")) %&amp;gt;' runat= "server"&lt;br /&gt;Style ='&amp;lt;%# Eval("CustomerHistoryId").ToString() == "" ? "Display:None"&lt;br /&gt;: "Display:Inline"%&amp;gt;'&lt;br /&gt;OnClick= "ViewCustomerHistory"&amp;gt; View ...&lt;br /&gt;&amp;lt;/asp:LinkButton&amp;gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-287749155026419036?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/287749155026419036/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/conditionally-add-control-on-markup.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/287749155026419036'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/287749155026419036'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/conditionally-add-control-on-markup.html' title='Conditionally add a control on Markup during Databinding'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-7146588039340901640</id><published>2008-03-18T18:31:00.002+08:00</published><updated>2008-03-18T19:03:34.600+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Client Side Programming'/><title type='text'>using JSON in C#.Net</title><content type='html'>I never thought that my objects can be accessed in javascript until I discover JSON. JSON or Javascript Object Notation is a simple data transformation from your serverside objects to clientside scripting.&lt;br /&gt;A string like&lt;br /&gt;&lt;blockquote&gt;'person = {"firstName": "Brett", "lastName":"McLaughlin", "email":&lt;br /&gt;"brett@newInstance.com" } ' &lt;/blockquote&gt;&lt;br /&gt;can be deserialized into JSON object using eval. Then can be accessed as simple as person.firstName. Below is a sample javascript code:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;var myJSON = 'person = {"firstName": "Brett", "lastName":"McLaughlin",&lt;br /&gt;"email": "brett@newInstance.com" } ' ;&lt;br /&gt;eval(myJSON);&lt;br /&gt;alert(person.firsName + ' ' + person.lastName + ', ' + person.email);&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;the code above will give a pop-up message saying:&lt;br /&gt;&lt;blockquote&gt;Brett McLaughlin, brett@newInstance.com&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Now how can we create a JSON object in C#.net and be able to pass it on clientside? Here is the procedure:&lt;br /&gt;&lt;br /&gt;1. Create a struct to be serialized as JSON:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public struct person&lt;br /&gt;{&lt;br /&gt;    public string firstName;&lt;br /&gt;    public string lastName;&lt;br /&gt;    public string email;&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;2. Create a method that will return a serialized JSON object&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public string SerializedJSON(object toSerialize, string className)&lt;br /&gt;{&lt;br /&gt;System.Web.Script.Serialization.JavaScriptSerializer jss;&lt;br /&gt;jss = new System.Web.Script.Serialization.JavaScriptSerializer();&lt;br /&gt;objectSystem.Text.StringBuilder sbControls = new&lt;br /&gt;System.Text.StringBuilder();&lt;br /&gt;jss.Serialize(toSerialize, sbControls);&lt;br /&gt;return className + "=" + sbControls.ToString();&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;3. then register the clientside method to call with parameter as JSON serialized string. This may be an attributes of controls event or a a method call on clientside&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;//as attribute&lt;br /&gt;string serialized = SerializedJSON(person, "person");&lt;br /&gt;button1.Attributes.add("onClick",&lt;br /&gt;"parseJSON('"+ serialized +"')");&lt;br /&gt;//as method call on serverside&lt;br /&gt;&lt;br /&gt;ScriptManager.RegisterClientScriptBlock(this,this.GetType(),&lt;br /&gt;"JS&lt;br /&gt;Method Call","parseJSON('"+ serialized +"')", true);&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;4. Now with those server side code, here is how we do the clientside:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;function parseJSON(serializedJSON)&lt;br /&gt;{&lt;br /&gt;  eval(serializedJSON);&lt;br /&gt;  alert(person.firsName + ' ' + person.lastName + ', ' +&lt;br /&gt;person.email);&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;You can even use JSON on array of objects and be able to call it by index on clientside like&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;person[0].firstName;&lt;br /&gt;or&lt;br /&gt;person[1].firstName;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;I usually use list&amp;lt;object&amp;gt; then serialize it to JSON. And there are many things to explore on JSON and that is what I'm doing right now! Thanks JSON!&lt;br /&gt;&lt;br /&gt;links: &lt;a href="http://www-128.ibm.com/developerworks/web/library/wa-ajaxintro10/"&gt;http://www-128.ibm.com/developerworks/web/library/wa-ajaxintro10/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-7146588039340901640?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/7146588039340901640/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/using-json-in-cnet.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/7146588039340901640'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/7146588039340901640'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/using-json-in-cnet.html' title='using JSON in C#.Net'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-8780159224356122305</id><published>2008-03-11T09:44:00.006+08:00</published><updated>2008-03-12T09:12:38.261+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Client Side Programming'/><title type='text'>Adding Javascript file programmatically in C#</title><content type='html'>Just got it from ASP.Net Forum and found it very useful for me. Thanks to NC01!!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;string resourceName = "YourJavaScriptFile.js";&lt;br /&gt;if ( !this.Page.IsClientScriptBlockRegistered(resourceName) )&lt;br /&gt;{&lt;br /&gt;// If the file is on the server root:&lt;br /&gt;// Ex: &lt;/span&gt;&lt;a href="http://localhost/YourJavaScriptFile.js"&gt;&lt;span style="font-family:courier new;"&gt;http://localhost/YourJavaScriptFile.js&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;string filePath = System.Web.HttpContext.Current.Request.Url. GetLeftPart( UriPartial.Authority) + "\\" + resourceName;&lt;br /&gt;// If the file is on the app virtual root:&lt;br /&gt;// Ex: C:/Inetpub/wwwroot/Test/YourJavaScriptFile.js&lt;br /&gt;string filePath = System.AppDomain.CurrentDomain.BaseDirectory + resourceName;&lt;br /&gt;// If the file is in a sub-folder inside of the app virtual root:&lt;br /&gt;// Ex: C:/Inetpub/wwwroot/Test/ScriptFiles/YourJavaScriptFile.js&lt;br /&gt;string filePath = &lt;strong&gt;System.AppDomain.CurrentDomain.BaseDirectory&lt;/strong&gt; + "ScriptFiles/" + resourceName;&lt;br /&gt;string scriptText = string.Format( System.Globalization.CultureInfo.InvariantCulture, "\n&amp;lt;script type='text/JavaScript' src='{0}'&amp;gt;&amp;lt;/script&amp;gt;\n", filePath);&lt;br /&gt;this.Page.RegisterClientScriptBlock(resourceName, scriptText);&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Note that RegisterOnSubmitStatement, RegisterStartupScript, RegisterClientScriptBlock, etc have changed since version 1.1 and you will get a compiler warning with the above. See &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.aspx"&gt;http://msdn2.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.aspx&lt;/a&gt; for more info.&lt;br /&gt;&lt;br /&gt;I just highlighted the property of getting the BaseURL,&lt;strong&gt; System.AppDomain.CurrentDomain.BaseDirectory &lt;/strong&gt;, i've been looking for it before and finally I got an answer. What I do before is put my baseURL in web.Config, but everytime I deploy it on different test site I have to change the value on web.config before publishing.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-8780159224356122305?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/8780159224356122305/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/adding-javascript-file-programmatically.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/8780159224356122305'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/8780159224356122305'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/adding-javascript-file-programmatically.html' title='Adding Javascript file programmatically in C#'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-3923329839514941518</id><published>2008-03-10T12:01:00.003+08:00</published><updated>2008-03-10T12:10:31.943+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MSSQL Tricks'/><title type='text'>Selecting specific Row and Size in a record using ROW_NUMBER()</title><content type='html'>&lt;span&gt;Sometime we want to select row that is between a record like for example record 10 to 20. We cannot achieve that by using TOP for it will just get the records starting from top. We can write it like this:&lt;/span&gt;&lt;br /&gt;&lt;span&gt;SELECT TOP 20 * FROM TABLE1 WHERE FIELDID NOT IN (SELECT TOP 10 FIELDID FROM TABLE1)&lt;/span&gt;&lt;br /&gt;&lt;span&gt;But performance wise this is not advisable. I recommend using ROW_NUMBER() OVER function in MSSQL to assign ROWID from the table then selecting the ROW in where clause. Here is the syntax below:&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt; SELECT * FROM ( SELECT *, ROW_NUMBER() OVER  (ORDER BY OrderField) as row FROM Table1) a WHERE row &gt; (@RecordNo-1) and row &lt;= (@RecordNo + @RecordSize-1)&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;where:&lt;/span&gt;&lt;br /&gt;&lt;span&gt;@RecordNo is the starting row&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;@RecordSize is the no of rows you want to retrieve starting from @RecordNo&lt;/span&gt;&lt;br /&gt;&lt;span&gt;OrderField is the order you want for the record before extraction&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;So to select records 10 to 20 you write it as:&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt; SELECT * FROM ( SELECT *, ROW_NUMBER() OVER  (ORDER BY OrderField) as row FROM Table1) a WHERE row &gt; (9) and row &lt;= (19)&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-3923329839514941518?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/3923329839514941518/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/selecting-specific-row-and-size-in.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/3923329839514941518'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/3923329839514941518'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/selecting-specific-row-and-size-in.html' title='Selecting specific Row and Size in a record using ROW_NUMBER()'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-8946920345670893214</id><published>2008-03-08T23:22:00.003+08:00</published><updated>2008-03-08T23:31:38.399+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MSSQL Tricks'/><title type='text'>Adding triggers for your Table</title><content type='html'>Triggers are very useful specially on registering audits on changes on tables.&lt;br /&gt;Triggers has INSERTED and DELETED object that can be used to get the activity&lt;br /&gt;made on the table and be able to save it on your audit tables.&lt;br /&gt;These objects has the same schema as your table so you can join it with other table to get other information you needed&lt;br /&gt;&lt;br /&gt;Below is the syntax in adding trigger on your table and how to save it on your audit.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;CREATE TRIGGER [Trigger_all] ON [dbo].[SampleTable]&lt;br /&gt;For INSERT, UPDATE, DELETE&lt;br /&gt;AS&lt;br /&gt;IF EXISTS(SELECT * FROM INSERTED) AND EXISTS(SELECT * FROM DELETED)&lt;br /&gt;BEGIN&lt;br /&gt;--procedure for Update&lt;br /&gt;INSERT INTO SampleTable_Audit VALUES(SELECT *, 'EDITTED', timestamp() FROM DELETED)&lt;br /&gt;END&lt;br /&gt;ELSE IF EXISTS(SELECT * FROM INSERTED)&lt;br /&gt;BEGIN&lt;br /&gt;--Procedure for insert&lt;br /&gt;INSERT INTO SampleTable_Audit VALUES(SELECT *, 'Inserted', timestamp() FROM INSERTED)&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;ELSE IF EXISTS(SELECT * FROM DELETED)&lt;br /&gt;BEGIN&lt;br /&gt;--Procedure for delete&lt;br /&gt;INSERT INTO SampleTable_Audit VALUES(SELECT *, 'EDITTED', timestamp() FROM DELETED)&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-8946920345670893214?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/8946920345670893214/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/adding-triggers-for-your-table.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/8946920345670893214'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/8946920345670893214'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/adding-triggers-for-your-table.html' title='Adding triggers for your Table'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-5539625518529797804</id><published>2008-03-08T19:04:00.008+08:00</published><updated>2008-03-18T22:12:11.988+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Client Side Programming'/><title type='text'>Calling Server Side Method with postback in C#</title><content type='html'>I've been researching for how to call server side methods over the internet but has been frustrated for all I searched was calling server side method without postback using pagemethods or using the ICallBackEventHandler that works like webservice calls in AJAX. I've been pondering time to solve this and found a solutions for myself.&lt;br /&gt;&lt;br /&gt;Here is how I did it:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Create a linkbutton on design and write an event for this. This event will be called on client side by some javascript function.&lt;/li&gt;&lt;li&gt;Register the Server Side Function by using the following:&lt;/li&gt;&lt;/ul&gt;&lt;blockquote&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;StringBuilder jscript = new StringBuilder();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;jsscript.append("function callServerEvent(){");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;jsscript.append(ClientScript.GetPostBackEventReference (LinkButton1, "") + ";}");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;RegisterClientScriptBlock("call server", jsscript.ToString());&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;ul&gt;&lt;li&gt;Do this on Page_Load event, then you can now call callServerEvent() from javascript will do a post back and update controls.&lt;/li&gt;&lt;li&gt;To hide the control on rendering the page set the display:none on LinkButon's style.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;I usually use this in calling server&lt;br /&gt;side function to update controls inside my updatepanel. Using Pagemethods are used for calling static methods and using ICallBackEventHandler is for calling serverside method but with no postback at all.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-5539625518529797804?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/5539625518529797804/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/calling-server-side-method-with.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/5539625518529797804'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/5539625518529797804'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/calling-server-side-method-with.html' title='Calling Server Side Method with postback in C#'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-728138556224950417</id><published>2008-03-08T17:55:00.003+08:00</published><updated>2008-03-08T18:52:06.264+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MSSQL Tricks'/><title type='text'>Selecting the last record entered on audit trail for each Item</title><content type='html'>Here is another trick I love and was amazed of what I have achieved!&lt;br /&gt;Audit trail accumulates all activities happened on the system or movements happened on the item. It is not that easy to extract from the audit trail the last movement of all the items, unless you individually query on each item and get the max date then transfer it to another table, a temporary maybe, then go to the next item and repeat the process until you have the last item. But I found a way to query it on just a single query string:&lt;br /&gt;&lt;br /&gt;SELECT A.ProductID, B.Description,&lt;br /&gt;LTRIM(RIGHT(MAX(CONVERT(VARCHAR(19), A.AuditTime, 120) +&lt;br /&gt;RIGHT(REPLICATE(' ',100) + Activity,100)),100)) AS LastActivity FROM AuditTrail A INNER JOIN Products B ON A.ProductID= B.ProductID GROUP BY A.ProductID, B.Description&lt;br /&gt;&lt;br /&gt;Here is how this works:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Convert the Audit Time to YYYY-MM-DD HH:NN:SS format, this will ensure the order of activities according to time it was written.&lt;/li&gt;&lt;li&gt;RIGHT(REPLICATE(' ',100) + Activity,100)) This will put leading spaces on activity to make the string a 100 character. eg. '10 items sold' will become '                     10 items sold' with 87 leading spaces.&lt;/li&gt;&lt;li&gt;Concatenate the 19 character datetime to the 100 character Activity making it a sum of 119 characters&lt;/li&gt;&lt;li&gt;Get the MAX value of the 119 character field that we have created. This will get the Max value we want since it will be alphabetically arranged.&lt;/li&gt;&lt;li&gt;Now its time to remove the date and time that we don't want to appear then trim again the leading spaces we added. this is the function of LTRIM(RIGHT( ---,100)) where the function right gets the 100 character activity we created ant LTRIM removes leading spaces.&lt;/li&gt;&lt;/ol&gt;Now thats it. We got the Activity of the last movement for each product.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-728138556224950417?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/728138556224950417/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/selecting-last-record-entered-on-audit.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/728138556224950417'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/728138556224950417'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/selecting-last-record-entered-on-audit.html' title='Selecting the last record entered on audit trail for each Item'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-5026393018139116543</id><published>2008-03-08T16:56:00.003+08:00</published><updated>2008-03-08T17:45:21.252+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MSSQL Tricks'/><title type='text'>How to Concatenate a record into a single field</title><content type='html'>Sometimes it is useful to create a column on header that contains a concatenated value of its detail. For example we want to display all available sizes of a specific product like this:&lt;br /&gt;   Product: Coca Cola&lt;br /&gt;   Sizes: 8oz, 12oz, 500ml, 1 Liter, 1.5 Liter&lt;br /&gt;&lt;br /&gt;We can achieve that by joining the details then looping on the detail to write it on a single string. But we can concatenate it using the following:&lt;br /&gt;&lt;br /&gt;CREATE FUNCTION Sizes&lt;br /&gt;(&lt;br /&gt;@ProductID varchar(50)&lt;br /&gt;)&lt;br /&gt;RETURNS varchar(2000)&lt;br /&gt;AS&lt;br /&gt;BEGIN&lt;br /&gt;DECLARE @Sizes varchar(2000)&lt;br /&gt;&lt;br /&gt;SET @Sizes=''&lt;br /&gt;SELECT @Sizes=@Sizes+','+ ProductSizes.Size FROM ProductSizes&lt;br /&gt;WHERE ProductSizes.ProductID=@ProductID&lt;br /&gt;&lt;br /&gt;RETURN @Sizes = RIGHT(@Sizes,LEN(@Sizes)-1)&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;This function returns a concatenated value of sizes according to the ProductID &lt;br /&gt;&lt;br /&gt;so we can write a query like this:&lt;br /&gt;&lt;br /&gt;SELECT ProductID, Description, dbo.Sizes(ProductID) FROM Products&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-5026393018139116543?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/5026393018139116543/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/how-to-concatenate-record-into-single.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/5026393018139116543'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/5026393018139116543'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/how-to-concatenate-record-into-single.html' title='How to Concatenate a record into a single field'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-4543792738284274556</id><published>2008-03-08T16:16:00.003+08:00</published><updated>2008-03-08T16:38:11.710+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MSSQL Tricks'/><title type='text'>Ordering a record according to search followed by the rest of the record</title><content type='html'>When searching from grid, commonly the searched record is left on the grid removing all unsearch record. Sometimes we don't want that style to happen. We want to put the searched item on top of the grid and the rest below it.&lt;br /&gt;Here is a trick to do that:&lt;br /&gt;&lt;br /&gt;SELECT *, '0'+ SearchField as OrderBy FROM Tables WHERE SearchField like '[value]%' &lt;br /&gt;UNION ALL&lt;br /&gt;SELECT *, '1'+ SearchField as OrderBy FROM Tables WHERE SearchField not like '[value]%'  Order By OrderBy&lt;br /&gt;&lt;br /&gt;OR&lt;br /&gt;&lt;br /&gt;SELECT field1, field2, SearchField,CASE WHEN SearchField like '[Value]%' THEN '0' ELSE '1' END ORDER BY 4,SearchField&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-4543792738284274556?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/4543792738284274556/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/ordering-record-according-to-search.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/4543792738284274556'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/4543792738284274556'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/ordering-record-according-to-search.html' title='Ordering a record according to search followed by the rest of the record'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-8933391865127603370</id><published>2008-03-08T03:00:00.001+08:00</published><updated>2008-06-12T10:14:29.904+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Project Accomplished and Involvement'/><title type='text'>HunterWise Project</title><content type='html'>1. HunterWise Comodities Trading&lt;br /&gt;&lt;br /&gt;Type: Web Application&lt;br /&gt;&lt;br /&gt;Tools:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;C#.Net&lt;/li&gt;&lt;li&gt;MSSQL&lt;/li&gt;&lt;li&gt;AJAX&lt;/li&gt;&lt;li&gt;ASP.Net&lt;/li&gt;&lt;/ul&gt;Duration: February 1, 2008 to May 1, 2008 (May be extended upon clients request)&lt;br /&gt;&lt;br /&gt;Client: Hunterwise, USA&lt;br /&gt;&lt;br /&gt;Function:Team Lead / Senior Developer(Software Engineer)&lt;br /&gt;&lt;br /&gt;Company Attached with : &lt;a href="http://www.blastasia.com/"&gt;BlastAsia Inc.&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-8933391865127603370?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/8933391865127603370/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/hunterwise-project.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/8933391865127603370'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/8933391865127603370'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/hunterwise-project.html' title='HunterWise Project'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-894593560967797509</id><published>2008-03-08T02:00:00.000+08:00</published><updated>2008-03-08T13:48:06.138+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Project Accomplished and Involvement'/><title type='text'>BeeLine Project</title><content type='html'>&lt;p&gt;1. BeeLine Invoice Payment System&lt;br /&gt;&lt;br /&gt;Type: WinForm Application&lt;br /&gt;&lt;br /&gt;Tools:&lt;br /&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;C#.Net&lt;/li&gt;&lt;li&gt;MSSQL&lt;/li&gt;&lt;/ul&gt;Duration: January 3, 2008 to January 31, 2008&lt;br /&gt;&lt;br /&gt;Client: BeeLine, Florida&lt;br /&gt;&lt;br /&gt;Function: Database Administration (Software Engineer)&lt;br /&gt;- Optimizations of Stored Procedures and Queries&lt;br /&gt;&lt;br /&gt;Company Attached With: &lt;a href="http://www.blastasia.com/"&gt;BlastAsia Inc.&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-894593560967797509?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/894593560967797509/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/beeline-project.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/894593560967797509'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/894593560967797509'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/beeline-project.html' title='BeeLine Project'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-5567184278331870932</id><published>2008-03-08T01:00:00.000+08:00</published><updated>2008-03-08T13:49:25.790+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Project Accomplished and Involvement'/><title type='text'>TSCERES SQL</title><content type='html'>Description: A Touch Screen Point-of-Sale (POS) System designed for Fast Food Chains and Restaurants&lt;br /&gt;&lt;br /&gt;Type: WinForm Application&lt;br /&gt;&lt;br /&gt;Tools:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Delphi 6&lt;/li&gt;&lt;li&gt;MySQL&lt;/li&gt;&lt;li&gt;MSSQL (For Corporate Accounts)&lt;/li&gt;&lt;li&gt;Crystal Report&lt;/li&gt;&lt;/ul&gt;Duration: April 19, 2007 - January 3, 2008&lt;br /&gt;&lt;br /&gt;Function: Front-End Developer&lt;br /&gt;&lt;br /&gt;Clients :&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Starbucks&lt;/li&gt;&lt;li&gt;YellowCab&lt;/li&gt;&lt;li&gt;Karate Kid&lt;/li&gt;&lt;li&gt;Brent International School Cafeteria&lt;/li&gt;&lt;li&gt;British School Cafeteria&lt;/li&gt;&lt;li&gt;etc.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;Company Attached with: &lt;a href="http://www.jimac-inc.com/"&gt;JIMAC Inc.&lt;/a&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-5567184278331870932?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/5567184278331870932/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/tsceres-sql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/5567184278331870932'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/5567184278331870932'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/tsceres-sql.html' title='TSCERES SQL'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-2268855788465261907</id><published>2008-03-08T00:00:00.000+08:00</published><updated>2008-03-08T13:50:02.621+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Project Accomplished and Involvement'/><title type='text'>SMES POS</title><content type='html'>Description : A System that handles text messages (SMS) and converts it to sales and/or inventory transaction depending on Provided Text Format. A modem is connected to the head office and works as a bridge to accept messages  to be processed from satellite stores.&lt;br /&gt;&lt;br /&gt;Type: WinForm Application&lt;br /&gt;&lt;br /&gt;Tools:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Delphi 6&lt;/li&gt;&lt;li&gt;MySQL&lt;/li&gt;&lt;li&gt;Crystal Report&lt;/li&gt;&lt;/ul&gt;Duration: April 19, 2007 - January 3, 2008&lt;br /&gt;&lt;br /&gt;Function: Front-End Developer&lt;br /&gt;&lt;br /&gt;Clients :&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Hotdog on Stick&lt;/li&gt;&lt;li&gt;Kettle and Corn&lt;/li&gt;&lt;li&gt;Fruit Magic&lt;br /&gt;&lt;/li&gt;&lt;li&gt;etc.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;Company Attached with: &lt;a href="http://www.jimac-inc.com/"&gt;JIMAC Inc.&lt;/a&gt;&lt;span style=""&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-2268855788465261907?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/2268855788465261907/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/smes-pos.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/2268855788465261907'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/2268855788465261907'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/smes-pos.html' title='SMES POS'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-2962517259652669733</id><published>2008-03-07T23:27:00.000+08:00</published><updated>2008-03-08T13:56:58.387+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Project Accomplished and Involvement'/><title type='text'>Student's Form Generator</title><content type='html'>Description:&lt;br /&gt;A complete Computerized Grading System that involves the following modules:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Class Record - Excel Program that computes raw scores entered by teachers and summarizes all component for each grading. Complete averaging from 1st grading to 4th grading&lt;/li&gt;&lt;li&gt;Summary Sheet - Excel Program that summarizes all grades acquired by the student on each subject and computes his final average. It also has a summary of Attendance for each month. It is linked to the Main Database for record keeping.&lt;/li&gt;&lt;li&gt;Registrar Module - Handles all record keeping of students information and grades for the whole curriculum. Can generate forms like Transcript of records, classlists and other forms needed by DepEd (Department of Education). It also has sectioning facilities to assign and trace students sections on each grade/year level.&lt;/li&gt;&lt;/ol&gt;Tools:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Visual Basic 6&lt;/li&gt;&lt;li&gt;MSSQL&lt;/li&gt;&lt;li&gt;MSExcel&lt;/li&gt;&lt;li&gt;Crystal Report&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Duration: May 2004 - May 2005&lt;br /&gt;&lt;br /&gt;Function: Created the whole System Development Life Cycle&lt;br /&gt;&lt;br /&gt;Client: Paco Catholic School&lt;br /&gt;&lt;br /&gt;Company Involve with : &lt;a href="http://www.pacocatholicschool.edu.ph/"&gt;Paco Catholic School&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-2962517259652669733?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/2962517259652669733/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/students-form-generator.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/2962517259652669733'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/2962517259652669733'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/students-form-generator.html' title='Student&apos;s Form Generator'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-5359675558765842380</id><published>2008-03-07T23:00:00.000+08:00</published><updated>2008-03-08T13:59:13.273+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Project Accomplished and Involvement'/><title type='text'>Nice Hotel Cashiering System</title><content type='html'>Description: Hotel Point-of-Sales Accommodation system&lt;br /&gt;&lt;br /&gt;Type : WinForm Application&lt;br /&gt;&lt;br /&gt;Tools:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Visual Basic 6&lt;/li&gt;&lt;li&gt;MSSQL&lt;/li&gt;&lt;li&gt;Crystal report&lt;/li&gt;&lt;/ul&gt;Duration: January 2006 - January 2007&lt;br /&gt;&lt;br /&gt;Involvement: Created the whole System Development Life Cycle (Free Lance)&lt;br /&gt;&lt;br /&gt;Client: Nice Hotel, Philippines&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-5359675558765842380?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/5359675558765842380/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/nice-hotel-cashiering-system.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/5359675558765842380'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/5359675558765842380'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/nice-hotel-cashiering-system.html' title='Nice Hotel Cashiering System'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-4145098286419029062</id><published>2008-03-07T22:00:00.000+08:00</published><updated>2008-03-08T13:59:48.777+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Project Accomplished and Involvement'/><title type='text'>Paco Catholic School's Website</title><content type='html'>Type: Static Website&lt;br /&gt;&lt;br /&gt;Tool:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Front Page&lt;/li&gt;&lt;li&gt;XML&lt;/li&gt;&lt;li&gt;Adobe Photoshop&lt;/li&gt;&lt;li&gt;Macromedia Flash&lt;/li&gt;&lt;/ul&gt;Duration: August 2006 - October 2006&lt;br /&gt;&lt;br /&gt;Client: Paco Catholic School, Manila, Phillipines&lt;br /&gt;&lt;br /&gt;Company involve with: &lt;a href="http://www.pacocatholicschool.edu.ph/"&gt;Paco Catholic School&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-4145098286419029062?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/4145098286419029062/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/paco-catholic-schools-website.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/4145098286419029062'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/4145098286419029062'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/paco-catholic-schools-website.html' title='Paco Catholic School&apos;s Website'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-2354976825007338878</id><published>2008-03-07T21:00:00.000+08:00</published><updated>2008-03-08T14:00:19.864+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Project Accomplished and Involvement'/><title type='text'>Electronic Quiz Bee</title><content type='html'>Description: A Client/Server system, used in a Quiz Bee Programs, that sends question to each team (client) and registers answer back to server to verify answer and accumulate scores.&lt;br /&gt;&lt;br /&gt;Tools:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Visual Basic 6&lt;/li&gt;&lt;li&gt;MSExcel&lt;/li&gt;&lt;/ul&gt;Used in the following Programs:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Paco Catholic School's Young Mind Quiz Whiz&lt;/li&gt;&lt;li&gt;Paco Catholic School's Computer Practical Arts Quiz Bee&lt;/li&gt;&lt;/ul&gt;Company involved with: &lt;a href="http://www.pacocatholicschool.edu.ph/"&gt;Paco Catholic School&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-2354976825007338878?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/2354976825007338878/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/electronic-quiz-bee.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/2354976825007338878'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/2354976825007338878'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/electronic-quiz-bee.html' title='Electronic Quiz Bee'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-2587218986746611304</id><published>2008-03-07T20:00:00.000+08:00</published><updated>2008-03-08T14:02:56.288+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Project Accomplished and Involvement'/><title type='text'>Online Quiz</title><content type='html'>Description: A web based quiz which is used by teachers when giving exams&lt;br /&gt;&lt;br /&gt;Tools:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Visual Basic.Net&lt;/li&gt;&lt;li&gt;MSSQL&lt;/li&gt;&lt;/ul&gt;Client: Paco Catholic School&lt;br /&gt;&lt;br /&gt;Company involve with: Paco Catholic School&lt;br /&gt;&lt;span style=""&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-2587218986746611304?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/2587218986746611304/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/online-quiz.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/2587218986746611304'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/2587218986746611304'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/online-quiz.html' title='Online Quiz'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5679237228171649717.post-2975612308067061396</id><published>2008-03-07T14:53:00.002+08:00</published><updated>2008-03-12T09:15:08.622+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Client Side Programming'/><title type='text'>Opening a new window without toolbars in C#</title><content type='html'>&lt;strong&gt;Here is window.open syntax:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;winRef = window.open( URL, name [ , features [, replace ] ] )&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;The parameters URL, name, features, replace have the following meaning:&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-STYLE: italic"&gt;URL&lt;/span&gt;&lt;br /&gt;String specifying the location of the Web page to be displayed in the new window. If you do not want to specify the location, pass an empty string as the URL (this may be the case when you are going to &lt;a href="http://www.javascripter.net/faq/writingt.htm"&gt;write&lt;/a&gt; some script-generated content to your new window).&lt;br /&gt;&lt;p&gt;&lt;span style="FONT-STYLE: italic"&gt;name&lt;/span&gt;&lt;br /&gt;String specifying the name of the new window. This name can be used in the same constructions as the frame name provided in the frame tag within a frameset . &lt;a href="http://www.blogger.com/page.htm" target="name"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="FONT-STYLE: italic"&gt;features&lt;/span&gt;&lt;br /&gt;An optional string parameter specifying the features of the new window. The features string may contain one or more feature=value pairs separated by commas. &lt;/p&gt;&lt;p&gt;&lt;span style="FONT-STYLE: italic"&gt;replace&lt;/span&gt;&lt;br /&gt;An optional boolean parameter. If true, the new location will replace the current page in the browser's navigation history. Note that some browsers will simply ignore this parameter.&lt;br /&gt;&lt;/p&gt;The following features are available in most browsers:&lt;br /&gt;toolbar=0/1&lt;br /&gt;-Specifies whether to display the toolbar in the new window.&lt;br /&gt;location=0/1&lt;br /&gt;-Specifies whether to display the address line in the new window.&lt;br /&gt;directories=0/1&lt;br /&gt;-Specifies whether to display the Netscape directory buttons.&lt;br /&gt;status=0/1&lt;br /&gt;-Specifies whether to display the browser status bar.&lt;br /&gt;menubar=0/1&lt;br /&gt;-Specifies whether to display the browser menu bar.&lt;br /&gt;scrollbars=0/1&lt;br /&gt;-Specifies whether the new window should have scrollbars.&lt;br /&gt;resizable=0/1&lt;br /&gt;-Specifies whether the new window is resizable.&lt;br /&gt;width=pixels&lt;br /&gt;-Specifies the width of the new window.&lt;br /&gt;height=pixels&lt;br /&gt;-Specifies the height of the new window.&lt;br /&gt;top=pixels&lt;br /&gt;-Specifies the Y coordinate of the top left corner of the new window. (Not supported in version 3 browsers.)&lt;br /&gt;left=pixels&lt;br /&gt;-Specifies the X coordinate of the top left corner of the new window. (Not supported in version 3 browsers.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Calling the window.open on serverside:&lt;br /&gt;&lt;pre width="60"&gt;&lt;br /&gt;RegisterClientScriptBlock("Open Window","&amp;lt;script&amp;gt; window.open('sample.aspx','sample','toolbar=No, width=300, height=190, resizable=No, top=400, left=600')&amp;lt;/script&amp;gt;");&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;To Create a page on the fly:&lt;br /&gt;&lt;pre width="60"&gt;&lt;br /&gt;StringBuilder jscript = new StringBuilder();&lt;br /&gt;jscript.append("&amp;lt;script&amp;gt;");&lt;br /&gt;jscript.append("win=window.open('','login',");&lt;br /&gt;jscript.append("'toolbar=No, width=300, height=190, resizable=No, top=400, left=600');");&lt;br /&gt;jscript.append("win.response.write('&amp;lt;BODY&amp;gt;');");&lt;br /&gt;jscript.append("win.response.write('this page is created on the fly!');");&lt;br /&gt;jscript.append("win.response.write('&amp;lt;/BODY&amp;gt;');");&lt;br /&gt;jscript.append("&amp;lt;/script&amp;gt;");&lt;br /&gt;RegisterClientScriptBlock("Open Window", jsscript.ToString());&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;reference: &lt;a href="http://www.javascripter.net/faq/openinga.htm"&gt;http://www.javascripter.net/faq/openinga.htm&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5679237228171649717-2975612308067061396?l=learnitfromvince.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnitfromvince.blogspot.com/feeds/2975612308067061396/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/opening-new-window-without-toolbars.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/2975612308067061396'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5679237228171649717/posts/default/2975612308067061396'/><link rel='alternate' type='text/html' href='http://learnitfromvince.blogspot.com/2008/03/opening-new-window-without-toolbars.html' title='Opening a new window without toolbars in C#'/><author><name>Vincent Calaor</name><uri>http://www.blogger.com/profile/06585703511290269339</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>
