<?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>Alex James Brown &#187; SQL</title>
	<atom:link href="http://www.alexjamesbrown.com/tags/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alexjamesbrown.com</link>
	<description>My Words. By Me.</description>
	<lastBuildDate>Wed, 04 Jan 2012 01:02:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Upgrading from Navision 4 to Navision 5 &#8211; Database Error</title>
		<link>http://www.alexjamesbrown.com/uncategorized/upgrading-from-navision-4-to-navision-5-database-error/</link>
		<comments>http://www.alexjamesbrown.com/uncategorized/upgrading-from-navision-4-to-navision-5-database-error/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 16:27:06 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Error]]></category>
		<category><![CDATA[navision]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.alexjamesbrown.com/?p=371</guid>
		<description><![CDATA[This is a tad of a messy blog post, so apologies for that, however it’s mainly for my own reference. Here at Crocus, we run Navision to handle product inventory, ...]]></description>
			<content:encoded><![CDATA[<p>This is a tad of a messy blog post, so apologies for that, however it’s mainly for my own reference.</p>
<p>Here at <a title="Crocus" href="http://www.crocus.co.uk" target="_blank">Crocus</a>, we run <a href="http://en.wikipedia.org/wiki/Microsoft_Dynamics_NAV" target="_blank">Navision</a> to handle product inventory, orders, and the like…    <br />We wanted to upgrade from version 4, to version 5.</p>
<p>After following the upgrade instructions, I got this error:</p>
<blockquote><p>Msg 8662, Level 16, State 0, Line 1      <br />Cannot create the clustered index &quot;VSIFTIDX&quot; on view &quot;Nav5.dbo.Crocus Live$OrderRequestDetail$VSIFT$1&quot; because the view references an unknown value (SUM aggregate of nullable expression). Consider referencing only non-nullable values in SUM. ISNULL() may be useful for this.</p>
</blockquote>
<p>Annoying.</p>
<p>There wasn’t anything obviously wrong.    <br />So I opened up SQL Profiler, and re-ran the update process in the Navision client, to capture the exact SQL queries that were causing the error….</p>
<p>I saw it created a view called Crocus Live$OrderRequestDetail$VSIFT$1</p>
<h3>Heres the create view script:</h3>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:1f01ede6-7ccb-4074-98b1-924cdc3b332f" class="wlWriterEditableSmartContent">
<pre name="code" class="sql">CREATE VIEW dbo."Crocus Live$OrderRequestDetail$VSIFT$1"
WITH SCHEMABINDING
AS
SELECT "PaidFor",COUNT_BIG(*) "$Cnt",SUM("Amount") "SUM$Amount",
SUM("AmountIncludingVAT") "SUM$AmountIncludingVAT"
FROM dbo."Crocus Live$OrderRequestDetail"
GROUP BY "PaidFor"</pre>
</div>
<h3>It was failing on the following query:</h3>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:c683f4a7-ed97-46b4-ac09-223dd1008225" class="wlWriterEditableSmartContent">
<pre name="code" class="sql">CREATE UNIQUE CLUSTERED INDEX "VSIFTIDX"
ON dbo."Crocus Live$OrderRequestDetail$VSIFT$1" ("PaidFor")</pre>
</div>
<h3>Problem was:</h3>
<p>Some of the columns specified as “boolean” within Navision, were in fact NULLABLE <strong><em>tinyint</em></strong> columns within SQL Server.</p>
<p>I suspect that this was due to some legacy version of SQL not supporting bit columns, or something along those lines…</p>
<p>Anyway, none of the values in the column (close to a million rows within the table) was null, so I changed the datatype to BIT and set NOT NULL. I did this for each of the columns in the table which should of been a boolean (and were specified in the CREATE VIEW statement (in my case was <strong>Amount</strong>, <strong>AmountIncludingVAT</strong> and <strong>PaidFor</strong>)</p>
<p>This immediately solved the “Cannot create the clustered index” problem</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alexjamesbrown.com/uncategorized/upgrading-from-navision-4-to-navision-5-database-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Copying tables across databases</title>
		<link>http://www.alexjamesbrown.com/uncategorized/copying-tables-across-databases/</link>
		<comments>http://www.alexjamesbrown.com/uncategorized/copying-tables-across-databases/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 09:39:28 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.alexjamesbrown.com/?p=131</guid>
		<description><![CDATA[So, you&#8217;ve got a requirement to move or copy a table from one database to the other? Including data? Use SELECT INTO. For example, we have a database called &#8220;MyDatabase&#8221; ...]]></description>
			<content:encoded><![CDATA[<p>So, you&#8217;ve got a requirement to move or copy a table from one database to the other? Including data?</p>
<p>Use <a href="http://www.w3schools.com/Sql/sql_select_into.asp" target="_blank">SELECT INTO</a>.</p>
<p>For example, we have a database called &#8220;MyDatabase&#8221;<br />
We also have another database &#8211; &#8220;MyNewDatabase&#8221;</p>
<p>MyDatabase contains the table &#8220;Customers&#8221; &#8211; with a bunch of data that we want to preserve.</p>
<p>You need to move this into MyNewDatabase?</p>
<p>Here is an example of the query:<br />
[sql]SELECT * INTO MyNewDatabase.dbo.Customers<br />
FROM MyDatabase.dbo.Customers[/sql]<br />
You could of course predicate your query, include where clauses, select only a few columns etc.</p>
<p>Check out this post on <a href="http://www.w3schools.com/Sql/sql_select_into.asp" target="_blank">W3Schools</a> for more information, and how to use this in the same database (for temp. backups for example)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alexjamesbrown.com/uncategorized/copying-tables-across-databases/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

