<?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>Martina Ponca&#039;s Blog</title>
	<atom:link href="http://audaxx.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://audaxx.net</link>
	<description>Notes on database design, business intelligence, ETL, and enterprise reporting using Microsoft SQL Server</description>
	<lastBuildDate>Thu, 10 Nov 2011 06:03:58 +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>Error: Cannot obtain the required interface (&#8220;IID_IDBSchemaRowset&#8221;) from OLE DB provider &#8220;VFPOLEDB&#8221; for linked server</title>
		<link>http://audaxx.net/2011/11/09/error-vfpoledb-iid_idbschemarowset/</link>
		<comments>http://audaxx.net/2011/11/09/error-vfpoledb-iid_idbschemarowset/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 06:03:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL Server 2008 R2]]></category>
		<category><![CDATA[Visual FoxPro]]></category>

		<guid isPermaLink="false">http://audaxx.net/?p=400</guid>
		<description><![CDATA[Environment: Windows XP Professional (32-bit) SSIS 2008 R2 Linked Server: EXEC master.dbo.sp_addlinkedserver @server = N'VFP', @srvproduct=N'foxpro', @provider=N'VFPOLEDB', @datasrc=N'c:\MyFolder\', @provstr=N'VFPOLEDB.1' GO I tried to access the FoxPro files from the linked server but was getting the following error: The OLE DB provider &#8220;VFPOLEDB&#8221; for linked server &#8220;VFP&#8221; reported an error. Access denied. Cannot obtain the required [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Environment: </strong><br />
Windows XP Professional (32-bit)<br />
SSIS 2008 R2<br />
Linked Server: </p>
<pre class="brush: sql">
EXEC master.dbo.sp_addlinkedserver @server = N'VFP',
	@srvproduct=N'foxpro', @provider=N'VFPOLEDB',
	@datasrc=N'c:\MyFolder\', @provstr=N'VFPOLEDB.1'

GO
</pre>
<p>I tried to access the FoxPro files from the linked server but was getting the following error:</p>
<p><em><font colour=red>The OLE DB provider &#8220;VFPOLEDB&#8221; for linked server &#8220;VFP&#8221; reported an error. Access denied. Cannot obtain the required interface (&#8220;IID_IDBSchemaRowset&#8221;) from OLE DB provider &#8220;VFPOLEDB&#8221; for linked server &#8220;VFP&#8221;. (Microsoft SQL Server, Error: 7399)</font></em></p>
<p>When the SQL Server service account run under NETWORK SERVICE or a DOMAIN Account, it didn’t work even though the domain account did have permissions to the FoxPro files. When I changed it to “Local System” it worked. To make it work with a domain account, I found the following answer in <a href="http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/thread/a525b569-77ca-41da-96e1-2ba1938dd32d " target="_blank">http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/thread/a525b569-77ca-41da-96e1-2ba1938dd32d </a></p>
<p>1. Start &#8211;> Run &#8211;> Dcomcnfg<br />
2. Component services &#8211;> My computer &#8211;> DCOM config &#8211;> MSDAINITIALIZE<br />
3. Right click on MSDAINITIALIZE &#8211;> properties &#8211;>security<br />
4. Add the SQL Start-up account ( you may have to go to services in administrative tools under control panel to check log on account) under &#8220;launch and activation permission&#8221;, &#8220;Access permission&#8221; and &#8220;Configuration permission&#8221;.<br />
5. Give full rights.</p>
]]></content:encoded>
			<wfw:commentRss>http://audaxx.net/2011/11/09/error-vfpoledb-iid_idbschemarowset/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Error: Cannot retrieve the column code page info from the OLE DB provider (Visual FoxPro)</title>
		<link>http://audaxx.net/2011/11/09/error-ssis-defaultcodepage-foxpro/</link>
		<comments>http://audaxx.net/2011/11/09/error-ssis-defaultcodepage-foxpro/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 05:46:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL Server 2008 R2]]></category>
		<category><![CDATA[SSIS]]></category>
		<category><![CDATA[Visual FoxPro]]></category>

		<guid isPermaLink="false">http://audaxx.net/?p=394</guid>
		<description><![CDATA[Environment: SQL Server 2008 R2 Integration Services (32-bit) Microsoft OLE DB Provider for Visual FoxPro C:\Program Files\Common Files\System\Ole DB\VfpOleDB.dll 9.0.0.5815 I&#8217;m getting the following error when I click on &#8220;Columns&#8221; while editing OLE DB Source using “Microsoft OLE DB Provider for Visual FoxPro” named “Source – myTable”: Warning: Warning at {….} [Source – myTable]: Cannot [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Environment:</strong><br />
SQL Server 2008 R2 Integration Services (32-bit)<br />
Microsoft OLE DB Provider for Visual FoxPro<br />
C:\Program Files\Common Files\System\Ole DB\VfpOleDB.dll 9.0.0.5815</p>
<p>I&#8217;m getting the following error when I click on &#8220;Columns&#8221; while editing OLE DB Source using “Microsoft OLE DB Provider for Visual FoxPro” named “Source – myTable”:</p>
<p><strong>Warning:</strong><br />
<em>Warning at {….} [Source – myTable]: Cannot retrieve the column code page info from the OLE DB provider. If the component supports the “DefaultCodePage” property, the code page from that property will be used. Change the value of the property if the current string code page values are incorrect. If the component does not support the property, the code page from the component’s locale ID will be used.</em><br />
<strong>Fix: </strong><br />
Edit the properties of the OLE DB Source, [Source – myTable] and set property “AlwaysUseDefaultCodePage” to True.</p>
<p>This error happens because the server does not have a default code page for Visual FoxPro in “C:\Program Files\Microsoft SQL Server\100\DTS\MappingFiles”.</p>
<p>The following blog posting was very helpful: <a href="http://venkattechnicalblog.blogspot.com/2008/07/ssis-errors-part-4.html" target="_blank">http://venkattechnicalblog.blogspot.com/2008/07/ssis-errors-part-4.html</a>. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://audaxx.net/2011/11/09/error-ssis-defaultcodepage-foxpro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Issue: SSIS 2008 R2 &#8211; OLE DB Provider for Visual FoxPro &#8211; OLE DB Source includes DELETED records even if DELETED=True</title>
		<link>http://audaxx.net/2011/11/09/issue-ssis-2008-r2-ole-db-provider-for-visual-foxpro-ole-db-source-includes-deleted-records-even-if-deletedtrue/</link>
		<comments>http://audaxx.net/2011/11/09/issue-ssis-2008-r2-ole-db-provider-for-visual-foxpro-ole-db-source-includes-deleted-records-even-if-deletedtrue/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 04:49:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL Server 2008 R2]]></category>
		<category><![CDATA[SSIS]]></category>
		<category><![CDATA[Visual FoxPro]]></category>

		<guid isPermaLink="false">http://audaxx.net/?p=385</guid>
		<description><![CDATA[I have encountered the following issue and reported it to Microsoft (Bug 697259 on connect.microsoft.ca). It’s marked as “Won’t Fix”, but in case you have the same issue, the workaround might come handy: https://connect.microsoft.com/SQLServer/feedback/details/697259/ssis-2008-r2-ole-db-provider-for-visual-foxpro-ole-db-source-includes-deleted-records-even-if-deleted-true Dev environment: SQL Server 2008 R2 Integration Services (32-bit) Microsoft OLE DB Provider for Visual FoxPro C:\Program Files\Common Files\System\Ole DB\VfpOleDB.dll 9.0.0.5815 [...]]]></description>
			<content:encoded><![CDATA[<p>I have encountered the following issue and reported it to Microsoft (Bug 697259 on connect.microsoft.ca). It’s marked as “Won’t Fix”, but in case you have the same issue, the workaround might come handy: </p>
<p><a href="https://connect.microsoft.com/SQLServer/feedback/details/697259/ssis-2008-r2-ole-db-provider-for-visual-foxpro-ole-db-source-includes-deleted-records-even-if-deleted-true" target="_blank">https://connect.microsoft.com/SQLServer/feedback/details/697259/ssis-2008-r2-ole-db-provider-for-visual-foxpro-ole-db-source-includes-deleted-records-even-if-deleted-true </a></p>
<p><strong>Dev environment:</strong><br />
SQL Server 2008 R2 Integration Services (32-bit)<br />
Microsoft OLE DB Provider for Visual FoxPro<br />
C:\Program Files\Common Files\System\Ole DB\VfpOleDB.dll 9.0.0.5815</p>
<p><strong>Bug: </strong><br />
When I create an SSIS package with “OLE DB Source” using “Microsoft OLE DB Provider for Visual FoxPro”, and for “Data access mode” use “Table or view” deleted records are included even if DELETED=True (means IGNORE DELETED=True). </p>
<p><strong>Workaround:</strong><br />
For “Data access mode” use “SQL Command”, i.e. “select * from myTable”. Deleted records will be excluded. </p>
]]></content:encoded>
			<wfw:commentRss>http://audaxx.net/2011/11/09/issue-ssis-2008-r2-ole-db-provider-for-visual-foxpro-ole-db-source-includes-deleted-records-even-if-deletedtrue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Transformation: Pivot Word to Letters</title>
		<link>http://audaxx.net/2011/10/21/pivot-word-to-letters/</link>
		<comments>http://audaxx.net/2011/10/21/pivot-word-to-letters/#comments</comments>
		<pubDate>Sat, 22 Oct 2011 05:37:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://audaxx.net/?p=379</guid>
		<description><![CDATA[DECLARE @statement NVARCHAR(MAX); SET @statement = N' CREATE FUNCTION [dbo].[SplitWordToLetters] ( @StringToSplit nvarchar(2000) ) RETURNS @RtnValue table ( Id int identity(1,1), Letter NCHAR(1) ) AS BEGIN Declare @substring nvarchar(2000) Declare @letter NCHAR(1) Set @substring = @StringToSplit While (LEN(@substring) > 0) Begin SELECT @letter = LEFT(@substring, 1), @substring = SUBSTRING(@substring, 2, 255) Insert into @RtnValue (Letter) [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: sql">
DECLARE @statement NVARCHAR(MAX);
SET @statement = N'
CREATE FUNCTION [dbo].[SplitWordToLetters]
(
      @StringToSplit nvarchar(2000)
)
RETURNS @RtnValue table
(
      Id int identity(1,1),
      Letter NCHAR(1)
)
AS
BEGIN
      Declare @substring nvarchar(2000)
      Declare @letter NCHAR(1)

      Set @substring = @StringToSplit 

      While (LEN(@substring) > 0)
      Begin
            SELECT @letter = LEFT(@substring, 1), @substring = SUBSTRING(@substring, 2, 255)

            Insert into @RtnValue (Letter) values (@letter)
      End

      Return
END '

IF OBJECT_ID(N'[dbo].[SplitWordToLetters]', N'TF') IS NULL
BEGIN
      EXECUTE (@statement);
END
ELSE
BEGIN
      SET @statement = REPLACE(@Statement, 'CREATE FUNCTION', 'ALTER FUNCTION');
      EXECUTE (@statement);
END
</pre>
<p>Usage:</p>
<pre class="brush: sql">
SELECT *
FROM dbo.SplitWordToLetters ('abc')

/* Result:
Id          Letter
----------- ------
1           a
2           b
3           c

(3 row(s) affected)
*/
</pre>
]]></content:encoded>
			<wfw:commentRss>http://audaxx.net/2011/10/21/pivot-word-to-letters/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Information Dashboard &#8211; SSRS 2008 R2</title>
		<link>http://audaxx.net/2011/02/02/information-dashboard-ssrs-2008-r2/</link>
		<comments>http://audaxx.net/2011/02/02/information-dashboard-ssrs-2008-r2/#comments</comments>
		<pubDate>Wed, 02 Feb 2011 19:32:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Data Visualization]]></category>
		<category><![CDATA[SQL Server 2008 R2]]></category>

		<guid isPermaLink="false">http://www.ilovedata.ca/?p=367</guid>
		<description><![CDATA[If you are already running SQL Server and don’t have too many needs, you can create a dashboard using SQL Server Reporting Services R2. Advantages: No additional cost. Able to visualize data in a table: Indicators, sparklines, data bars and gauges can be used as part of a table. Able to drill-through to existing reports [...]]]></description>
			<content:encoded><![CDATA[<p>If you are already running SQL Server and don’t have too many needs, you can create a dashboard using SQL Server Reporting Services R2.<br />
<br />
<strong>Advantages: </strong></p>
<ul>
<li>No additional cost.</li>
<li>Able to visualize data in a table: Indicators, sparklines, data bars and gauges can be used as part of a table.</li>
<li>Able to drill-through to existing reports</li>
<li>Can access KPIs from SSAS cubes</li>
<li>Many maps, gauges and charts</li>
<li>Able to embed reports/dashboard within a web page or SharePoint</li>
</ul>
<p><strong>With some creativity: </strong></p>
<ul>
<li>Example of custom Gantt Chart: <a href="http://blog.summitcloud.com/2009/11/ssrs-2008-gantt-charts/">http://blog.summitcloud.com/2009/11/ssrs-2008-gantt-charts/</a></li>
<li>Example of custom Heat Map:<br />
<a href="http://theruntime.com/blogs/thomasswilliams/archive/2007/05/04/reporting-services-heatmap.aspx">Thomas Williams: SSRS Heat Maps</a>,<br />
<a href="http://prologika.com/CS/blogs/blog/archive/2009/08/30/heat-maps-as-reports.aspx">Teo Lachev: Heat Maps as Reports</a></li>
<li>Example of using Visio and SSRS Map Reports for Store Layouts <a href="http://blog.oraylis.de/2010/06/using-visio-and-ssrs-map-reports-for-store-layouts-etc/">http://blog.oraylis.de/2010/06/using-visio-and-ssrs-map-reports-for-store-layouts-etc/</a></li>
</ul>
<p><strong>Disadvantages: </strong></p>
<ul>
<li>Unable to dynamically set visibility of parameters (in SSRS, can do it in custom app)</li>
<li>Unable to move the parameters from the top header to right or left (in SSRS, can do it in custom app)</li>
<li>Unable to rename Excel sheets on export</li>
<li>Unable to create dynamic alerts but could schedule Standard or Data-Driven subscription as a workaround that would run on a regular basis.</li>
<li>And more: <a href="http://www.simple-talk.com/sql/reporting-services/ten-common-sql-server-reporting-services-challenges-and-solutions/">http://www.simple-talk.com/sql/reporting-services/ten-common-sql-server-reporting-services-challenges-and-solutions/</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://audaxx.net/2011/02/02/information-dashboard-ssrs-2008-r2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Data Visualization and Information Dashboards</title>
		<link>http://audaxx.net/2011/02/01/data-visualization-and-dashboards/</link>
		<comments>http://audaxx.net/2011/02/01/data-visualization-and-dashboards/#comments</comments>
		<pubDate>Tue, 01 Feb 2011 17:00:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Data Visualization]]></category>
		<category><![CDATA[SQL Server 2008 R2]]></category>

		<guid isPermaLink="false">http://www.ilovedata.ca/?p=328</guid>
		<description><![CDATA[Visual Communication. Data visualization is a way to present an audience with easier to read data and communicate data visually.]]></description>
			<content:encoded><![CDATA[<p><strong>Visual Communication</strong><br />
Data visualization is a way to present an audience with easier to read data and communicate data visually. Based on my experience, these are some of the elements users like:</p>
<ul>
<li>Keep things simple &#8211; simple lines, well organized and easy to view data.</li>
<li>Create summarized data sections that allow users to drill through (to another report) and drill down (usually after clicking “+” sign).</li>
<li>Choose the types of graphs and performance indicators that make sense and are correct for the situation. Use correct labels. Show numbers in a context.</li>
<li>Don’t use too many intense colours, shading and gradient filling as it takes away from data readability. Tone down the colours or use shades of the colour.</li>
<li>Shading and gradient filling might confuse the reader if the shading and gradient filling does not mean anything, and it is done to simply make the report more “exciting”.</li>
<li>Keep colours and pictures across the report or reporting solution consistent (i.e. green indicator is always good, red is bad, yellow is neutral).</li>
<li>Export reports to Excel, Word, PDF, etc. exactly as the user requested.</li>
</ul>
<p>Most of the reports I create contain financial data, and I prefer if the visual representation of that data still looks like a financial report not as a computer game. But, as with everything, it’s important to meet the needs of the audience. Best reports are reports created specifically for a user, department, or company in mind while allowing that user, department, or company give us feedback.</p>
<p><strong>Dashboards vs. Reports<br />
</strong>I have been looking at options to create effective dashboards. Dashboards are different from reports in a way that reports answer specific question your audience asked while dashboard is a single screen that is used to “monitor” what’s going on in some aspect of the business and deals with situation awareness. There are many books out there related to building dashboards. The book that resonates with me is <em><strong>Information Dashboard Design. The Effective Visual Communication of Data</strong></em> by <strong>Stephen Few.</strong> His visualizations just make sense and seem so simple: <a href="http://www.perceptualedge.com/">http://www.perceptualedge.com/</a>. Takes his <a href="http://www.perceptualedge.com/files/GraphDesignIQ.html">Graph Design I.Q. Test</a> and see how you&#8217;ll do.</p>
<p><strong>Dashboard Software Evaluation Criteria:</strong></p>
<ol>
<li>Can the dashboard tool drill through to existing SSRS Reports (reusability)?</li>
<li>Can the dashboard tool access SSAS KPIs?</li>
<li>Does the dashboard tool have (a) its own server, or (b) does it need to be integrated with a web page or SharePoint?</li>
<li>Can I use Active Directory Trusted Security or does it have its own authentication system?</li>
<li>Would I have access to any of these out-of-the-box controls:
<ul>
<li>Strategy Maps</li>
<li>Calendar Component</li>
<li>Bullet Graph</li>
<li>Tree Map</li>
<li>Gantt Chart</li>
<li>Heat Map</li>
<li>Table Inline Charts (sparklines, indicators, bar chart)</li>
<li>Decomposition Tree</li>
</ul>
</li>
<li>What are the options for (a) value filters (dropdowns) , (b)additional tabs and (c) drill troughs?</li>
<li>Ability to create alerts (a) visually on screen, (b) send email or SMS, (c) or trigger some other action.</li>
<li>Initial price and annual support maintenance cost?</li>
<li>Could I use it for mobile BI? Would it run on iPhone or iPad?</li>
</ol>
<p><strong>Dashboard software packages I&#8217;m in the process of reviewing:</strong></p>
<ol>
<li>Microsoft SQL Server Reporting Services 2008 R2</li>
<li>PerformancePoint in Microsoft Office SharePoint Server 2010 (former ProClarity) <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=fc97d587-ffa4-4b43-b77d-958f3f8a87b9&amp;displaylang=en">Getting started with business intelligence in SharePoint Server 2010</a></li>
<li>Dundas Dashboard <a href="http://www.dundas.com">www.dundas.com</a></li>
<li>Tableau Software <a href="http://www.tableausoftware.com">www.tableausoftware.com</a></li>
<li>SAS Software <a href="http://www.sas.com">www.sas.com</a></li>
<li>Xcelsius – SAP Crystal Presentation Design <a href="http://www12.sap.com/solutions/sap-crystal-solutions/freetrials/index.epx">Free Trial Download Page</a></li>
<li>Microsoft Office Excel, PowerPivot &amp; Excel Services (SharePoint)</li>
</ol>
<p>Some of the other BI Tools worth mentioning are MicroStrategy (has mobile BI that will run on iPad), Information Builders, Oracle and Hyperion, SAP Business Objects, IBM Cognos, and Pentaho.</p>
<p>For more BI Tools, see these two article:</p>
<ul>
<li><a href="http://www.computerworld.com/s/article/9200878/The_state_of_BI_tools">ComputerWorld: The state of BI tools</a></li>
<li><a href="http://www.computerworld.com/s/article/9200823/Self_service_BI_catches_on_?taxonomyId=9&amp;pageNumber=1">ComputerWorld: Self-service BI catches on</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://audaxx.net/2011/02/01/data-visualization-and-dashboards/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Transformation: Example of Recursive Query Using Common Table Expressions (CTE WITH)</title>
		<link>http://audaxx.net/2010/09/07/recursive-query-using-common-table-expressions-cte-with/</link>
		<comments>http://audaxx.net/2010/09/07/recursive-query-using-common-table-expressions-cte-with/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 05:19:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[CTE]]></category>
		<category><![CDATA[WITH]]></category>

		<guid isPermaLink="false">http://www.ilovedata.ca/?p=305</guid>
		<description><![CDATA[DECLARE @Temp TABLE (PrimaryKey INT, ParentKey INT) INSERT INTO @Temp (PrimaryKey, ParentKey) SELECT 1, 0 UNION SELECT 2, 1 UNION SELECT 3, 2 UNION SELECT 4, 3; WITH TopParent(PrimaryKey, ParentLevel, ParentKey) AS ( SELECT PrimaryKey, 0, ParentKey FROM @Temp UNION ALL SELECT Temp.PrimaryKey, TP.ParentLevel + 1, TP.ParentKey FROM @Temp Temp INNER JOIN TopParent TP ON [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: sql">
DECLARE @Temp TABLE (PrimaryKey INT, ParentKey INT)

INSERT INTO @Temp (PrimaryKey, ParentKey)
SELECT 1, 0
UNION SELECT 2, 1
UNION SELECT 3, 2
UNION SELECT 4, 3;  

WITH TopParent(PrimaryKey, ParentLevel, ParentKey) AS
(
       SELECT PrimaryKey, 0, ParentKey
       FROM @Temp
       UNION ALL
       SELECT Temp.PrimaryKey, TP.ParentLevel + 1, TP.ParentKey
       FROM @Temp Temp
       INNER JOIN TopParent TP ON TP.PrimaryKey = Temp.ParentKey
)
SELECT Tbl.PrimaryKey, Tbl.MaxLevel, TopParent.ParentKey
FROM TopParent
INNER JOIN (
	SELECT TopParent.PrimaryKey,
		   MAX(TopParent.ParentLevel) AS MaxLevel
	FROM TopParent
	GROUP BY TopParent.PrimaryKey
) Tbl ON Tbl.PrimaryKey = TopParent.PrimaryKey
	AND Tbl.MaxLevel = TopParent.ParentLevel;

/*
PrimaryKey  MaxLevel    ParentKey
----------- ----------- -----------
1           0           0
2           1           0
3           2           0
4           3           0

(4 row(s) affected)
*/
</pre>
]]></content:encoded>
			<wfw:commentRss>http://audaxx.net/2010/09/07/recursive-query-using-common-table-expressions-cte-with/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Transformation: Pivot Columns to Rows using XML</title>
		<link>http://audaxx.net/2010/06/30/pivot-columns-to-rows-using-xml/</link>
		<comments>http://audaxx.net/2010/06/30/pivot-columns-to-rows-using-xml/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 05:13:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SSRS]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://www.ilovedata.ca/?p=289</guid>
		<description><![CDATA[SELECT MyTable.myColumn.value('local-name(.)', 'VARCHAR(100)') AS ColumnHeader, MyTable.myColumn.value('.', 'VARCHAR(MAX)') AS Value FROM ( SELECT ( SELECT * FROM Production.Product WHERE ProductID = 1 FOR XML RAW, TYPE) AS XmlRow )T CROSS APPLY T.XmlRow.nodes('row/@*') AS MyTable(myColumn) I used this idea when creating a Generic Drillthrough Report for SSRS, my query for dataset looked like this: -- the SSRS [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: sql">
SELECT
       MyTable.myColumn.value('local-name(.)', 'VARCHAR(100)') AS ColumnHeader,
       MyTable.myColumn.value('.', 'VARCHAR(MAX)') AS Value
FROM (
       SELECT (
       SELECT *
       FROM Production.Product
       WHERE ProductID = 1
       FOR XML RAW, TYPE) AS XmlRow
)T
CROSS APPLY T.XmlRow.nodes('row/@*') AS MyTable(myColumn)
</pre>
<p>I used this idea when creating a Generic Drillthrough Report  for SSRS, my query for dataset looked like this: </p>
<pre class="brush: sql">
-- the SSRS report has the following parameters
DECLARE @SchemaDotTableOrViewName VARCHAR(200), @PrimaryKeyColumnName VARCHAR(200), @PrimaryKeyValue VARCHAR(20)
SELECT @SchemaDotTableOrViewName = 'Production.Product',
	@PrimaryKeyColumnName = 'ProductID',
	@PrimaryKeyValue = 1

-- dataset query
DECLARE @statement NVARCHAR(MAX)
SET @statement =
N'
SELECT
	MyTable.myColumn.value(''local-name(.)'', ''VARCHAR(100)'') AS ColumnHeader,
	MyTable.myColumn.value(''.'', ''VARCHAR(MAX)'') AS Value
FROM (
	SELECT (
		SELECT *
		FROM ' + @SchemaDotTableOrViewName + '
		WHERE ' + @PrimaryKeyColumnName + ' = ' + @PrimaryKeyValue + '
		FOR XML RAW, TYPE
	) AS XmlRow
) T
CROSS APPLY T.XmlRow.nodes(''row/@*'') AS MyTable(myColumn)
'

EXECUTE dbo.sp_executesql @statement
</pre>
]]></content:encoded>
			<wfw:commentRss>http://audaxx.net/2010/06/30/pivot-columns-to-rows-using-xml/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SSRS 2008 Tips</title>
		<link>http://audaxx.net/2010/05/30/ssrs-2008-tips/</link>
		<comments>http://audaxx.net/2010/05/30/ssrs-2008-tips/#comments</comments>
		<pubDate>Mon, 31 May 2010 05:50:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SSRS]]></category>

		<guid isPermaLink="false">http://www.ilovedata.ca/?p=291</guid>
		<description><![CDATA[Handy shortcuts for SQL 2008: Display multi-valued parameters: - Join(Parameters!Product.Label, vbcrfl) for new line - Join(Parameters!Product.Label, &#8220;,&#8221;) Format Date: - FormatDateTime(Parameters!PaymentStartDate.Value, DateFormat.ShortDate) - &#8220;yyyy-MM-dd HH:mm:ss&#8221; Force report repeat table header on each page: After true true For multi-valued params, determine if user selected &#8220;(Select All)&#8221;: The report should have 1 dataset CountriesDataset and 2 parameters, [...]]]></description>
			<content:encoded><![CDATA[<p>Handy shortcuts for SQL 2008:<br />
Display multi-valued parameters:<br />
	- Join(Parameters!Product.Label, vbcrfl) for new line<br />
	- Join(Parameters!Product.Label, &#8220;,&#8221;)<br />
Format Date:<br />
	- FormatDateTime(Parameters!PaymentStartDate.Value, DateFormat.ShortDate)<br />
	- &#8220;yyyy-MM-dd HH:mm:ss&#8221;</p>
<p>Force report repeat table header on each page:</p>
<pre class="brush: xml">
	<TablixRowHierarchy>
	  <TablixMembers>
		<TablixMember>
		  <KeepWithGroup>After</KeepWithGroup>
		  <RepeatOnNewPage>true</RepeatOnNewPage>
		  <KeepTogether>true</KeepTogether>
		</TablixMember>
		<TablixMember>
		  <Group Name="Details1" />
		</TablixMember>
	  </TablixMembers>
	</TablixRowHierarchy>
</pre>
<p>For multi-valued params, determine if user selected &#8220;(Select All)&#8221;:<br />
The report should have 1 dataset CountriesDataset and 2 parameters, for example:<br />
	- @Countries will be VISIBLE multi-valued parameter and allow users to select countries they&#8217;d like to query<br />
	- @AllCountries will be HIDDEN and &#8220;available&#8221; as well as &#8220;default&#8221; parameters will be set to our CountriesDataset<br />
You pass both params to the stored procedure, in the stored proc, and with a help of your Split funciton, do a check as follows</p>
<pre class="brush: sql">
DECLARE @AllCountriesSelected
SET @AllCountriesSelected =
	(CASE WHEN (SELECT COUNT([Data]) FROM dbo.Split(@Countries, ',')
			= (SELECT COUNT([Data]) FROM dbo.Split(@AllCountries, ',')
		 THEN 1
		 ELSE 0
	END);

-- the query will be something like this
SELECT *
FROM SomeTable
WHERE (
	@AllCountriesSelected = 1
	OR SomeTable.Country IN (SELECT COUNT([Data]) FROM dbo.Split(@Countries, ',')
	)
</pre>
<pre class="brush: vb">
Function CHGetFirstOfMonth ( ByVal Year As Integer, ByVal Month As Integer) As Date

                Dim firstOfMonth as Date
                firstOfMonth = DateValue(Year.ToString() + "-" + Month.ToString()+ "-" + "01")
                Return firstOfMonth
End Function

Function CHGetLastOfMonth ( ByVal Year As Integer, ByVal Month As Integer) As Date

                Dim firstOfMonth as Date
                Dim lastOfMonth as Date

                firstOfMonth = DateValue(Year.ToString() + "-" + Month.ToString()+ "-" + "01")
                lastOfMonth = DateAdd("D", -1, DateAdd("m", 1, firstOfMonth))

                Return lastOfMonth
End Function
</pre>
]]></content:encoded>
			<wfw:commentRss>http://audaxx.net/2010/05/30/ssrs-2008-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Transformation: Dates and Strings</title>
		<link>http://audaxx.net/2010/04/30/transformation-dates-strings/</link>
		<comments>http://audaxx.net/2010/04/30/transformation-dates-strings/#comments</comments>
		<pubDate>Sat, 01 May 2010 06:15:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://www.ilovedata.ca/?p=318</guid>
		<description><![CDATA[-- Create Date declare @year int, @month int, @day int select @year = 2009, @month= 3, @day = 3; select dateadd(mm,(@year-1900)* 12 + @month - 1,0) + (@day -1) [Date] -- Get Last Name out of Full Name string DECLARE @FullName VARCHAR(30), @LastName as VARCHAR(30) SET @FullName = 'Smith,John'; SELECT LastName = SUBSTRING(@FullName, 0, CHARINDEX(',', [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: sql">
-- Create Date
declare @year int, @month int, @day int
select @year = 2009, @month= 3, @day = 3;
select dateadd(mm,(@year-1900)* 12 + @month - 1,0) + (@day -1) [Date]
</pre>
<pre class="brush: sql">
-- Get Last Name out of Full Name string
DECLARE @FullName VARCHAR(30), @LastName as VARCHAR(30)
SET @FullName = 'Smith,John';
SELECT LastName = SUBSTRING(@FullName, 0, CHARINDEX(',', @FullName, 0))
</pre>
]]></content:encoded>
			<wfw:commentRss>http://audaxx.net/2010/04/30/transformation-dates-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

