<?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>Claus on Code</title>
	<atom:link href="http://clausoncode.dk/wp/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://clausoncode.dk/wp</link>
	<description>A data dudes random musings about code, bugs, products, life etc.</description>
	<lastBuildDate>Sun, 22 Apr 2012 21:30:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Unboxing MS SQL Server 2012 &#8211; The new analytic functions</title>
		<link>http://clausoncode.dk/wp/?p=237</link>
		<comments>http://clausoncode.dk/wp/?p=237#comments</comments>
		<pubDate>Sun, 22 Apr 2012 21:29:14 +0000</pubDate>
		<dc:creator>Claus</dc:creator>
				<category><![CDATA[Unboxing MS SQL Server 2012]]></category>

		<guid isPermaLink="false">http://clausoncode.dk/wp/?p=237</guid>
		<description><![CDATA[As mentioned in my previous blot post, SQL server 2012 comes with 8 new analytic functions: LEAD LAG LAST_VALUE FIRST_VALUE PERCENTILE_CONT PERCENTILE_DISC PERCENT_RANK CUME_DIST All the new analytic functions work with the window functions I described earlier in this blog series, and calculate an aggregate in the given window. Let’s start by looking at the [...]]]></description>
			<content:encoded><![CDATA[<p>As mentioned in my <a href="http://clausoncode.dk/wp/?p=210">previous blot post</a>, SQL server 2012 comes with 8 new analytic functions:</p>
<ul>
<li>LEAD</li>
<li>LAG</li>
<li>LAST_VALUE</li>
<li>FIRST_VALUE</li>
<li>PERCENTILE_CONT</li>
<li>PERCENTILE_DISC</li>
<li>PERCENT_RANK</li>
<li>CUME_DIST</li>
</ul>
<p>All the new analytic functions work with the window functions I described earlier in this blog series, and calculate an aggregate in the given window.<br />
Let’s start by looking at the LAG and LEAD functions. The syntax looks like this</p>
<blockquote><p><code>LAG/LEAD (scalar_expression [,offset] [,default])<br />
OVER ( [ partition_by_clause ] order_by_clause )</code></p></blockquote>
<p>Let’s add them to the query and dataset I introduced <a href="http://clausoncode.dk/wp/?p=210">earlier</a>:</p>
<pre class="brush: sql; title: ; notranslate">

SELECT TOP 10
[Date] ,
[Last] ,
LEAD([Last],1) OVER
(PARTITION  BY YEAR(Date), MONTH(Date), Name ORDER BY Date DESC ) AS 'Lead 1' ,
LAG([Last],1) OVER
(PARTITION  BY YEAR(Date), MONTH(Date), Name ORDER BY Date DESC ) AS 'Lag 1' ,
LAG([Last],2) OVER
(PARTITION  BY YEAR(Date), MONTH(Date), Name ORDER BY Date DESC ) AS 'Lag 2'
FROM dbo.Stock ORDER BY DATE DESC
</pre>
<p>Which yield the result:</p>
<pre class="brush: plain; title: ; notranslate">

Date                    Last                  Lead 1                Lag 1                 Lag 2

----------------------- --------------------- --------------------- --------------------- ---------------------

2012-04-19 00:00:00.000 51,45                 51,65                 NULL                  NULL

2012-04-18 00:00:00.000 51,65                 53,35                 51,45                 NULL

2012-04-17 00:00:00.000 53,35                 55,55                 51,65                 51,45

2012-04-16 00:00:00.000 55,55                 48,95                 53,35                 51,65

2012-04-13 00:00:00.000 48,95                 50,55                 55,55                 53,35

2012-04-12 00:00:00.000 50,55                 50,65                 48,95                 55,55

2012-04-11 00:00:00.000 50,65                 50,20                 50,55                 48,95

2012-04-10 00:00:00.000 50,20                 52,50                 50,65                 50,55

2012-04-09 00:00:00.000 52,50                 52,50                 50,20                 50,65

2012-04-06 00:00:00.000 52,50                 52,50                 52,50                 50,20
</pre>
<p>The LAG and LEAD functions are pretty self-explaining, but it is a feature that I often need in my work, and this new way of getting those values are a great addition to the SQL Server.</p>
<p><strong>The FIRST/LAST_Value</strong> works pretty much the same way, and are just as self-explaining. The syntax looks like this</p>
<blockquote><p>FIRST/LAST_VALUE ( [scalar_expression )     OVER ( [ partition_by_clause ] order_by_clause rows_range_clause )</p></blockquote>
<p>Pay attention to the rows_range clause, if you want to make sure that the first/last row function doesn’t stop at the current row. Let’s look at the SQL:</p>
<pre class="brush: sql; title: ; notranslate">
SELECT TOP 50
[Date] ,
[Last] ,
FIRST_VALUE([Last]) OVER
        (PARTITION  BY YEAR(Date), MONTH(Date), Name ORDER BY Date ASC )
        AS 'First value in month' ,
LAST_VALUE([Last]) OVER
        (PARTITION  BY YEAR(Date), MONTH(Date), Name ORDER BY Date ASC
        RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING )
        AS 'Last Value in month'
FROM dbo.Stock
ORDER BY DATE DESC
</pre>
<p>Result:</p>
<pre class="brush: plain; title: ; notranslate">
Date                    Last                  First value in month  Last Value in month

----------------------- --------------------- --------------------- ---------------------

2012-04-19 00:00:00.000 51,45                 55,30                 51,45

2012-04-18 00:00:00.000 51,65                 55,30                 51,45

2012-04-17 00:00:00.000 53,35                 55,30                 51,45

2012-04-16 00:00:00.000 55,55                 55,30                 51,45

2012-04-13 00:00:00.000 48,95                 55,30                 51,45

2012-04-12 00:00:00.000 50,55                 55,30                 51,45

2012-04-11 00:00:00.000 50,65                 55,30                 51,45

2012-04-10 00:00:00.000 50,20                 55,30                 51,45

2012-04-09 00:00:00.000 52,50                 55,30                 51,45

2012-04-06 00:00:00.000 52,50                 55,30                 51,45

2012-04-05 00:00:00.000 52,50                 55,30                 51,45

2012-04-04 00:00:00.000 52,50                 55,30                 51,45

2012-04-03 00:00:00.000 54,95                 55,30                 51,45

2012-04-02 00:00:00.000 55,30                 55,30                 51,45

2012-03-30 00:00:00.000 56,60                 56,45                 56,60

2012-03-29 00:00:00.000 55,60                 56,45                 56,60

2012-03-28 00:00:00.000 58,20                 56,45                 56,60

2012-03-27 00:00:00.000 58,15                 56,45                 56,60

2012-03-26 00:00:00.000 60,95                 56,45                 56,60

2012-03-23 00:00:00.000 60,00                 56,45                 56,60

2012-03-22 00:00:00.000 58,25                 56,45                 56,60

2012-03-21 00:00:00.000 58,80                 56,45                 56,60

2012-03-20 00:00:00.000 59,30                 56,45                 56,60

2012-03-19 00:00:00.000 62,40                 56,45                 56,60

2012-03-16 00:00:00.000 63,95                 56,45                 56,60
</pre>
<p>The last 4 functions PERCENTILE_CONT, PERCENTILE_DISC, PERCENT_RANK, CUME_DIST are Window Distribution Functions used to do statistical computations. Coming up with an example about how to use those will take too long, but the syntax is similar to the other functions, and if you know the math behind, they are straightforward to use.</p>
<p><strong>Conclusion</strong></p>
<p>But to sum up. The conclusion is the same as in my previous blog post in this series. The new analytic functions a very nice addition to the new SQL server, and we can now do more advanced analytics in a much simpler way.</p>
]]></content:encoded>
			<wfw:commentRss>http://clausoncode.dk/wp/?feed=rss2&#038;p=237</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monitor the process of long running SQL queries like DBCC SHRINKDATABASE</title>
		<link>http://clausoncode.dk/wp/?p=222</link>
		<comments>http://clausoncode.dk/wp/?p=222#comments</comments>
		<pubDate>Tue, 17 Apr 2012 21:48:35 +0000</pubDate>
		<dc:creator>Claus</dc:creator>
				<category><![CDATA[MS SQL Server]]></category>

		<guid isPermaLink="false">http://clausoncode.dk/wp/?p=222</guid>
		<description><![CDATA[When a query runs a little longer than I would expect, I sometimes starts to get nervous. Especially in the cases, where there is no status telling me when it will finish; Like for instance when I run a shrink database cmd. You can get information about the queries running like this. Especially the percent_complete [...]]]></description>
			<content:encoded><![CDATA[<p>When a query runs a little longer than I would expect, I sometimes starts to get nervous. Especially in the cases, where there is no status telling me when it will finish; Like for instance when I run a shrink database cmd.</p>
<p>You can get information about the queries running like this.</p>
<pre class="brush: sql; title: ; notranslate">

SELECT
T.text,
R.Status,
R.Command,
DatabaseName = db_name(R.database_id) ,
R.cpu_time,
R.total_elapsed_time,
R.percent_complete
FROM sys.dm_exec_requests R
CROSS APPLY sys.dm_exec_sql_text(R.sql_handle) T
</pre>
<p>Especially the percent_complete is nice.</p>
]]></content:encoded>
			<wfw:commentRss>http://clausoncode.dk/wp/?feed=rss2&#038;p=222</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Unboxing MS SQL Server 2012 &#8211; The new window functions</title>
		<link>http://clausoncode.dk/wp/?p=210</link>
		<comments>http://clausoncode.dk/wp/?p=210#comments</comments>
		<pubDate>Mon, 09 Apr 2012 10:46:28 +0000</pubDate>
		<dc:creator>Claus</dc:creator>
				<category><![CDATA[Unboxing MS SQL Server 2012]]></category>

		<guid isPermaLink="false">http://clausoncode.dk/wp/?p=210</guid>
		<description><![CDATA[SQL server 2012 comes with a new set of window functions and analytically possibilities, which I will look into in this blog post. Prior to 2012 Prior to the 2012 version, windows functions were also possible. The syntax looked like this: Ranking Window Functions &#60; OVER_CLAUSE &#62; :: = OVER ( [ PARTITION BY value_expression [...]]]></description>
			<content:encoded><![CDATA[<p>SQL server 2012 comes with a new set of window functions and analytically possibilities, which I will look into in this blog post.</p>
<p><strong>Prior to 2012</strong><br />
Prior to the 2012 version, windows functions were also possible. The syntax looked like this:</p>
<blockquote><p>Ranking Window Functions<br />
&lt; OVER_CLAUSE &gt; :: =<br />
OVER ( [ PARTITION BY value_expression , ... [ n ] ]<br />
&lt;ORDER BY_Clause&gt; )</p>
<p>Aggregate Window Functions<br />
&lt; OVER_CLAUSE &gt; :: =<br />
OVER ( [ PARTITION BY value_expression , ... [ n ] ] )</p></blockquote>
<p>Where the over clause creates a window for the entire result set, and the PARTITION BY divide the window to a lot of smaller distinct windows. This can be used, when you look at a row with a value, for instance, to a product and day, and you want to compare it to the value for the same product to month or year.</p>
<p>To demonstrate both the new and old version I’ll introduce a dataset.</p>
<p>Let’s look at the Vestas share prices. I’ll create a table only with the share prices for Vestas, like so</p>
<blockquote><p>CREATE TABLE [dbo].[Stock]<br />
(<br />
[StockID] [int] IDENTITY(1,1) NOT NULL,<br />
[Name] [nvarchar](50) NULL,<br />
[Date] [datetime] NULL,<br />
[OpeningPrice] [money] NULL,<br />
[High] [money] NULL,<br />
[Low] [money] NULL,<br />
[Last] [money] NULL,<br />
[Volume] [float] NULL<br />
)</p></blockquote>
<p>Then I import the data for the last couple of years from http://www.euroinvestor.dk/. Now we have a realistic dataset.</p>
<p>Let’s look at the closing price for the last 100 days like this:</p>
<blockquote><p>SELECT top 100 StockID, Name, Date, last<br />
FROM dbo.Stock<br />
ORDER BY Date Desc</p></blockquote>
<p>This yield the result<br />
<a href="http://clausoncode.dk/images/2image001.png"><img class="alignnone" src="http://clausoncode.dk/images/2image001.png" alt="" width="315" height="208" /></a></p>
<p>Using the window functions prior to the 2012 version, we could use the window functions like this<br />
<a href="http://clausoncode.dk/images/SQL1.jpg"><img class="alignnone" src="http://clausoncode.dk/images/SQL1.jpg" alt="" width="690" height="260" /></a></p>
<p>Giving this result set<br />
<a href="http://clausoncode.dk/images/2image003.jpg"><img class="alignnone" src="http://clausoncode.dk/images/2image003.jpg" alt="" width="642" height="192" /></a></p>
<p>You can use these values to do more intensive analytics etc.</p>
<p>Of course, the aggregate functions could also be achieved with a subselect, or a join to the same SQL statement grouped on the same as it is partitioned by in window functions, but this would for obvious reasons perform worse and yield a more complicated SQL.</p>
<p>The aggregate functions also provide the same as what will be performed by analysis services, when you are build a data mart with aggregated values.</p>
<p>The Row number is often used in data collection scenarios where you want to filter out duplicates.</p>
<p><strong>The 2012 version</strong></p>
<p>So, that is how window functions worked prior to the 2012 edition. So lets look at some of the things they have improved. First of all, the syntax has been extended as shown below:</p>
<blockquote><p>OVER (<br />
[ &lt;PARTITION BY clause&gt; ]<br />
[ &lt;ORDER BY clause&gt; ]<br />
[ &lt;ROW or RANGE clause&gt; ]<br />
)</p>
<p>&lt;PARTITION BY clause&gt; ::=<br />
PARTITION BY value_expression , &#8230; [ n ]</p>
<p>&lt;ORDER BY clause&gt; ::=<br />
ORDER BY order_by_expression<br />
[ COLLATE collation_name ]<br />
[ ASC | DESC ]<br />
[ ,...n ]</p>
<p>&lt;ROW or RANGE clause&gt; ::=<br />
{ ROWS | RANGE } &lt;window frame extent&gt;</p>
<p>&lt;window frame extent&gt; ::=<br />
{ &lt;window frame preceding&gt;<br />
| &lt;window frame between&gt;<br />
}</p>
<p>&lt;window frame between&gt; ::=<br />
BETWEEN &lt;window frame bound&gt; AND &lt;window frame bound&gt;</p>
<p>&lt;window frame bound&gt; ::=<br />
{ &lt;window frame preceding&gt;<br />
| &lt;window frame following&gt;<br />
}</p>
<p>&lt;window frame preceding&gt; ::=<br />
{<br />
UNBOUNDED PRECEDING<br />
| &lt;unsigned_value_specification&gt; PRECEDING<br />
| CURRENT ROW<br />
}</p>
<p>&lt;window frame following&gt; ::=<br />
{<br />
UNBOUNDED FOLLOWING<br />
| &lt;unsigned_value_specification&gt; FOLLOWING<br />
| CURRENT ROW<br />
}</p>
<p>&lt;unsigned value specification&gt; ::=<br />
{ &lt;unsigned integer literal&gt; }</p></blockquote>
<p>As you may have noticed, one of the short comings prior to the 2012 version is that you can’t add an ‘order by’ to the aggregate functions, hence you can’t calculate a running AVG or SUM. That has been changed in the new version. Let’s try to add an order by to the previous SQL. And let’s just delete the collumns that makes no sense. So the SQL will look like so:</p>
<p><a href="http://clausoncode.dk/images/SQL2.jpg"><img class="alignnone" src="http://clausoncode.dk/images/SQL2.jpg" alt="" width="649" height="105" /></a></p>
<p>Then we have a running AVG in each month.<br />
<a href="http://clausoncode.dk/images/2image004.png"><img class="alignnone" src="http://clausoncode.dk/images/2image004.png" alt="" width="393" height="236" /></a></p>
<p>All of my examples probably don’t make much sense to a stock broker. I’m only looking at the SQL functions, and not the data. One thing I do know, is however, that the running AVG won’t make much sense, starting all over from the first each month. Luckily there has also been added a sliding window function, so we can look at the previous/next n rows when doing our calculations.</p>
<p>This can now be done like so.<br />
<a href="http://clausoncode.dk/images/SQL3.jpg"><img class="alignnone" src="http://clausoncode.dk/images/SQL3.jpg" alt="" width="767" height="83" /></a></p>
<p>Where the AVG now is the AVG of the current row, and the 2 previous rows. The extension of the ORDER BY, now overrides the default partitioning.  The result set:<br />
<a href="http://clausoncode.dk/images/2image005.png"><img class="alignnone" src="http://clausoncode.dk/images/2image005.png" alt="" width="382" height="233" /></a></p>
<p><strong>Conclusion</strong></p>
<p>I have looked into some of the new window functions, and it is safe to say, that they have been significantly improved, and can now be used to do more advanced analytics in a simpler way.<br />
A new addition to the window functions is also some new analytic functions that can be used. This is: CUME_DIST, LEAD, FIRST_VALUE, PERCENTILE_CONT, LAG, PERCENTILE_DISC, LAST_VALUE, PERCENT_RANK.</p>
<p>I’ll cover those in the next blog post.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://clausoncode.dk/wp/?feed=rss2&#038;p=210</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Unboxing MS SQL Server 2012 – Installing the database server and the Adventure works databases</title>
		<link>http://clausoncode.dk/wp/?p=200</link>
		<comments>http://clausoncode.dk/wp/?p=200#comments</comments>
		<pubDate>Thu, 05 Apr 2012 18:48:36 +0000</pubDate>
		<dc:creator>Claus</dc:creator>
				<category><![CDATA[Unboxing MS SQL Server 2012]]></category>

		<guid isPermaLink="false">http://clausoncode.dk/wp/?p=200</guid>
		<description><![CDATA[The new MS SQL server version 2012 was released not so long ago. With this article series, I will log my first experiences with it, regarding installation and setup, new features, look and feel etc. First things first. Let’s install it. If you don’t have a developer edition in you company, download a trial version [...]]]></description>
			<content:encoded><![CDATA[<p>The new MS SQL server version 2012 was released not so long ago. With this article series, I will log my first experiences with it, regarding installation and setup, new features, look and feel etc.</p>
<p>First things first. Let’s install it. If you don’t have a developer edition in you company, download a trial version from MS’s <a href="http://www.microsoft.com/sqlserver/en/us/get-sql-server/try-it.aspx" target="_blank">website</a>.</p>
<p>Just download the ISO, and install it from there.</p>
<div class="wp-caption alignnone" style="width: 395px"><a href="http://clausoncode.dk/images/image002.jpg"><img title="Figure 1 – download it" src="http://clausoncode.dk/images/image002.jpg" alt="Figure 1 – download it" width="385" height="261" /></a><p class="wp-caption-text">Figure 1 – download it</p></div>
<p>&nbsp;</p>
<div class="wp-caption alignnone" style="width: 245px"><a href="http://clausoncode.dk/images/image003.png"><img title="Figure 2 - Double click setup.exe" src="http://clausoncode.dk/images/image003.png" alt="Figure 2 - Double click setup.exe" width="235" height="169" /></a><p class="wp-caption-text">Figure 2 - Double click setup.exe</p></div>
<p>&nbsp;</p>
<div class="wp-caption alignnone" style="width: 323px"><a href="http://clausoncode.dk/images/image004.png"><img title="Figure 3 – installation process looks the same as previous version -&gt; Clik New SQL server stand alone installation" src="http://clausoncode.dk/images/image004.png" alt="Figure 3 – installation process looks the same as previous version -&gt; Clik New SQL server stand alone installation" width="313" height="91" /></a><p class="wp-caption-text">Figure 3 – installation process looks the same as previous version -&gt; Clik New SQL server stand alone installation</p></div>
<p>&nbsp;</p>
<div class="wp-caption alignnone" style="width: 503px"><a href="http://clausoncode.dk/images/image006.png"><img title="Figure 4 – If you downloaded the Trial version as me, select the evaluation version" src="http://clausoncode.dk/images/image006.png" alt="Figure 4 – If you downloaded the Trial version as me, select the evaluation version" width="493" height="368" /></a><p class="wp-caption-text">Figure 4 – If you downloaded the Trial version as me, select the evaluation version</p></div>
<p>&nbsp;</p>
<div class="wp-caption alignnone" style="width: 503px"><a href="http://clausoncode.dk/images/image008.png"><img title="Figure 5 – Let’s just select SQL server feature installation" src="http://clausoncode.dk/images/image008.png" alt="Figure 5 – Let’s just select SQL server feature installation" width="493" height="371" /></a><p class="wp-caption-text">Figure 5 – Let’s just select SQL server feature installation</p></div>
<p>&nbsp;</p>
<p>After this, just click through with the default setting and start the installation.</p>
<p>After the installation, you can log on to the database server with SQL Server Management Studio (SSMS). Not much to see now, except from a more pretty interface, that looks as though it is part of Visual Studio 2010.</p>
<p>All development is now done visual studio 2010, and there are a lot of improvements, but more of that in a later article. Let’s first get some databases to work with. Let’s Install <strong>the adventureworks databases</strong>.</p>
<p>Apparently in 2012, there is no install file to install the databases. Instead you can download the mdf files separately from codeplex, and attach them. Do It here: <a href="http://msftdbprodsamples.codeplex.com/">http://msftdbprodsamples.codeplex.com/</a></p>
<p>Let’s just start with the two relational databases.</p>
<div class="wp-caption alignnone" style="width: 590px"><a href="http://clausoncode.dk/images/image010.png"><img title="Figure 6 – Right click on databases-&gt;Select attach database, and select the downloaded mdf files. The OLTP  and the DWH databases." src="http://clausoncode.dk/images/image010.png" alt="Figure 6 – Right click on databases-&gt;Select attach database, and select the downloaded mdf files. The OLTP  and the DWH databases." width="580" height="377" /></a><p class="wp-caption-text">Figure 6 – Right click on databases-&gt;Select attach database, and select the downloaded mdf files. The OLTP and the DWH databases.</p></div>
<p>&nbsp;</p>
<p>We are now ready to explore the new SQL features. We&#8217;ll start with that in the next blog post.</p>
]]></content:encoded>
			<wfw:commentRss>http://clausoncode.dk/wp/?feed=rss2&#038;p=200</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Search text in SP</title>
		<link>http://clausoncode.dk/wp/?p=185</link>
		<comments>http://clausoncode.dk/wp/?p=185#comments</comments>
		<pubDate>Sun, 05 Feb 2012 10:13:07 +0000</pubDate>
		<dc:creator>Claus</dc:creator>
				<category><![CDATA[MS SQL Server]]></category>

		<guid isPermaLink="false">http://clausoncode.dk/wp/?p=185</guid>
		<description><![CDATA[*Just as a note to myself* I’ve just joined a big project with thousands of stored procedures. To get an overview of it, it would be nice if I could get the SP’s which inserted data in to table a, or update column b in table c etc. That is easily done, like so: SELECT [...]]]></description>
			<content:encoded><![CDATA[<p>*Just as a note to myself*</p>
<p>I’ve just joined a big project with thousands of stored procedures. To get an overview of it, it would be nice if I could get the SP’s which inserted data in to table a, or update column b in table c etc.</p>
<p>That is easily done, like so:</p>
<blockquote><p>SELECT Name<br />
FROM sys.procedures<br />
WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE &#8216;%table a%&#8217;</p></blockquote>
<p>and</p>
<blockquote><p>SELECT Name<br />
FROM sys.procedures<br />
WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE &#8216;%column b%&#8217;<br />
AND OBJECT_DEFINITION(OBJECT_ID) LIKE &#8216;%table c %&#8217;</p></blockquote>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://clausoncode.dk/wp/?feed=rss2&#038;p=185</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MS, seriously!!!  SSIS and System.Runtime.InteropServices.COMException (0x800A03EC)</title>
		<link>http://clausoncode.dk/wp/?p=180</link>
		<comments>http://clausoncode.dk/wp/?p=180#comments</comments>
		<pubDate>Fri, 27 Jan 2012 08:58:53 +0000</pubDate>
		<dc:creator>Claus</dc:creator>
				<category><![CDATA[Integration services 2005/2008]]></category>

		<guid isPermaLink="false">http://clausoncode.dk/wp/?p=180</guid>
		<description><![CDATA[Let me describe my problem. Maybe you have the same, if you have googled for the error code, and found this page. So, I&#8217;m downloading an old Excel file from a German webpage. The Excel file is in a spreadsheetML format, which is impossible to read from SSIS. No worries, I can easily with a [...]]]></description>
			<content:encoded><![CDATA[<p>Let me describe my problem. Maybe you have the same, if you have googled for the error code, and found this page.</p>
<p>So, I&#8217;m downloading an old Excel file from a German webpage. The Excel file is in a spreadsheetML format, which is impossible to read from SSIS.</p>
<p>No worries, I can easily with a script task, convert the file to CSV, using C# and the Excel API. Like so</p>
<blockquote><p>&#8230;.<br />
using MS.Internal.Xml;<br />
using Microsoft.Office.Interop.Excel;<br />
&#8230;&#8230;.</p>
<p>Microsoft.Office.Interop.Excel.Workbook wb1 ;<br />
Microsoft.Office.Interop.Excel.Application wb2 =<br />
new Microsoft.Office.Interop.Excel.Application();<br />
wb2.DisplayAlerts = false;<br />
wb1 = (Microsoft.Office.Interop.Excel.Workbook)wb2.Workbooks._Open(filename, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);</p>
<p>if (wb1.FileFormat == Microsoft.Office.Interop.Excel.XlFileFormat.xlXMLSpreadsheet)<br />
{<br />
wb1.SaveAs(filename.Replace(&#8220;.xls&#8221;,&#8221;.csv&#8221;) , Microsoft.Office.Interop.Excel.XlFileFormat.xlCSVMSDOS , Type.Missing, Type.Missing, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,false,false,false,false,false);<br />
}<br />
else<br />
{<br />
wb2.Workbooks.Close();<br />
}<br />
wb2.Workbooks.Close();</p></blockquote>
<p>Now I can read the data with a SSIS CSV data source. This Works fine, when I run my SSIS package from BIDS. When I put it in to production, and run the package with the SQL server agent, I get the following error:</p>
<blockquote><p>Service cannot be started. System.Runtime.InteropServices.COMException (0x800A03EC): Microsoft Office Excel cannot access the file &#8216;c:\XXXX&#8217;. There are several possible reasons:<br />
• The file name or path does not exist.<br />
• The file is being used by another program.<br />
• The workbook you are trying to save has the same name as a currently open workbook.</p></blockquote>
<p>None of the above is my problem. I think I tried everything to find a solution to the problem. It turns out, that it is a bug in windows server 2008. There are some different solutions on the web, which include changing the registry values on the server.</p>
<p>Since I&#8217;m a consultant, and hence an expensive resource, I would like not to fuck anything up, playing around with registry values.</p>
<p>I found an easier fix however. Apparently, the folder C:\Windows\SysWOW64\config\systemprofile\Desktop has been removed from Windows server 2008. It was present in windows server 2003.</p>
<p>When I created the folder, everything worked fine. Apparently the desktop folder is necessary, if you want to manipulate Excel files with code from the SQL server agent. Scary.</p>
<p>So, the answer: if you have problems manipulating office files from code executed from the SQL server agent on windows server 2008 create the folder C:\Windows\SysWOW64\config\systemprofile\Desktop (C:\Windows\System32\config\systemprofile\Desktop if it is 32bit)</p>
<p>That was it for now. Bye bye:-)</p>
]]></content:encoded>
			<wfw:commentRss>http://clausoncode.dk/wp/?feed=rss2&#038;p=180</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OLE DB error: OLE DB or ODBC error: Invalid column name &#8216;x&#8217;.; 42S22.</title>
		<link>http://clausoncode.dk/wp/?p=179</link>
		<comments>http://clausoncode.dk/wp/?p=179#comments</comments>
		<pubDate>Tue, 06 Jul 2010 08:18:31 +0000</pubDate>
		<dc:creator>Claus</dc:creator>
				<category><![CDATA[Analysis services 2008]]></category>

		<guid isPermaLink="false">http://clausoncode.dk/wp/?p=179</guid>
		<description><![CDATA[After spending time debugging my analysis services cube for the second time having this error, I guess it will be a good idea to blog about it, so I can remember it to another time I got the above error after I had modified a dimension, so used it three fields for the key, instead [...]]]></description>
			<content:encoded><![CDATA[<p>After spending time debugging my analysis services cube for the second time having this error, I guess it will be a good idea to blog about it, so I can remember it to another time <img src='http://clausoncode.dk/wp/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>I got the above error after I had modified a dimension, so used it three fields for the key, instead of one. I made the relationship from my facts, based on the 3 keys, and then I deployed and processed the cube. And then I got the above error. </p>
<p>The reason for the error is, that I had the partitions for the fact table, based on some SQL sentences, and I had forgotten to modify these  partitions after I had made the new relation. </p>
<p>So the conclusion: When you get the error &#8220;Invalid column name &#8216;x&#8217;.; 42S22&#8243; in analysis services, it is a problem related to the partitions design.</p>
]]></content:encoded>
			<wfw:commentRss>http://clausoncode.dk/wp/?feed=rss2&#038;p=179</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Warning: Null value is eliminated by an aggregate or other SET operation</title>
		<link>http://clausoncode.dk/wp/?p=176</link>
		<comments>http://clausoncode.dk/wp/?p=176#comments</comments>
		<pubDate>Tue, 04 May 2010 20:37:46 +0000</pubDate>
		<dc:creator>Claus</dc:creator>
				<category><![CDATA[Integration services 2005/2008]]></category>

		<guid isPermaLink="false">http://clausoncode.dk/wp/?p=176</guid>
		<description><![CDATA[I just had a SSIS package that had been running every day for the last couple of years without any problems, which failed on me with the following error message: Warning: Null value is eliminated by an aggregate or other SET operation The SQL source had a group by, where I was taking a minimum [...]]]></description>
			<content:encoded><![CDATA[<p>I just had a SSIS package that had been running every day for the last couple of years without any problems, which failed on me with the following error message:</p>
<blockquote><p>Warning: Null value is eliminated by an aggregate or other SET operation</p></blockquote>
<p>The SQL source had a group by, where I was taking a minimum on some datetime fields. I needed it to return NULL values because I had some additional logic that took these NULL values into account.</p>
<p>What was even stranger was, that when I ran the package by double clicking it on the server, it completed with success.</p>
<p>So apparently a warning from the SQL server causes an error in SSIS, but only sometimes….. Nice….</p>
<p>The solution is to either change your SQL, so you don’t get NULL values, by for instance use COALESCE or ISNULL, or if you can’t do that, put this statement in front of your SQL : SET ANSI_WARNINGS OFF</p>
<p>Read more about the problem/bug here:<br />
<a href="https://connect.microsoft.com/SQLServer/feedback/details/483175/failure-because-of-warning-about-null-aggregation">https://connect.microsoft.com/SQLServer/feedback/details/483175/failure-because-of-warning-about-null-aggregation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://clausoncode.dk/wp/?feed=rss2&#038;p=176</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[rsAggregateOfMixedDataTypes] The Value expression for &#8216;x&#8217; uses an aggregate function on data of varying data types.  Aggregate functions other than First, Last, Previous, Count, and CountDistinct can only aggregate data of a single data type</title>
		<link>http://clausoncode.dk/wp/?p=174</link>
		<comments>http://clausoncode.dk/wp/?p=174#comments</comments>
		<pubDate>Wed, 17 Mar 2010 13:59:12 +0000</pubDate>
		<dc:creator>Claus</dc:creator>
				<category><![CDATA[Reporting services 2008]]></category>

		<guid isPermaLink="false">http://clausoncode.dk/wp/?p=174</guid>
		<description><![CDATA[Yet another irritating error message from reporting services You will typically get that error, when you try to create a calculated member in the visual designer like so: IIF( [Measures].[x]=0 , [Measures].[y] , 0,00) And then use the SUM or another aggregate function on the new measure. If you create the same calculated member in [...]]]></description>
			<content:encoded><![CDATA[<p>Yet another irritating error message from reporting services <img src='http://clausoncode.dk/wp/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>You will typically get that error, when you try to create a calculated member in the visual designer like so:</p>
<blockquote><p>IIF( [Measures].[x]=0 , [Measures].[y] , 0,00)</p></blockquote>
<p>And then use the SUM or another aggregate function on the new measure.</p>
<p>If you create the same calculated member in pure MDX, and run it in for instance management studio, it will not yield any errors. Like so:</p>
<blockquote><p>WITH MEMBER [Measures].[z] AS<br />
IIF( [Measures].[x]=0 ,<br />
[Measures].[y] , 0,00)</p></blockquote>
<p>Just to describe the calculated member in words. If the measure x equals 0, then the new measure z will be the value of the measure y, and if the measure x not equals 0, then the new measure z will take the value of 0,00.<br />
The problem is that, when reporting services SUM the new measure z, it Sums data from y and 0,00, and reporting services will in some cases see the values as different data types. In my example the measure x was a decimal, and reporting services interpreted the 0,00 as an integer.</p>
<p>To avoid this problem, you have to tell reporting services that 0,00 is a decimal like this:</p>
<blockquote><p>IIF( [Measures].[x]=0 , [Measures].[y] ,  Cdec(  0,00))</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://clausoncode.dk/wp/?feed=rss2&#038;p=174</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What BI frontend tool in Sharepoint 2010 should I use?</title>
		<link>http://clausoncode.dk/wp/?p=169</link>
		<comments>http://clausoncode.dk/wp/?p=169#comments</comments>
		<pubDate>Sat, 13 Mar 2010 23:51:00 +0000</pubDate>
		<dc:creator>Claus</dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[Sharepoint]]></category>

		<guid isPermaLink="false">http://clausoncode.dk/wp/?p=169</guid>
		<description><![CDATA[In regards to my earlier link to the power pivot blog post, that compared analysis services to power pivot, and discussed when to use what, I also have to throw in a link that compares all the front end BI tools in sharepoint 2010, and discuss when to use what there. You can find a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://perfmon.dk/bi.jpg" target="_blank"><img class="alignright" title="Frontend tools for sharepoint 2010" src="http://perfmon.dk/bi.jpg" alt="" width="293" height="230" /></a>In regards to my earlier link to the power pivot blog post, that compared analysis services to power pivot, and discussed when to use what, I also have to throw in a link that compares all the front end BI tools in sharepoint 2010, and discuss when to use what there.</p>
<p>You can find a great overview of the frontend tools here:</p>
<p><a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=fc97d587-ffa4-4b43-b77d-958f3f8a87b9#filelist">http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=fc97d587-ffa4-4b43-b77d-958f3f8a87b9#filelist</a></p>
<p>There are a lot of possibilities, and my short advice is: Don’t try to use them all at once, even though you think you have a big project, which needs it all. Start by identifying what tool you need the most. You will properly be able to create most of what you need with that. Don’t throw a lot of different reports after the users. They will be confused when they get more advanced drill through possibilities in performance point services, than they for instance do in an excel services report, and they will get confused when they can’t export their performance point services report to PDF, the same way they can with for instance reporting services.</p>
]]></content:encoded>
			<wfw:commentRss>http://clausoncode.dk/wp/?feed=rss2&#038;p=169</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

