<?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/"
	>

<channel>
	<title>Made2Mentor</title>
	<atom:link href="http://www.made2mentor.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.made2mentor.com</link>
	<description>My Path Toward Business Intelligence Mastery</description>
	<lastBuildDate>Wed, 17 Mar 2010 13:00:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Purging Pointless Permission Records Provides Performance Payoff</title>
		<link>http://www.made2mentor.com/2010/03/purging-pointless-permission-records-provides-performance-payoff/</link>
		<comments>http://www.made2mentor.com/2010/03/purging-pointless-permission-records-provides-performance-payoff/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 13:00:52 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Made2Manage]]></category>

		<guid isPermaLink="false">http://www.made2mentor.com/?p=3179</guid>
		<description><![CDATA[
			
				
			
		
<p>This article is obviously a follow up to Permission Problems post I published previously. The other day I was using the User Permissions Report (RPUSER), I noticed something amiss.  I had recently deleted a couple of educational and testing companies which many people used. However, like many other areas of M2M, the records are [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.made2mentor.com%2F2010%2F03%2Fpurging-pointless-permission-records-provides-performance-payoff%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.made2mentor.com%2F2010%2F03%2Fpurging-pointless-permission-records-provides-performance-payoff%2F&amp;source=Made2Mentor&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>This article is obviously a follow up to <a href="http://www.made2mentor.com/2009/12/profuse-perpetual-pointless-pernicious-permission-problems/">Permission Problems</a> post I published previously. The other day I was using the User Permissions Report (RPUSER), I noticed something amiss.  I had recently deleted a couple of educational and testing companies which many people used. However, like <a href="http://www.made2mentor.com/2010/02/let%E2%80%99s-play-the-orphaned-records-game/">many other areas of M2M</a>, the records are not properly deleted and cleaned up. </p>
<p>This becomes a problem when you run the User Permissions Report because it lists every single company, every user associated with it, and the exhaustive list of screens with their permissions. It includes every user and company even after deleting them from within M2M. This slows down the report and clutters the results. </p>
<p>Below is the code one could use in Visual FoxPro to clean this up. Please read my <a href="http://www.made2mentor.com/2010/03/standard-disclaimer/">Standard Disclaimer</a> before trying any code from this site. I’m going to stress this several times because of an issue that came up as a result of the orphaned records post. Stay tuned for details. </p>
<blockquote><p>
<strong>Set excl on</strong> – You must have exclusive access to perform this.<br />
<strong>OPEN DATABASE X:\m2mdata\util\util.dbc</strong> – Replace X with the network drive letter assigned to M2M.<br />
<strong>Use utacc</strong><br />
<strong>Copy to utaccOLD</strong><br />
<strong>Brow for fccompid = ‘XX’ </strong>&#8211; where XX is the number of the M2M Company for which you intend to remove users and rights. Make sure you do NOT do so on your live M2M Company. This will show the records that will be deleted.<br />
<strong>Delete for fccompid = ‘XX’</strong> – Remember, don’t use this on your live data.<br />
<strong>Pack</strong> – This will make the deletion permanent.<br />
<strong>Close all<br />
Quit.</strong>
</p></blockquote>
<p>Please remember to test this on a test server, and if you feel uncomfortable contact M2M Support or a qualified consultant such as myself for help. </p>
<p>Any questions? </p>
]]></content:encoded>
			<wfw:commentRss>http://www.made2mentor.com/2010/03/purging-pointless-permission-records-provides-performance-payoff/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Honey, I Shrunk my Project File</title>
		<link>http://www.made2mentor.com/2010/03/honey-i-shrunk-my-project-file/</link>
		<comments>http://www.made2mentor.com/2010/03/honey-i-shrunk-my-project-file/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 14:00:33 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Made2Manage]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[Pop Culture]]></category>

		<guid isPermaLink="false">http://www.made2mentor.com/?p=1581</guid>
		<description><![CDATA[
			
				
			
		
<p>I&#8217;ve mentioned in the past how difficult M2M&#8217;s flavor of VBA is to use. One problem that I haven&#8217;t touched on is the problem of VBA file corruption. </p>
M2M VBA File Corruption? What exactly are you talking about?
<p>When I talk about the VBA file, I am referring to the M2VEvents.prj file.  This is the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.made2mentor.com%2F2010%2F03%2Fhoney-i-shrunk-my-project-file%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.made2mentor.com%2F2010%2F03%2Fhoney-i-shrunk-my-project-file%2F&amp;source=Made2Mentor&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://www.made2mentor.com/wp-content/uploads/2010/03/shrunk_the_kids_tiny.jpg"><img src="http://www.made2mentor.com/wp-content/uploads/2010/03/shrunk_the_kids_tiny.jpg" alt="" title="shrunk_the_kids_tiny" width="300" height="197" class="alignleft size-full wp-image-3169" /></a>I&#8217;ve <a href="http://www.made2mentor.com/2008/10/dark-helmets-approach-to-project-management/">mentioned in the past</a> how difficult M2M&#8217;s flavor of VBA is to use. One problem that I haven&#8217;t touched on is the problem of VBA file corruption. </p>
<h3>M2M VBA File Corruption? What exactly are you talking about?</h3>
<p>When I talk about the VBA file, I am referring to the M2VEvents.prj file.  This is the file which holds all of your VBA code including forms and modules. Every time you edit that file, it grows in size. There is no way that I know of to shrink it. If all of the modules are deleted, the file still doesn&#8217;t decrease in size. </p>
<h3>Why should I care about how large the file is?</h3>
<p>The problem is that over time these files can become corrupt and cause all sorts of weird behavior. This problem is very difficult to find because often the VBA customizations will not stop working all-together, but the code may work intermittently. The results are unpredictable.  </p>
<p>Several years ago my current employer contracted with M2M to customize M2M using VBA and FastForms. I came on board in the middle of it. After M2M delivered the code file, I could not get it to work. Some modules would not work, and some would work, but not completely. When I opened the M2VEvents.prj file and reviewed the code, I knew that it should work. After nearly 40 hours of investigation, I realized that the file M2M had provided was corrupt. The consultant had to re-create a new file and the new copy worked. I&#8217;m sure they used the same method I am going to share with you. </p>
<p>Please read my <a href="http://www.made2mentor.com/2010/03/standard-disclaimer/">standard disclaimer </a>before you begin and perform these operations on a back up copy of your M2VEvents.prj file. Before beginning the process, note the size of the file. </p>
<h3>What are the Steps?</h3>
<ol>
<li>
Open the VBPROJ screen to load the empty project.  Easiest way is to hit ALT-F8.</li>
<li>The currently used VBA Project File should be listed. Click edit and the VBA editor will open. Click the thumbnail below to see full size.</li>
<p><a href="http://www.made2mentor.com/wp-content/uploads/2010/03/vba_editor_modules.jpg"><img src="http://www.made2mentor.com/wp-content/uploads/2010/03/vba_editor_modules-150x150.jpg" alt="" title="vba_editor_modules" width="150" height="150" class="alignnone size-thumbnail wp-image-3160" /></a></p>
<li>Right click on each of your forms and modules and select Remove.  You will be asked if you want to export them first, do so.   </li>
<li>After every form and module is removed you will find that your M2VEvents.prj file still has not shrunk.  I have no idea why not.  This is why you need to start with an &#8220;empty&#8221; one. </li>
<li>Before proceeding, in the VBA window check your references. They&#8217;re found under Tools, References. Jot them down or take a screen shot. Click the thumbnail below to see full size.</li>
<p><a href="http://www.made2mentor.com/wp-content/uploads/2010/03/vba_references.jpg"><img src="http://www.made2mentor.com/wp-content/uploads/2010/03/vba_references-150x150.jpg" alt="" title="vba_references" width="150" height="150" class="alignnone size-thumbnail wp-image-3165" /></a></p>
<li>Download the attached &#8220;empty&#8221; <a href='http://www.made2mentor.com/wp-content/uploads/2010/03/M2VEvents.zip'>M2VEvents.prj file</a>.</li>
<li>Go to your VBPROJ screen to load the empty project.  The easiest way is to hit ALT-F8. Click on the Close button.  </li>
<li>Choose a screen which will have customizations associated with it.  In this example, I did so with the SO screen.  Right click on the mnemonic and choose Components.</li>
<p><a href="http://www.made2mentor.com/wp-content/uploads/2010/03/components.jpg"><img src="http://www.made2mentor.com/wp-content/uploads/2010/03/components-150x150.jpg" alt="" title="components" width="150" height="150" class="alignnone size-thumbnail wp-image-3171" /></a></p>
<li> Select an event such as INIT and you&#8217;ll notice that the corresponding module has been created for you. </li>
<li>Before importing any of the VB files, check your references in the new file.  Once again, they&#8217;re found under Tools, References.  Make sure that any that are included in your production system, are also included in the new prj file we are building.  </li>
<li>You may encounter a situation where your production prj file has a reference that is NOT found in the list of references for your blank file.  If so, notice which file is referenced below and browse to it manually.  </li>
<li>Now import the frm and bas modules.  However, you will have to remove the sample module created as your import will NOT replace it.</li>
<p><a href="http://www.made2mentor.com/wp-content/uploads/2010/03/import.jpg"><img src="http://www.made2mentor.com/wp-content/uploads/2010/03/import-150x150.jpg" alt="" title="import" width="150" height="150" class="alignnone size-thumbnail wp-image-3172" /></a></p>
<li>Test your customizations just to be sure everything works. </li>
</ol>
<p>I perform these shrinks every six months or so to avoid VBA file corruption. Note the difference in size of the file.  My production file shrunk from 560KB to 131KB, roughly a 75% reduction. </p>
<p>So, how much did your file shrink? </p>
]]></content:encoded>
			<wfw:commentRss>http://www.made2mentor.com/2010/03/honey-i-shrunk-my-project-file/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>All the Little Ants are Marching&#8230;</title>
		<link>http://www.made2mentor.com/2010/03/ants-marching/</link>
		<comments>http://www.made2mentor.com/2010/03/ants-marching/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 14:10:51 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Made2Manage]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://www.made2mentor.com/?p=3001</guid>
		<description><![CDATA[
			
				
			
		
<p>
&#8220;I got an ant farm; them fellas didn&#8217;t grow shit.&#8221; &#8211; Mitch Hedberg</p>
<p>A few months ago I became aware that a company I deal with still uses dot matrix printers. For those of you who have never seen one, that’s because most companies phased these relics out of existence fifteen years ago.</p>
<p>The dot matrix printer [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.made2mentor.com%2F2010%2F03%2Fants-marching%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.made2mentor.com%2F2010%2F03%2Fants-marching%2F&amp;source=Made2Mentor&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://www.made2mentor.com/wp-content/uploads/2010/03/ants.jpg"><img src="http://www.made2mentor.com/wp-content/uploads/2010/03/ants.jpg" alt="" title="ants" width="367" height="242" class="alignleft size-full wp-image-3022" /></a><br />
&#8220;I got an ant farm; them fellas didn&#8217;t grow shit.&#8221; &#8211; Mitch Hedberg</p>
<p>A few months ago I became aware that a company I deal with still uses dot matrix printers. For those of you who have <a href="http://en.wikipedia.org/wiki/Dot_matrix_printer">never seen one</a>, that’s because most companies phased these relics out of existence fifteen years ago.</p>
<p>The dot matrix printer worked so why replace it? Well, it’s more expensive to operate for one since their printers still need the special pin feed paper and they’re buying it in three ply colors. </p>
<p>Anyway, they called me in a panic because their printer died. After a great deal of effort, I convinced them not to fix or replace it with another dinosaur, and get a good laser printer instead. </p>
<h3>Red and Black Antennas Waving&#8230;</h3>
<p>On a recent visit to that site I witnessed the accounts payable people actually using the special three ply dot matrix paper with the laser printer.  Once again, for those who have never used one, let me explain why this is a problem. Each box of paper is actually one long contiguous piece of paper with perforations between the individual sheets. So, each piece is torn from that long strip. The paper is also bordered on both sides by perforated strips with holes running down each side. The ancient printers used a pin feed mechanism with round pinned cogs on both sides, and those pins entered the holes of the paper. The Cogs spin and move the paper into the machine. The users were going through all of this hassle for every single print and feeding each piece of colored paper into the laser printer, and manually printing each invoice three times so they’d have separate color copies of the invoice. Each invoice required several minutes to print this way.</p>
<h3>They all do it the Same&#8230; They all do it the Same Way..</h3>
<p>This kind of behavior reminds me of college jobs I had. Between college jobs, I took a temporary position with <a href="http://www.amway.com/en">Amway</a>, which is a multi-level marketing company founded near my hometown in West Michigan. Their production facilities are there and I worked on their factory floor. The supervisors moved the temps to new jobs every two hours. Each station was more boring that the last. I’d spend two solid hours placing empty packaging tubes on a conveyor belt, etc. However, the most boring job was to sit on a stool and watch high pressure spray deodorant bottles run at high speed into a water bath and look for bubbles. The trouble was that you would only see one every fifteen minutes or so. I had terrible trouble staying alert and quickly realized that mind numbing, repetitive tasks were not for me. </p>
<p>Anyway, back to the accounting folks. This kind of behavior is mind-blowing to me as much as <a href="http://www.made2mentor.com/2009/09/pete-people-for-the-ethical-treatment-of-excel/">Excel Hell</a>. Users can be almost robotic in their actions. They don’t think about their actions nor question them. They simply have to print invoices, this is the invoice paper, use it to create invoices. When I asked them why they weren’t using regular laser printer paper to print invoices their answer essentially was, “Nobody told us to.” In fact, the purchasing department kept ordering this dot matrix paper. </p>
<p>I met with the manager and explained that they should use regular paper. They should eschew the multiple colors and I would create separate copies of the invoice for them. They would save time and the paper would be much cheaper. </p>
<p>However, when he asked his people about the change <strong>they unanimously rejected it.</strong> They didn&#8217;t feel that there was anything wrong with the current process and were comfortable with it. Un-freakin-believable. </p>
<p>Do you notice similar attitudes and behavior in your work?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.made2mentor.com/2010/03/ants-marching/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Removing Null Country Values From the Syaddr Table</title>
		<link>http://www.made2mentor.com/2010/03/removing-null-country-values/</link>
		<comments>http://www.made2mentor.com/2010/03/removing-null-country-values/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 02:45:27 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[Made2Manage]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Data Integrity]]></category>

		<guid isPermaLink="false">http://www.made2mentor.com/?p=2986</guid>
		<description><![CDATA[
			
				
			
		
<p>Unfortunately M2M does not automatically populate the Country field on many screens when a US State is selected. This can cause problems in reporting when an executive wants sales broken down by country and many of them are grouped under Null. </p>
<p>Anyway, if you want to see how many addresses are missing &#8220;United States&#8221; you [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.made2mentor.com%2F2010%2F03%2Fremoving-null-country-values%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.made2mentor.com%2F2010%2F03%2Fremoving-null-country-values%2F&amp;source=Made2Mentor&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Unfortunately M2M does not automatically populate the Country field on many screens when a US State is selected. This can cause problems in reporting when an executive wants sales broken down by country and many of them are grouped under Null. </p>
<p>Anyway, if you want to see how many addresses are missing &#8220;United States&#8221; you can run the following script. Once again, please read my <a href="http://www.made2mentor.com/2010/03/standard-disclaimer/">standard disclaimer</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">FROM</span> syaddr 
<span style="color: #0000FF;">WHERE</span> FCCOUNTRY <span style="color: #808080;">=</span> <span style="color: #FF0000;">''</span>
<span style="color: #808080;">AND</span> fcstate <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'AL'</span>,<span style="color: #FF0000;">'AK'</span>,<span style="color: #FF0000;">'AZ'</span>,<span style="color: #FF0000;">'AR'</span>,
                       <span style="color: #FF0000;">'CA'</span>,<span style="color: #FF0000;">'CO'</span>,<span style="color: #FF0000;">'CT'</span>,<span style="color: #FF0000;">'DE'</span>,
                       <span style="color: #FF0000;">'DC'</span>,<span style="color: #FF0000;">'FL'</span>,<span style="color: #FF0000;">'GA'</span>,<span style="color: #FF0000;">'HI'</span>,
                       <span style="color: #FF0000;">'ID'</span>,<span style="color: #FF0000;">'IL'</span>,<span style="color: #FF0000;">'IN'</span>,<span style="color: #FF0000;">'IA'</span>,
                       <span style="color: #FF0000;">'KS'</span>,<span style="color: #FF0000;">'KY'</span>,<span style="color: #FF0000;">'LA'</span>,<span style="color: #FF0000;">'ME'</span>,
                       <span style="color: #FF0000;">'MD'</span>,<span style="color: #FF0000;">'MA'</span>,<span style="color: #FF0000;">'MI'</span>,<span style="color: #FF0000;">'MN'</span>,
                       <span style="color: #FF0000;">'MS'</span>,<span style="color: #FF0000;">'MO'</span>,<span style="color: #FF0000;">'MT'</span>,<span style="color: #FF0000;">'NE'</span>,
                       <span style="color: #FF0000;">'NV'</span>,<span style="color: #FF0000;">'NH'</span>,<span style="color: #FF0000;">'NJ'</span>,<span style="color: #FF0000;">'NM'</span>,
                       <span style="color: #FF0000;">'NY'</span>,<span style="color: #FF0000;">'NC'</span>,<span style="color: #FF0000;">'ND'</span>,<span style="color: #FF0000;">'OH'</span>,
                       <span style="color: #FF0000;">'OK'</span>,<span style="color: #FF0000;">'OR'</span>,<span style="color: #FF0000;">'PA'</span>,<span style="color: #FF0000;">'RI'</span>,
                       <span style="color: #FF0000;">'SC'</span>,<span style="color: #FF0000;">'SD'</span>,<span style="color: #FF0000;">'TN'</span>,<span style="color: #FF0000;">'TX'</span>,
                       <span style="color: #FF0000;">'UT'</span>,<span style="color: #FF0000;">'VT'</span>,<span style="color: #FF0000;">'VA'</span>,<span style="color: #FF0000;">'WA'</span>,
                       <span style="color: #FF0000;">'WV'</span>,<span style="color: #FF0000;">'WI'</span>,<span style="color: #FF0000;">'WY'</span><span style="color: #808080;">&#41;</span></pre></div></div>

<p>If you want to fix them automatically, you may want to run the following script. It will update all of the blank country records fields that are associated with US states.</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">UPDATE</span> syaddr
<span style="color: #0000FF;">SET</span> FCCOUNTRY <span style="color: #808080;">=</span> <span style="color: #FF0000;">'United States'</span>
<span style="color: #0000FF;">WHERE</span> FCCOUNTRY <span style="color: #808080;">=</span> <span style="color: #FF0000;">''</span>
<span style="color: #808080;">AND</span> fcstate <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'AL'</span>,<span style="color: #FF0000;">'AK'</span>,<span style="color: #FF0000;">'AZ'</span>,<span style="color: #FF0000;">'AR'</span>,
                       <span style="color: #FF0000;">'CA'</span>,<span style="color: #FF0000;">'CO'</span>,<span style="color: #FF0000;">'CT'</span>,<span style="color: #FF0000;">'DE'</span>,
                       <span style="color: #FF0000;">'DC'</span>,<span style="color: #FF0000;">'FL'</span>,<span style="color: #FF0000;">'GA'</span>,<span style="color: #FF0000;">'HI'</span>,
                       <span style="color: #FF0000;">'ID'</span>,<span style="color: #FF0000;">'IL'</span>,<span style="color: #FF0000;">'IN'</span>,<span style="color: #FF0000;">'IA'</span>,
                       <span style="color: #FF0000;">'KS'</span>,<span style="color: #FF0000;">'KY'</span>,<span style="color: #FF0000;">'LA'</span>,<span style="color: #FF0000;">'ME'</span>,
                       <span style="color: #FF0000;">'MD'</span>,<span style="color: #FF0000;">'MA'</span>,<span style="color: #FF0000;">'MI'</span>,<span style="color: #FF0000;">'MN'</span>,
                       <span style="color: #FF0000;">'MS'</span>,<span style="color: #FF0000;">'MO'</span>,<span style="color: #FF0000;">'MT'</span>,<span style="color: #FF0000;">'NE'</span>,
                       <span style="color: #FF0000;">'NV'</span>,<span style="color: #FF0000;">'NH'</span>,<span style="color: #FF0000;">'NJ'</span>,<span style="color: #FF0000;">'NM'</span>,
                       <span style="color: #FF0000;">'NY'</span>,<span style="color: #FF0000;">'NC'</span>,<span style="color: #FF0000;">'ND'</span>,<span style="color: #FF0000;">'OH'</span>,
                       <span style="color: #FF0000;">'OK'</span>,<span style="color: #FF0000;">'OR'</span>,<span style="color: #FF0000;">'PA'</span>,<span style="color: #FF0000;">'RI'</span>,
                       <span style="color: #FF0000;">'SC'</span>,<span style="color: #FF0000;">'SD'</span>,<span style="color: #FF0000;">'TN'</span>,<span style="color: #FF0000;">'TX'</span>,
                       <span style="color: #FF0000;">'UT'</span>,<span style="color: #FF0000;">'VT'</span>,<span style="color: #FF0000;">'VA'</span>,<span style="color: #FF0000;">'WA'</span>,
                       <span style="color: #FF0000;">'WV'</span>,<span style="color: #FF0000;">'WI'</span>,<span style="color: #FF0000;">'WY'</span><span style="color: #808080;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.made2mentor.com/2010/03/removing-null-country-values/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Standard Disclaimer</title>
		<link>http://www.made2mentor.com/2010/03/standard-disclaimer/</link>
		<comments>http://www.made2mentor.com/2010/03/standard-disclaimer/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 02:45:11 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Made2Manage]]></category>

		<guid isPermaLink="false">http://www.made2mentor.com/?p=2964</guid>
		<description><![CDATA[
			
				
			
		
<p>
As I was preparing to post another script, this time with an update statement, I started to insert my standard disclaimer. However, as more and more of my posts will include SQL code, I thought I would just dedicate one post for the disclaimer and then link to it. So, without further adieu&#8230;</p>
Important: All information [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.made2mentor.com%2F2010%2F03%2Fstandard-disclaimer%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.made2mentor.com%2F2010%2F03%2Fstandard-disclaimer%2F&amp;source=Made2Mentor&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://www.made2mentor.com/wp-content/uploads/2010/03/disclaimer.jpg"><img src="http://www.made2mentor.com/wp-content/uploads/2010/03/disclaimer.jpg" alt="" title="disclaimer" width="166" height="346" class="alignleft size-full wp-image-2977" /></a><br />
As I was preparing to post another script, this time with an update statement, I started to insert my standard disclaimer. However, as more and more of my posts will include SQL code, I thought I would just dedicate one post for the disclaimer and then link to it. So, without further adieu&#8230;</p>
<h4>Important: All information on this site is provided &#8220;as is&#8221; for informational purposes only. </p>
<p>In particular, all code samples are provided &#8220;as is&#8221; without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.  </p>
<p>If you should decide to use any of the code taken from this site, make sure you test it thoroughly on a test company, or better yet a <a href="http://www.made2mentor.com/?p=156">test server</a>, before you ever use it on your live data.  </h4>
<p>That isn&#8217;t to say that I don&#8217;t want to help you, I help people all the time. Just be careful when you apply any code to your server or database. I do my best to research everything I post, but ultimately you are responsible for your own database. </p>
<p>Keep that in mind when you run code from my site or any site you find on the internet because&#8230;.<br />
<a href="http://www.made2mentor.com/wp-content/uploads/2010/03/fault_stupid1.jpg"><img src="http://www.made2mentor.com/wp-content/uploads/2010/03/fault_stupid1.jpg" alt="" title="fault_stupid1" width="288" height="288" class="alignleft size-full wp-image-2983" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.made2mentor.com/2010/03/standard-disclaimer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>M2M Database Polls</title>
		<link>http://www.made2mentor.com/2010/03/m2m-database-polls/</link>
		<comments>http://www.made2mentor.com/2010/03/m2m-database-polls/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 18:50:42 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Made2Manage]]></category>

		<guid isPermaLink="false">http://www.made2mentor.com/?p=2950</guid>
		<description><![CDATA[
			
				
			
		
<p>One of my crappy college jobs was in market research. Yes, I was one of those annoying guys in the mall holding a clipboard. I would approach you, politely ask you about your soda preferences (for the enlightened folks we call it Pop), and then take you back into the &#8220;store&#8221; to do a taste [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.made2mentor.com%2F2010%2F03%2Fm2m-database-polls%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.made2mentor.com%2F2010%2F03%2Fm2m-database-polls%2F&amp;source=Made2Mentor&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>One of my crappy college jobs was in market research. Yes, I was one of those annoying guys in the mall holding a clipboard. I would approach you, politely ask you about your soda preferences (for the enlightened folks we call it Pop), and then take you back into the &#8220;store&#8221; to do a taste test on several of them. Kind of like the Pepsi Challenge. </p>
<p>It required a few minutes, but it was general painless and we&#8217;d send you away with samples of free products. Well, I don&#8217;t want to know whether you prefer Coke or Pepsi, but I have what I think are some amazing ideas for reporting on M2M. I need your assistance to determine whether people can/will actually use them. So, in the same vein, please assist me by answering some questions. </p>
<p>How large is your largest M2M database? To determine the database size, simply open Enterprise Manager, navigate to your database, right click on it, and choose Properties. You should see the size of the database on the first page shown (General).<br />
Note: There is a poll embedded within this post, please visit the site to participate in this post's poll.</p>
<p>Is disk space an issue for you? If I told you I could <strong>simply your reporting life by automating most of the reporting process</strong>, but it would involve duplicating at least parts of your database, would this cause you an issue? Keep in mind that this process could double or triple your disk usage.<br />
Note: There is a poll embedded within this post, please visit the site to participate in this post's poll.</p>
<p>Please paste the following script into Query Analyzer or SQL Server Management Studio. It will report the size of many of the primary tables in your M2M Database. Please respond by copying and pasting the grid into the comments area, like people did with the <a href="http://www.made2mentor.com/2010/02/let%E2%80%99s-play-the-orphaned-records-game/">Orphaned Records Game</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">DECLARE</span> @TableName <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">100</span><span style="color: #808080;">&#41;</span>    <span style="color: #008080;">--For storing values in the cursor</span>
&nbsp;
<span style="color: #008080;">--Cursor to get the name of all user tables from the sysobjects listing</span>
<span style="color: #0000FF;">DECLARE</span> tableCursor <span style="color: #0000FF;">CURSOR</span>
<span style="color: #0000FF;">FOR</span> 
<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">&#91;</span>name<span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">FROM</span> dbo.<span style="color: #202020;">sysobjects</span> 
<span style="color: #0000FF;">WHERE</span>  <span style="color: #FF00FF;">OBJECTPROPERTY</span><span style="color: #808080;">&#40;</span>id, N<span style="color: #FF0000;">'IsUserTable'</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #000;">1</span>
and <span style="color: #808080;">&#91;</span>name<span style="color: #808080;">&#93;</span> in 
<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'slcdpm'</span>,
         <span style="color: #FF0000;">'somast'</span>,
         <span style="color: #FF0000;">'soitem'</span>,
         <span style="color: #FF0000;">'sorels'</span>,
         <span style="color: #FF0000;">'qtmast'</span>,
         <span style="color: #FF0000;">'qtitem'</span>,
         <span style="color: #FF0000;">'inmast'</span>,
         <span style="color: #FF0000;">'inonhd'</span>,
         <span style="color: #FF0000;">'invend'</span>,
         <span style="color: #FF0000;">'armast'</span>,
         <span style="color: #FF0000;">'aritem'</span>,
         <span style="color: #FF0000;">'apmast'</span>,
         <span style="color: #FF0000;">'apitem'</span>,
         <span style="color: #FF0000;">'jomast'</span>,
         <span style="color: #FF0000;">'joitem'</span>,
         <span style="color: #FF0000;">'pomast'</span>,
         <span style="color: #FF0000;">'poitem'</span>,
         <span style="color: #FF0000;">'lamast'</span>,
         <span style="color: #FF0000;">'ladetail'</span>,
         <span style="color: #FF0000;">'shmast'</span>,
         <span style="color: #FF0000;">'shitem'</span>,
         <span style="color: #FF0000;">'glmast'</span>,
         <span style="color: #FF0000;">'glitem'</span>,
         <span style="color: #FF0000;">'rcmast'</span>,
         <span style="color: #FF0000;">'rcitem'</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">FOR</span> <span style="color: #0000FF;">READ</span> <span style="color: #0000FF;">ONLY</span>
&nbsp;
<span style="color: #008080;">--A procedure level temp table to store the results</span>
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> #TempTable
<span style="color: #808080;">&#40;</span>
    tableName <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">100</span><span style="color: #808080;">&#41;</span>,
    numberofRows <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">100</span><span style="color: #808080;">&#41;</span>,
    reservedSize <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">50</span><span style="color: #808080;">&#41;</span>,
    dataSize <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">50</span><span style="color: #808080;">&#41;</span>,
    indexSize <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">50</span><span style="color: #808080;">&#41;</span>,
    unusedSize <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">50</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #008080;">--Open the cursor</span>
<span style="color: #0000FF;">OPEN</span> tableCursor
&nbsp;
<span style="color: #008080;">--Get the first table name from the cursor</span>
<span style="color: #0000FF;">FETCH</span> <span style="color: #0000FF;">NEXT</span> <span style="color: #0000FF;">FROM</span> tableCursor <span style="color: #0000FF;">INTO</span> @TableName
&nbsp;
<span style="color: #008080;">--Loop until the cursor was not able to fetch</span>
<span style="color: #0000FF;">WHILE</span> <span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">@@FETCH_STATUS</span> <span style="color: #808080;">&gt;=</span> <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">BEGIN</span>
    <span style="color: #008080;">--Dump the results of the sp_spaceused query to the temp table</span>
    <span style="color: #0000FF;">INSERT</span>  #TempTable
        <span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_SPACEUSED</span> @TableName
&nbsp;
    <span style="color: #008080;">--Get the next table name</span>
    <span style="color: #0000FF;">FETCH</span> <span style="color: #0000FF;">NEXT</span> <span style="color: #0000FF;">FROM</span> tableCursor <span style="color: #0000FF;">INTO</span> @TableName
<span style="color: #0000FF;">END</span>
&nbsp;
<span style="color: #008080;">--Get rid of the cursor</span>
<span style="color: #0000FF;">CLOSE</span> tableCursor
<span style="color: #0000FF;">DEALLOCATE</span> tableCursor
&nbsp;
<span style="color: #008080;">--Select all records so we can use the reults</span>
<span style="color: #0000FF;">SELECT</span> tablename <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">TABLE</span><span style="color: #808080;">&#93;</span>,datasize <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">SIZE</span><span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">FROM</span> #TempTable
<span style="color: #0000FF;">ORDER</span> <span style="color: #0000FF;">BY</span> tablename
&nbsp;
<span style="color: #008080;">--Final cleanup!</span>
<span style="color: #0000FF;">DROP</span> <span style="color: #0000FF;">TABLE</span> #TempTable</pre></div></div>

<p>Thank you for participating, and stay tuned for updates on my new reporting ideas. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.made2mentor.com/2010/03/m2m-database-polls/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Tool Dependence</title>
		<link>http://www.made2mentor.com/2010/02/tool-dependence/</link>
		<comments>http://www.made2mentor.com/2010/02/tool-dependence/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 13:27:21 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[SSMS]]></category>
		<category><![CDATA[TOAD]]></category>

		<guid isPermaLink="false">http://www.made2mentor.com/?p=2934</guid>
		<description><![CDATA[
			
				
			
		
<p>My girlfriend really loves the Amazing Race Show, which of course means that I have to “love” it too. It’s a reality TV show where teams compete in contests all over the world with a one million dollar prize at the end. Anyway, in one episode of last season the contestants were in Dubai. The [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.made2mentor.com%2F2010%2F02%2Ftool-dependence%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.made2mentor.com%2F2010%2F02%2Ftool-dependence%2F&amp;source=Made2Mentor&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>My girlfriend really loves the <a href="http://www.examiner.com/x-22292-Savannah-Reality-TV-Examiner~y2009m10d25-Amazing-Race-recap--A-giant-slide-is-the-downfall-for-Mika-and-Canan?cid=edition-rss-Savannah">Amazing Race Show</a>, which of course means that I have to “love” it too. It’s a reality TV show where teams compete in contests all over the world with a one million dollar prize at the end. Anyway, in one episode of last season the contestants were in Dubai. The challenge was to weigh out the exactly $500,000 worth of gold and the value was constantly fluctuating. They were given the value of gold per ounce. The trick was to realize that 16 ounces are in a pound and for the sake of this example the price of gold is $1089.87 per ounce. If you divide $500,000 by the price per ounce you can figure out how many ounces you need. Then divide that number by 16 to determine how many pounds and ounces for the final weight. Simple right? Well, remember that the price of gold was changing every minute or so. Think you can do it in under a minute?</p>
<p>Go ahead and grab a piece of paper and try. I’ll wait.<br />
::Humming the Jeopardy Theme:: </p>
<p>What? You can’t do it? Everyone learns how to do it, it&#8217;s just simply long division. </p>
<p><a href="http://www.made2mentor.com/wp-content/uploads/2010/02/evil_calc.jpg"><img src="http://www.made2mentor.com/wp-content/uploads/2010/02/evil_calc.jpg" alt="" title="evil_calc" width="300" height="200" class="alignleft size-full wp-image-2937" /></a>You&#8217;ve forgotten how to do long division with decimals? I realized the same thing as my girlfriend and I were laughing at the contestants. I have forgotten how to do long division. This is ironic because I used to teach math. I am a SQL Programmer, which obviously involves math. I’m embarrassed to admit that I actually <a href="http://www.mathsisfun.com/dividing-decimals.html">Googled how to do long division with decimals</a>. </p>
<p>I can almost hear you saying, <strong>“Well stupid, use a calculator or the computer you are working on.” </strong>Well, some of the teams had calculators and got the answer. The teams that didn’t couldn’t keep up with the constantly changing price of gold and had to do an alternate challenge. </p>
<h3>What is the point? </h3>
<p>Why do we use calculators and computers? It’s simple, they are fast. What is the likelihood that a million dollars will be on the line for a long division problem? What is the likelihood that I will be without some kind of gadget that calculates? </p>
<p>In this case, it is a no-brainer. I may never have to do long division again. However, other technologies are not so clear-cut. Since moving to Dallas nearly two years ago I have used a Garmin Nuvi GPS and I love those things. I type in the address I’m looking for and it gives me turn by turn directions. It helps me find stores, restaurants, and I only use a small subset of the features of this device. </p>
<p>Here’s the problem. Since I use this thing everywhere I go, I have virtually no understanding of the geography here. Remember when you were a little kid and you were driven everywhere? Do you remember what it was like to start driving yourself? I actually had to “find” places that I had been to tons of times because I never had to know where they were before. In essence, this is my situation now. If someone asks me for directions to my place, I’m fairly clueless. </p>
<p>Can you still write cursive (besides your signature)? I really have to work at it and I hate filling out forms. Have you noticed that your spelling has degenerated since the advent of spell check? Mine has. </p>
<h3>What the heck does this have to do with SQL?</h3>
<p>How many of us could effectively program without intellisense? I learned Basic waaaay back in the day and really had to learn it. When discussing development tools I often hear veteran programmers laugh that you can code in notepad, but who would? We did. We learned more thoroughly too. When mistakes are painful, we make less of them. I truly think that people learning now, don’t learn as thoroughly because of intellisense.  </p>
<p>Furthermore, as I’ve mentioned before, when I write T-SQL I do so using a program called <a href="http://www.toadsoft.com/toadsqlserver/toad_sqlserver.htm">TOAD</a>. I really like the program and it greatly improves my productivity. However, if I open Query Analyzer or SQL Server Management Studio, I still have to Google many of the functions to get the syntax right. Is using TOAD, or another product doing myself a disservice in the long run? </p>
<p>What do you think? </p>
]]></content:encoded>
			<wfw:commentRss>http://www.made2mentor.com/2010/02/tool-dependence/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MacGyver Moments</title>
		<link>http://www.made2mentor.com/2010/02/macgyver-moments/</link>
		<comments>http://www.made2mentor.com/2010/02/macgyver-moments/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 13:31:47 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[TOAD]]></category>

		<guid isPermaLink="false">http://www.made2mentor.com/?p=2920</guid>
		<description><![CDATA[
			
				
			
		
<p><p class="wp-caption-text">Total Badass</p>We may have never saved the world with a paper clip, chewing gum, and duct tape, but many of us are MacGyvers in our daily lives. Perhaps we’re stuck with SQL Server 6 or running on ridiculously old equipment, for whatever reason we’ve had to make something out of junk. </p>
<p>I was reminded [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.made2mentor.com%2F2010%2F02%2Fmacgyver-moments%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.made2mentor.com%2F2010%2F02%2Fmacgyver-moments%2F&amp;source=Made2Mentor&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><div id="attachment_2921" class="wp-caption alignleft" style="width: 250px"><a href="http://www.made2mentor.com/wp-content/uploads/2010/02/macgyver.jpg"><img src="http://www.made2mentor.com/wp-content/uploads/2010/02/macgyver.jpg" alt="" title="" width="240" height="297" class="size-full wp-image-2921" /></a><p class="wp-caption-text">Total Badass</p></div>We may have never saved the world with a paper clip, chewing gum, and duct tape, but many of us are MacGyvers in our daily lives. Perhaps we’re stuck with SQL Server 6 or running on ridiculously old equipment, for whatever reason we’ve had to make something out of junk. </p>
<p>I was reminded of this the other night. I called a friend and co-worker at my previous employer.  I asked him how things were at the shop and he indicated that they were going fine, with the exception that the fax server needed to be replaced. That made me smile because I was tasked with building a fax server approximately 8 years ago with no budget whatsoever. I re-used a retired desktop computer (rather than a server), with Windows 98, with a paltry amount of RAM and hard drive space, and a Pentium II Processor. I stripped other retired computers of their dial up modems to use for faxing and filled all of the motherboard slots with them. </p>
<p>I purchased and installed ActiveFax, which I had heard about from a fellow M2M Admin, because it was so much cheaper than M2M’s officially supported product. At one time that “server” was e-mailing and faxing notifications of invoices, sales orders, and other documents to customers automatically. I integrated it into ordering software I wrote and Customer Service could automatically fax questions to customers as well.  It handled incoming faxes as well and acted as a secondary fax machine for two departments, directing those faxes to various network printers. ActiveFax never went down. It rarely needed to be upgraded. There were no maintenance fees as lifetime maintenance and upgrades were included. It just simply worked. </p>
<p>Building this server was actually one of the best decisions I made during my time there. This was one of my best MacGyver moments. </p>
<p>I&#8217;m tagging three Microsoft MVP&#8217;s that I follow on a regular basis <a href="http://www.brentozar.com/">Brent Ozar,</a> <a href="http://www.timmitchell.net/">Tim Mitchell,</a> and <a href="http://sqlblog.com/blogs/aaron_bertrand/">Aaron Bertrand</a> to challenge them to share their MacGyver Moments.</p>
<p>I also challenge my readers, both of you, to share yours. So, what are your MacGyver Moments? </p>
]]></content:encoded>
			<wfw:commentRss>http://www.made2mentor.com/2010/02/macgyver-moments/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Let’s Play the Orphaned Records Game</title>
		<link>http://www.made2mentor.com/2010/02/let%e2%80%99s-play-the-orphaned-records-game/</link>
		<comments>http://www.made2mentor.com/2010/02/let%e2%80%99s-play-the-orphaned-records-game/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 18:34:04 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[Made2Manage]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Data Integrity]]></category>

		<guid isPermaLink="false">http://www.made2mentor.com/?p=2896</guid>
		<description><![CDATA[
			
				
			
		
<p>In the past couple of weeks, I have discussed the problems of orphaned records in the M2M Database and promised to provide a script to find them. So, I’ve decided to turn it into a game. </p>
<p>If you’d like to play, paste the following script into your Query Analyzer or SQL Server Management Studio and [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.made2mentor.com%2F2010%2F02%2Flet%25e2%2580%2599s-play-the-orphaned-records-game%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.made2mentor.com%2F2010%2F02%2Flet%25e2%2580%2599s-play-the-orphaned-records-game%2F&amp;source=Made2Mentor&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>In the <a href="http://www.made2mentor.com/2010/02/orphaned-records-and-technical-hypochondria/">past couple of weeks</a>, I have discussed the problems of <a href="http://www.made2mentor.com/2010/02/more-data-corruption-problems-with-m2m-orphan-quote-records/">orphaned records</a> in the M2M Database and promised to provide a script to find them. So, I’ve decided to turn it into a game. </p>
<p>If you’d like to play, paste the following script into your Query Analyzer or SQL Server Management Studio and run it. It will return the count of orphaned records in each table. Copy and paste the results grid into the comments of the blog so we can compare. Here’s the script:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Sales Order Releases'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>sor.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span> S<span style="color: #808080;">OR</span>ELS S<span style="color: #808080;">OR</span>
      <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> SOITEM SOI
        <span style="color: #0000FF;">ON</span> SOI.<span style="color: #202020;">FSONO</span> <span style="color: #808080;">=</span> S<span style="color: #808080;">OR</span>.<span style="color: #202020;">FSONO</span>
 <span style="color: #808080;">AND</span>       SOI.<span style="color: #202020;">FINUMBER</span> <span style="color: #808080;">=</span> S<span style="color: #808080;">OR</span>.<span style="color: #202020;">FINUMBER</span>
      <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> SOMAST SOM
        <span style="color: #0000FF;">ON</span> SOM.<span style="color: #202020;">FSONO</span> <span style="color: #808080;">=</span> S<span style="color: #808080;">OR</span>.<span style="color: #202020;">FSONO</span>
      <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> SLCDPM SLC
        <span style="color: #0000FF;">ON</span> SLC.<span style="color: #202020;">FCUSTNO</span> <span style="color: #808080;">=</span> SOM.<span style="color: #202020;">FCUSTNO</span>
 <span style="color: #0000FF;">WHERE</span> SOI.<span style="color: #202020;">FSONO</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span>
 <span style="color: #808080;">OR</span>     SOM.<span style="color: #202020;">FSONO</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span>
 <span style="color: #808080;">OR</span>     SLC.<span style="color: #202020;">FCUSTNO</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Sales Order Items'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>SOI.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span> SOITEM SOI
      <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> SOMAST SOM
        <span style="color: #0000FF;">ON</span> SOM.<span style="color: #202020;">FSONO</span> <span style="color: #808080;">=</span> SOI.<span style="color: #202020;">FSONO</span>
      <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> SLCDPM SLC
        <span style="color: #0000FF;">ON</span> SLC.<span style="color: #202020;">FCUSTNO</span> <span style="color: #808080;">=</span> SOM.<span style="color: #202020;">FCUSTNO</span>
 <span style="color: #0000FF;">WHERE</span> SOM.<span style="color: #202020;">FSONO</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span>
 <span style="color: #808080;">OR</span>     SLC.<span style="color: #202020;">FCUSTNO</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Sales Order Master'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>SOM.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span> SOMAST SOM <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> SLCDPM SLC <span style="color: #0000FF;">ON</span> SLC.<span style="color: #202020;">FCUSTNO</span> <span style="color: #808080;">=</span> SOM.<span style="color: #202020;">FCUSTNO</span>
 <span style="color: #0000FF;">WHERE</span> SLC.<span style="color: #202020;">FCUSTNO</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Quote Items'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>qtitem.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span> qtitem
      <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> QTMAST
        <span style="color: #0000FF;">ON</span> qtmast.<span style="color: #202020;">fquoteno</span> <span style="color: #808080;">=</span> qtitem.<span style="color: #202020;">FQUOTENO</span>
      <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> slcdpm
        <span style="color: #0000FF;">ON</span> slcdpm.<span style="color: #202020;">FCUSTNO</span> <span style="color: #808080;">=</span> qtmast.<span style="color: #202020;">FCUSTNO</span>
 <span style="color: #0000FF;">WHERE</span> qtmast.<span style="color: #202020;">FQUOTENO</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span>
 <span style="color: #808080;">OR</span>     slcdpm.<span style="color: #202020;">FCUSTNO</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Quote Master'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>qtmast.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span> qtmast <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> slcdpm <span style="color: #0000FF;">ON</span> slcdpm.<span style="color: #202020;">FCUSTNO</span> <span style="color: #808080;">=</span> qtmast.<span style="color: #202020;">FCUSTNO</span>
 <span style="color: #0000FF;">WHERE</span> slcdpm.<span style="color: #202020;">FCUSTNO</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Shipping'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>shitem.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span> shitem <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> SHMAST <span style="color: #0000FF;">ON</span> shmast.<span style="color: #202020;">fshipno</span> <span style="color: #808080;">=</span> shitem.<span style="color: #202020;">fshipno</span>
 <span style="color: #0000FF;">WHERE</span> shmast.<span style="color: #202020;">FSHIPNO</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Accts Recv Items'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>aritem.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span> aritem
      <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> armast
        <span style="color: #0000FF;">ON</span> aritem.<span style="color: #202020;">FCINVOICE</span> <span style="color: #808080;">=</span> armast.<span style="color: #202020;">FCINVOICE</span>
      <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> slcdpm
        <span style="color: #0000FF;">ON</span> slcdpm.<span style="color: #202020;">FCUSTNO</span> <span style="color: #808080;">=</span> aritem.<span style="color: #202020;">FCUSTNO</span>
 <span style="color: #0000FF;">WHERE</span> armast.<span style="color: #202020;">FCINVOICE</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span>
 <span style="color: #808080;">OR</span>     slcdpm.<span style="color: #202020;">FCUSTNO</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Accts Recv Master'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>armast.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span> armast <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> SLCDPM <span style="color: #0000FF;">ON</span> slcdpm.<span style="color: #202020;">FCUSTNO</span> <span style="color: #808080;">=</span> armast.<span style="color: #202020;">FCUSTNO</span>
 <span style="color: #0000FF;">WHERE</span> slcdpm.<span style="color: #202020;">FCUSTNO</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Accts Payable Items'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>apitem.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span> apitem
      <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> apmast
        <span style="color: #0000FF;">ON</span> apitem.<span style="color: #202020;">FCINVKEY</span> <span style="color: #808080;">=</span> <span style="color: #808080;">&#40;</span>apmast.<span style="color: #202020;">fvendno</span> <span style="color: #808080;">+</span> apmast.<span style="color: #202020;">fcinvoice</span><span style="color: #808080;">&#41;</span>
      <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> APVEND
        <span style="color: #0000FF;">ON</span> APVEND.<span style="color: #202020;">FVENDNO</span> <span style="color: #808080;">=</span> apmAST.<span style="color: #202020;">FVENDNO</span>
 <span style="color: #0000FF;">WHERE</span> apmast.<span style="color: #202020;">IDENTITY_COLUMN</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span>
 <span style="color: #808080;">OR</span>     APVEND.<span style="color: #202020;">FVENDNO</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Accts Payable Master'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>apmast.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span> apmast <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> APVEND <span style="color: #0000FF;">ON</span> APVEND.<span style="color: #202020;">FVENDNO</span> <span style="color: #808080;">=</span> apmAST.<span style="color: #202020;">FVENDNO</span>
 <span style="color: #0000FF;">WHERE</span> APVEND.<span style="color: #202020;">FVENDNO</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'General Ledger'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>GLITEM.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span> GLITEM <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> glmast <span style="color: #0000FF;">ON</span> glmast.<span style="color: #202020;">fcacctnum</span> <span style="color: #808080;">=</span> glitem.<span style="color: #202020;">FCACCTNUM</span>
 <span style="color: #0000FF;">WHERE</span> glmast.<span style="color: #202020;">FCACCTNUM</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Journal Entry'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>gljeitem.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span>   gljeitem
      <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span>
        gljemast
      <span style="color: #0000FF;">ON</span> gljemast.<span style="color: #202020;">fcentry</span> <span style="color: #808080;">=</span> gljeitem.<span style="color: #202020;">fcentry</span>
 <span style="color: #0000FF;">WHERE</span> gljemast.<span style="color: #202020;">fcentry</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Jobs'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>joitem.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span> joitem <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> jomast <span style="color: #0000FF;">ON</span> jomast.<span style="color: #202020;">FJOBNO</span> <span style="color: #808080;">=</span> joitem.<span style="color: #202020;">FJOBNO</span>
 <span style="color: #0000FF;">WHERE</span> jomast.<span style="color: #202020;">FJOBNO</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Receiving Items'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>rcitem.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span> rcitem <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> rcmast <span style="color: #0000FF;">ON</span> rcmast.<span style="color: #202020;">FRECEIVER</span> <span style="color: #808080;">=</span> rcitem.<span style="color: #202020;">FRECEIVER</span>
 <span style="color: #0000FF;">WHERE</span> rcmast.<span style="color: #202020;">FRECEIVER</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Bill of Lading'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>bolitem.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span> BOLITEM <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> BOLMAST <span style="color: #0000FF;">ON</span> bolmast.<span style="color: #202020;">FCBOLNO</span> <span style="color: #808080;">=</span> bolitem.<span style="color: #202020;">FCBOLNO</span>
 <span style="color: #0000FF;">WHERE</span> bolmast.<span style="color: #202020;">FCBOLNO</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Purchase Items'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>poitem.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span> poitem <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> pomast <span style="color: #0000FF;">ON</span> pomast.<span style="color: #202020;">FPONO</span> <span style="color: #808080;">=</span> poitem.<span style="color: #202020;">FPONO</span>
 <span style="color: #0000FF;">WHERE</span> pomast.<span style="color: #202020;">FPONO</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Purchase Master'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>pomast.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span> pomast <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> apvend <span style="color: #0000FF;">ON</span> pomast.<span style="color: #202020;">FVENDNO</span> <span style="color: #808080;">=</span> apvend.<span style="color: #202020;">FVENDNO</span>
 <span style="color: #0000FF;">WHERE</span> apvend.<span style="color: #202020;">FVENDNO</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'RFQ'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>poqitm.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span>   poqitm
      <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span>
        POQREC
      <span style="color: #0000FF;">ON</span> POQREC.<span style="color: #202020;">fpartno</span> <span style="color: #808080;">+</span> POQREC.<span style="color: #202020;">frev</span> <span style="color: #808080;">+</span> POQREC.<span style="color: #202020;">fac</span> <span style="color: #808080;">=</span>
           poqitm.<span style="color: #202020;">fpartno</span> <span style="color: #808080;">+</span> poqitm.<span style="color: #202020;">fcpartrev</span> <span style="color: #808080;">+</span> poqitm.<span style="color: #202020;">fac</span>
 <span style="color: #0000FF;">WHERE</span> poqrec.<span style="color: #202020;">IDENTITY_COLUMN</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Inventory Vendors'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>invend.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span>   <span style="color: #808080;">IN</span>VEND
      <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span>
        <span style="color: #808080;">IN</span>MAST
      <span style="color: #0000FF;">ON</span> <span style="color: #808080;">&#40;</span>inmast.<span style="color: #202020;">FPARTNO</span> <span style="color: #808080;">+</span> inmast.<span style="color: #202020;">FREV</span> <span style="color: #808080;">+</span> inmast.<span style="color: #202020;">FAC</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span>
           <span style="color: #808080;">&#40;</span>invend.<span style="color: #202020;">FPARTNO</span> <span style="color: #808080;">+</span> invend.<span style="color: #202020;">FPARTREV</span> <span style="color: #808080;">+</span> invend.<span style="color: #202020;">FAC</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">WHERE</span> inmast.<span style="color: #202020;">IDENTITY_COLUMN</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Current Rev'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>invcur.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span>   <span style="color: #808080;">IN</span>VCUR
      <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span>
        <span style="color: #808080;">IN</span>MAST
      <span style="color: #0000FF;">ON</span> <span style="color: #808080;">&#40;</span><span style="color: #808080;">IN</span>VCUR.<span style="color: #202020;">fcpartno</span> <span style="color: #808080;">+</span> <span style="color: #808080;">IN</span>VCUR.<span style="color: #202020;">fcpartrev</span> <span style="color: #808080;">+</span> <span style="color: #808080;">IN</span>VCUR.<span style="color: #202020;">fac</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span>
           <span style="color: #808080;">&#40;</span>inmast.<span style="color: #202020;">FPARTNO</span> <span style="color: #808080;">+</span> inmast.<span style="color: #202020;">FREV</span> <span style="color: #808080;">+</span> inmast.<span style="color: #202020;">fac</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">WHERE</span> inmast.<span style="color: #202020;">FPARTNO</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Part Cross Ref'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span>incros.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span>   incros
      <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span>
        inmast
      <span style="color: #0000FF;">ON</span> <span style="color: #808080;">&#40;</span>incros.<span style="color: #202020;">fpartno</span> <span style="color: #808080;">+</span> incros.<span style="color: #202020;">fcpartrev</span> <span style="color: #808080;">+</span> incros.<span style="color: #202020;">fac</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span>
           <span style="color: #808080;">&#40;</span>inmast.<span style="color: #202020;">FPARTNO</span> <span style="color: #808080;">+</span> inmast.<span style="color: #202020;">FREV</span> <span style="color: #808080;">+</span> inmast.<span style="color: #202020;">fac</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">WHERE</span> inmast.<span style="color: #202020;">FPARTNO</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">UNION</span>
<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'BOMs'</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">IN</span>BOMS.<span style="color: #202020;">IDENTITY_COLUMN</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">FROM</span>   <span style="color: #808080;">IN</span>BOMS
      <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span>
        <span style="color: #808080;">IN</span>BOMM
      <span style="color: #0000FF;">ON</span> <span style="color: #808080;">&#40;</span><span style="color: #808080;">IN</span>BOMS.<span style="color: #202020;">fparent</span> <span style="color: #808080;">+</span> <span style="color: #808080;">IN</span>BOMS.<span style="color: #202020;">fparentrev</span> <span style="color: #808080;">+</span> <span style="color: #808080;">IN</span>BOMS.<span style="color: #202020;">pfacilityid</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span>
           <span style="color: #808080;">&#40;</span><span style="color: #808080;">IN</span>BOMM.<span style="color: #202020;">fpartno</span> <span style="color: #808080;">+</span> <span style="color: #808080;">IN</span>BOMM.<span style="color: #202020;">fcpartrev</span> <span style="color: #808080;">+</span> <span style="color: #808080;">IN</span>BOMM.<span style="color: #202020;">facilityid</span><span style="color: #808080;">&#41;</span>
 <span style="color: #0000FF;">WHERE</span> inboms.<span style="color: #202020;">fparent</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span></pre></div></div>

<p>If you have orphaned records and you want to see which records are orphaned, you can <a href='http://www.made2mentor.com/wp-content/uploads/2010/02/Orphan-File-Clean-Up-Left-Joins.txt'>download this script</a> and run it. It will show you details of the records found above. </p>
<h3>What should I do about orphaned records?</h3>
<p>Well, I would contact support to evaluate your problem and provide scripts to delete the records. If you aren’t on support, you may want to contract with a M2M consultant, such as myself, to verify that the records are un-needed and delete them. </p>
<p>So, what’s your score? </p>
]]></content:encoded>
			<wfw:commentRss>http://www.made2mentor.com/2010/02/let%e2%80%99s-play-the-orphaned-records-game/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>That&#8217;s Quite a View &#8211; INMast</title>
		<link>http://www.made2mentor.com/2010/02/thats-quite-a-view/</link>
		<comments>http://www.made2mentor.com/2010/02/thats-quite-a-view/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 13:35:42 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Made2Manage]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Customization]]></category>
		<category><![CDATA[Performance Tuning]]></category>

		<guid isPermaLink="false">http://www.made2mentor.com/?p=2909</guid>
		<description><![CDATA[
			
				
			
		
<p>A Made2Manage customer called me with a serious performance problem with one of his custom reports. After I looked at it, I realized that the inventory changes in M2M Version 6.0 were the culprit. To give you some idea of his problem, the query in question ran took a few seconds before the migration and [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.made2mentor.com%2F2010%2F02%2Fthats-quite-a-view%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.made2mentor.com%2F2010%2F02%2Fthats-quite-a-view%2F&amp;source=Made2Mentor&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>A Made2Manage customer called me with a serious performance problem with one of his custom reports. After I looked at it, I realized that the inventory changes in M2M Version 6.0 were the culprit. To give you some idea of his problem, the query in question ran took a few seconds before the migration and then jumped to a whopping 2.5 minutes afterward. </p>
<p>Since M2M Support won’t support custom reports, who you gonna call? Ghostbust….. Well no, actually me. <img src='http://www.made2mentor.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>What was the problem with M2M 6.0?</h3>
<p>I remembered from <a href="http://www.made2mentor.com/2008/10/vegas-reflections-consona-connect-2008/">Consona Connect 2008</a> that the inventory master table(INMAST) was essentially replaced with a sub table INMASTX and converted into a <strong>view</strong>. However, at that time, nobody could/would tell me why. Well, take a look at the create statement for the view:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">/****** Object: View [dbo].[inmast] ******/</span>
<span style="color: #0000FF;">USE</span> <span style="color: #808080;">&#91;</span>M2MDATA01<span style="color: #808080;">&#93;</span>;
GO
<span style="color: #0000FF;">SET</span>  ANSI_<span style="color: #808080;">NULL</span>S <span style="color: #0000FF;">ON</span>;
GO
<span style="color: #0000FF;">SET</span>  QUOTED_IDENTIFIER <span style="color: #0000FF;">ON</span>;
GO
&nbsp;
<span style="color: #008080;">-- Create new view and instead of trigger based on the renamed table.</span>
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">VIEW</span> dbo.<span style="color: #202020;">inmast</span> <span style="color: #0000FF;">AS</span>
  <span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span>
       , dbo.<span style="color: #202020;">GetItemOnHandQuantity</span><span style="color: #808080;">&#40;</span>fac, fpartno, frev<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> fonhand
       , dbo.<span style="color: #202020;">GetItemInspectionQuantity</span><span style="color: #808080;">&#40;</span>fac, fpartno, frev<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> fqtyinspec
       , dbo.<span style="color: #202020;">GetItemNonNetQuantity</span><span style="color: #808080;">&#40;</span>fac, fpartno, frev<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> fnonnetqty
       , dbo.<span style="color: #202020;">GetItemInProcessQuantity</span><span style="color: #808080;">&#40;</span>fac, fpartno, frev<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> fproqty
       , dbo.<span style="color: #202020;">GetItemOnOrderQuantity</span><span style="color: #808080;">&#40;</span>fac, fpartno, frev<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> fonorder
       , dbo.<span style="color: #202020;">GetItemCommittedQuantity</span><span style="color: #808080;">&#40;</span>fac, fpartno, frev<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> fbook
       , dbo.<span style="color: #202020;">GetItemLastIssueDate</span><span style="color: #808080;">&#40;</span>fac, fpartno, frev<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> flastiss
       , dbo.<span style="color: #202020;">GetItemLastReceiptDate</span><span style="color: #808080;">&#40;</span>fac, fpartno, frev<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> flastrcpt
       , dbo.<span style="color: #202020;">GetItemMTDIssues</span><span style="color: #808080;">&#40;</span>fac
                            , fpartno
                            , frev
                            , <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
           <span style="color: #0000FF;">AS</span> fmtdiss
       , dbo.<span style="color: #202020;">GetItemYTDIssues</span><span style="color: #808080;">&#40;</span>fac
                            , fpartno
                            , frev
                            , <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
           <span style="color: #0000FF;">AS</span> fytdiss
       , dbo.<span style="color: #202020;">GetItemMTDReceipts</span><span style="color: #808080;">&#40;</span>fac
                              , fpartno
                              , frev
                              , <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
           <span style="color: #0000FF;">AS</span> fmtdrcpt
       , dbo.<span style="color: #202020;">GetItemYTDReceipts</span><span style="color: #808080;">&#40;</span>fac
                              , fpartno
                              , frev
                              , <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
           <span style="color: #0000FF;">AS</span> fytdrcpt
  <span style="color: #0000FF;">FROM</span> dbo.<span style="color: #202020;">inmastx</span>
GO</pre></div></div>

<p>I’ll briefly describe what is happening here. The view loads every field from the base table IMASTX and then completes 12 separate User Defined Functions. I described how to use <a href="http://www.made2mentor.com/2010/01/using-user-defined-functions-to-suppress-blank-dates/">UDF’s here</a>. </p>
<h3>Why did Consona make this change?</h3>
<p>I’d say it’s a good bet that they did so because they’ve always had problems keeping inventory numbers synced with other tables, especially with the Inventory On Hand table (INONHD). That’s why there are so many utilities to recalculate these manually. It’s important to note that M2M violates the rules of database normalization by keeping duplicates of information all over its database, and this is just one more example of it. </p>
<h3>Great, what is the problem?</h3>
<p>The problem, as I eluded to before, is that this <strong>kills performance</strong>, or at least the querying performance. Each one of those UDFs makes a separate call to the database, converting one select statement into many for each row. </p>
<p>Consider the following profile traces. When I execute the following query against the underlying table:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span>
<span style="color: #0000FF;">FROM</span> inmastx
<span style="color: #0000FF;">WHERE</span> fpartno <span style="color: #808080;">=</span> <span style="color: #FF0000;">'123456'</span>
<span style="color: #808080;">AND</span>   frev <span style="color: #808080;">=</span> <span style="color: #FF0000;">'001'</span></pre></div></div>

<p>Profiler returns 13 rows with a total run time of 29 Milliseconds or .029 seconds.<br />
The next trace involves the same query against the INMAST view:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span>
<span style="color: #0000FF;">FROM</span> inmast
<span style="color: #0000FF;">WHERE</span> fpartno <span style="color: #808080;">=</span> ‘<span style="color: #000;">123456</span>’
<span style="color: #808080;">AND</span>   frev <span style="color: #808080;">=</span> <span style="color: #FF0000;">'001'</span></pre></div></div>

<p>Profiler returns 49 Rows with a total runtime of 198 Milliseconds or .198 seconds. </p>
<h3>What’s the big hairy deal? The second query is 1/5th of a second anyway.</h3>
<p>Ah, very true, but how many parts do you have in your item master? I ran the following queries against a database with approximately 7000 part numbers. Keep in mind that you should never “Select *” from anything, but I am doing it for simplicity.</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">FROM</span> inmastx requires <span style="color: #000;">1</span> <span style="color: #0000FF;">MINUTE</span> <span style="color: #000;">22</span> seconds. 
<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">FROM</span> inmast requires <span style="color: #000;">3</span> minutes <span style="color: #000;">4</span> seconds.</pre></div></div>

<p>This performance hit above is bad, but it actually gets worse. What happens if you are only retrieving fields that aren’t calculated? For example, what if you only want the part number, revision, and product class? This is common because some modules, such as shipping, do not include the product class so you must link back to the item master to retrieve it. Consider the following:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> FPARTNO, FREV, FPRODCL <span style="color: #0000FF;">FROM</span> m2mdata01..<span style="color: #202020;">inmast</span></pre></div></div>

<p>Because INMAST is a view, all of those columns are calculated anyway and the query churns 6 times as long regardless.  </p>
<h3>So, what do I do about it?</h3>
<p>Well, you’re going to have to edit your custom reports that deal with inventory in order to migrate, or consult with someone like me to do it for you. Essentially, you need to query the underlying table INMASTX for your data and then if you need On Hand Quantity, calculate it yourself with a sub-query. Here’s an example from above.</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span>
, dbo.<span style="color: #202020;">GetItemOnHandQuantity</span><span style="color: #808080;">&#40;</span>fac, fpartno, frev<span style="color: #808080;">&#41;</span> <span style="color: #808080;">&#91;</span>OnHand<span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">FROM</span> inmastx 
<span style="color: #0000FF;">WHERE</span> fpartno <span style="color: #808080;">=</span> <span style="color: #FF0000;">'123456'</span>
<span style="color: #808080;">AND</span>   frev <span style="color: #808080;">=</span> <span style="color: #FF0000;">'001'</span></pre></div></div>

<p>This isn’t a perfect solution, but in this way you can call any of the UDF’s used in that view without calling all of them. </p>
<h3>Well smarty pants, if this is so bad, what would you do?</h3>
<p>First, it’s Mr. Smarty Pants to you. Seriously though, I have reservations about the upgrade path with M2M. To the best of my knowledge, Consona is not making substantive database changes in Version 7. In my opinion, they should take the opportunity to <a href="http://en.wikipedia.org/wiki/Database_normalization">normalize the database</a> (or at least significant portions of it) and enforce <a href="http://www.made2mentor.com/2009/08/made2manage-lacks-referential-integrity/"> referential integrity</a> while migrating to the .Net platform. I think they should drop VFP entirely, train users to use SQL Reporting Services for reports, and start fresh in version 7. </p>
<p>What do you think? </p>
]]></content:encoded>
			<wfw:commentRss>http://www.made2mentor.com/2010/02/thats-quite-a-view/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
