<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Fazle Rokib&#039;s Blog</title>
	<atom:link href="http://fazlerokib.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://fazlerokib.wordpress.com</link>
	<description></description>
	<lastBuildDate>Thu, 22 Apr 2010 05:00:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='fazlerokib.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/c66de94f48fd80f30eae857ecf3afa0e?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Fazle Rokib&#039;s Blog</title>
		<link>http://fazlerokib.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://fazlerokib.wordpress.com/osd.xml" title="Fazle Rokib&#039;s Blog" />
	<atom:link rel='hub' href='http://fazlerokib.wordpress.com/?pushpress=hub'/>
		<item>
		<title>SQL Server : Recompiling /Refreshing Dependent Objects</title>
		<link>http://fazlerokib.wordpress.com/2010/04/22/sql-server-recompiling-refreshing-dependent-objects/</link>
		<comments>http://fazlerokib.wordpress.com/2010/04/22/sql-server-recompiling-refreshing-dependent-objects/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 04:57:54 +0000</pubDate>
		<dc:creator>Fazle Rokib</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fazlerokib.wordpress.com/2010/04/22/sql-server-recompiling-refreshing-dependent-objects/</guid>
		<description><![CDATA[Some times we add or drop column to/from a table or view. When the change hits the production we suddenly find out that a lot of Views or Procedures just became invalid and would return wrong result. As for example, the new field that was added is not available in the view that uses select [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fazlerokib.wordpress.com&amp;blog=8927015&amp;post=150&amp;subd=fazlerokib&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Some times we add or drop column to/from a table or view. When the change hits the production we suddenly find out that a lot of Views or Procedures just became invalid and would return wrong result. As for example, the new field that was added is not available in the view that uses select * . </p>
<p>Here is a small stored procedure that you can call after each Alter Table or Alter View statement to make sure that all dependent Views are refreshed and all stored procedures are recompiled.&#160; Basically it finds all dependent objects using build-in stored procedure sp_depends @objectName that takes the object name as input and returns a table of dependent objects that contains two columns 1) Object Name and 2) Object Type. We just go through the result and execute one of the built in stored procs 1) If the object type is view then we call sp_RefreshView @depObjName&#160; 2) Otherwise we call sp_Recompile @depObjName.</p>
<p>&#160;</p>
<blockquote><p>Alter Procedure sp_RefreshDependentObjects     <br />(      <br />@ObjectName as Varchar(100)      <br />)      <br />As </p>
<p>CREATE TABLE #DepObjs(     <br />ObjectName Varchar(100),      <br />ObjectType Varchar(30) ) </p>
<p>Declare @objName Varchar(100), @objType Varchar(30) </p>
<p>Insert Into #DepObjs     <br /> EXEC sp_depends @ObjectName </p>
<p>declare objCursor CURSOR FOR     <br />Select * From #DepObjs </p>
<p>Open objCursor </p>
<p>Fetch Next From objCursor INTO&#160;&#160; @objName, @objType     <br />WHILE @@FETCH_STATUS = 0      <br />BEGIN      <br />&#160;&#160;&#160; IF @objType=&#8217;view&#8217;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Exec sp_RefreshView @objName       <br />&#160;&#160;&#160; ELSE      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Exec sp_recompile @objName      <br />&#160;&#160;&#160; FETCH NEXT FROM objCursor INTO @objName, @objType      <br />END </p>
<p>Drop Table #DepObjs</p>
</blockquote>
<br />Filed under: <a href='http://fazlerokib.wordpress.com/category/uncategorized/'>Uncategorized</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fazlerokib.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fazlerokib.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fazlerokib.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fazlerokib.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fazlerokib.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fazlerokib.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fazlerokib.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fazlerokib.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fazlerokib.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fazlerokib.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fazlerokib.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fazlerokib.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fazlerokib.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fazlerokib.wordpress.com/150/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fazlerokib.wordpress.com&amp;blog=8927015&amp;post=150&amp;subd=fazlerokib&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fazlerokib.wordpress.com/2010/04/22/sql-server-recompiling-refreshing-dependent-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/854126705b2ba33900098b8adfb52538?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rokib</media:title>
		</media:content>
	</item>
		<item>
		<title>Finding Similar Products</title>
		<link>http://fazlerokib.wordpress.com/2009/10/07/finding-similar-products/</link>
		<comments>http://fazlerokib.wordpress.com/2009/10/07/finding-similar-products/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 17:45:52 +0000</pubDate>
		<dc:creator>Fazle Rokib</dc:creator>
				<category><![CDATA[Self Join]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://fazlerokib.wordpress.com/?p=93</guid>
		<description><![CDATA[Some times we are required to give a link on a product page to show similar products. The actual sql query that is used to make a list of such products is very simple. You have to make a decision on which fields of the product you want to use to find the similar products. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fazlerokib.wordpress.com&amp;blog=8927015&amp;post=93&amp;subd=fazlerokib&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Some times we are required to give a link on a product page to show similar products. The actual sql query that is used to make a list of such products is very simple. You have to make a decision on which fields of the product you want to use to find the similar products. It can be Category, Manufacturer, similar sounding product name and / or some statistical field that you keep about this product in a different table or in the same table. This part that is basically a where condition can just be a matter of choice for you. Lets assume that two product are similar if they have the same Category or Same UserRating or Their names sound similar.</p>
<p>We use self join to make the actual query.</p>
<p>Say for example, if you have a table as follows:</p>
<p><strong>Product</strong></p>
<p>&#8212;&#8212;&#8211;</p>
<p>ProductID</p>
<p>ProductName</p>
<p>CategoryID</p>
<p>UserRating</p>
<p><strong>Now lets make the query:</strong></p>
<blockquote>
<p style="text-align:left;">Select p2.ProductID, p2.ProductName, p2.Price, p2.UserRating</p>
<p style="text-align:left;">From Product  as  p1Inner Join Product  as  p2</p>
<p style="text-align:left;">ON  p2.CategoryID=p1.CategoryID</p>
<p style="text-align:left;">OR  p2.UserRating = p1.UserRating</p>
<p style="text-align:left;">OR Soundex(p2.ProductName)= Soundex(p1.ProductName)</p>
<p style="text-align:left;">Where</p>
<p style="text-align:left;">p1.ProductID = @myProductID</p>
</blockquote>
<br />Posted in Self Join, SQL  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fazlerokib.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fazlerokib.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fazlerokib.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fazlerokib.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fazlerokib.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fazlerokib.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fazlerokib.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fazlerokib.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fazlerokib.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fazlerokib.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fazlerokib.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fazlerokib.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fazlerokib.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fazlerokib.wordpress.com/93/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fazlerokib.wordpress.com&amp;blog=8927015&amp;post=93&amp;subd=fazlerokib&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fazlerokib.wordpress.com/2009/10/07/finding-similar-products/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/854126705b2ba33900098b8adfb52538?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rokib</media:title>
		</media:content>
	</item>
		<item>
		<title>Effective Price</title>
		<link>http://fazlerokib.wordpress.com/2009/08/08/effective-price-calculation/</link>
		<comments>http://fazlerokib.wordpress.com/2009/08/08/effective-price-calculation/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 20:29:19 +0000</pubDate>
		<dc:creator>Fazle Rokib</dc:creator>
				<category><![CDATA[Self Join]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://fazlerokib.wordpress.com/?p=7</guid>
		<description><![CDATA[Effective Price Code Example:  (SQL Server / MySQL / Oracle) SQL Server: 1. 1: CREATE View v_EffectivePrice 2: As 3: Select a.EffectiveDate as StartDate , 4: ( 5: Select DateAdd(day,-1,ISNULL(Min(b.EffectiveDate), DateAdd( 6: year,50,GETDATE() ) ) ) 7: From EffectivePrice b Where b.ProductID=a.ProductID And b.EffectiveDate &#62; 8: a.EffectiveDate 9: ) As EndDate, a.ProductID, a.EffectivePrice 10: From [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fazlerokib.wordpress.com&amp;blog=8927015&amp;post=7&amp;subd=fazlerokib&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div>
<table border="0" cellspacing="0" cellpadding="3">
<tbody>
<tr>
<td style="text-align:left;" width="80%"><strong><span style="font-size:medium;">Effective Price</span> </strong></td>
</tr>
<tr>
<td width="80%">
<div style="text-align:left;"><strong><span style="font-size:small;">Code Example:  (<span style="background-color:#ffff00;">SQL Server</span> / MySQL / Oracle)</span></strong></div>
<p><span style="font-size:small;"><strong><br />
SQL Server:</strong></span></p>
<p>1.</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" class="csharpcode">
<pre class="alt"></pre>
<p><!--CRLF--></p>
<pre class="alteven"></pre>
<p><!--CRLF--></p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum1" style="color:#606060;">   1:</span> <span style="color:#0000ff;">CREATE</span> <span style="color:#0000ff;">View</span> v_EffectivePrice</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum2" style="color:#606060;">   2:</span> <span style="color:#0000ff;">As</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum3" style="color:#606060;">   3:</span> <span style="color:#0000ff;">Select</span> a.EffectiveDate <span style="color:#0000ff;">as</span> StartDate ,</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum4" style="color:#606060;">   4:</span> (</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum5" style="color:#606060;">   5:</span> <span style="color:#0000ff;">Select</span> DateAdd(<span style="color:#0000ff;">day</span>,-1,ISNULL(<span style="color:#0000ff;">Min</span>(b.EffectiveDate), DateAdd(</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum6" style="color:#606060;">   6:</span> <span style="color:#0000ff;">year</span>,50,GETDATE() ) ) )</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum7" style="color:#606060;">   7:</span> <span style="color:#0000ff;">From</span> EffectivePrice b <span style="color:#0000ff;">Where</span> b.ProductID=a.ProductID <span style="color:#0000ff;">And</span> b.EffectiveDate &gt;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum8" style="color:#606060;">   8:</span> a.EffectiveDate</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum9" style="color:#606060;">   9:</span> ) <span style="color:#0000ff;">As</span> EndDate, a.ProductID, a.EffectivePrice</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum10" style="color:#606060;">  10:</span> <span style="color:#0000ff;">From</span> EffectivePrice <span style="color:#0000ff;">As</span> a</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum11" style="color:#606060;">  11:</span> 2. <span style="color:#0000ff;">Use</span> the <span style="color:#0000ff;">view</span> <span style="color:#0000ff;">to</span> <span style="color:#0000ff;">get</span> price <span style="color:#0000ff;">on</span> <span style="color:#0000ff;">any</span> <span style="color:#0000ff;">date</span> /<span style="color:#0000ff;">time</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum12" style="color:#606060;">  12:</span> <span style="color:#0000ff;">Select</span> ep.ProductID, ep.Price <span style="color:#0000ff;">from</span> v_EffectivePrice <span style="color:#0000ff;">as</span> ep</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum13" style="color:#606060;">  13:</span> <span style="color:#0000ff;">Where</span> @mydate</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum14" style="color:#606060;">  14:</span> <span style="color:#0000ff;">Between</span> ep.StartDate <span style="color:#0000ff;">And</span> ep.EndDate <span style="color:#0000ff;">And</span> ep.ProductID=@myProductID</pre>
<p><!--CRLF--></p>
</div>
</div>
<p><!--CRLF--></p>
</div>
</div>
<div style="text-align:left;"><strong><span style="font-size:small;"></p>
<p></span></strong></div>
</td>
<td valign="top">
<div style="text-align:left;"><strong><span style="font-size:small;">Explanation</span></strong></div>
<p><strong></p>
<p><span style="font-size:small;">Use case: </span></strong></p>
<p>Store web-fronts need this capability.</p>
<p><span style="font-size:small;"></p>
<p><strong>Requirement:</strong></span></p>
<blockquote><p>You want the price to be effective from certain date/time and you want to set it up in advance. As for example, you want a promotional price to be effective in a certain date/time .</p></blockquote>
<p><strong>Table Design:</strong></p>
<p>EffectivePrice</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p><span style="font-weight:bold;">ProductID</span> int</p>
<p><span style="font-weight:bold;">EffectiveDate </span>DateTime</p>
<p>Price              Money</p>
<p>Primary Key (ProductID, EffectiveDate)</p>
<p><span style="font-size:small;"><strong>Technology Highlight:</strong></span> <span style="background-color:#ffff00;">Self Join </span></td>
</tr>
</tbody>
</table>
</div>
<br />Posted in Self Join, SQL  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fazlerokib.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fazlerokib.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fazlerokib.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fazlerokib.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fazlerokib.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fazlerokib.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fazlerokib.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fazlerokib.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fazlerokib.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fazlerokib.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fazlerokib.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fazlerokib.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fazlerokib.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fazlerokib.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fazlerokib.wordpress.com&amp;blog=8927015&amp;post=7&amp;subd=fazlerokib&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fazlerokib.wordpress.com/2009/08/08/effective-price-calculation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/854126705b2ba33900098b8adfb52538?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rokib</media:title>
		</media:content>
	</item>
	</channel>
</rss>
