<?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>SQL Slayer &#187; Uncategorized</title>
	<atom:link href="http://www.sqlslayer.com/wp/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sqlslayer.com/wp</link>
	<description>Making SQL do what we want it to do.</description>
	<lastBuildDate>Wed, 18 Aug 2010 14:11:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>“RowGUID is neither a DataColumn nor a DataRelation for table summary. (System.Data)”</title>
		<link>http://www.sqlslayer.com/wp/2010/01/08/%e2%80%9crowguid-is-neither-a-datacolumn-nor-a-datarelation-for-table-summary-system-data%e2%80%9d/</link>
		<comments>http://www.sqlslayer.com/wp/2010/01/08/%e2%80%9crowguid-is-neither-a-datacolumn-nor-a-datarelation-for-table-summary-system-data%e2%80%9d/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 15:41:12 +0000</pubDate>
		<dc:creator>mlakarj</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA["is neither a DataColumn nor a DataRelation for table summary. (System.Data)”]]></category>
		<category><![CDATA[SQL SERVER 2005]]></category>

		<guid isPermaLink="false">http://www.sqlslayer.com/wp/?p=187</guid>
		<description><![CDATA[<p>We had merge replication in SQL Server 2005 set up that was working fine, except when trying to view conflicts, the Conflict Viewer would give this error: “RowGUID is neither a DataColumn nor a DataRelation for table summary. (System.Data)”.</p>
<p>The source of this it turns out was actually a period in the Publication name, as we [...]]]></description>
			<content:encoded><![CDATA[<p>We had merge replication in SQL Server 2005 set up that was working fine, except when trying to view conflicts, the Conflict Viewer would give this error: “RowGUID is neither a DataColumn nor a DataRelation for table summary. (System.Data)”.</p>
<p>The source of this it turns out was actually a period in the Publication name, as we had a “6.1” as part of the name.  Other special characters would probably also cause trouble.  </p>
<p>The only way to fix this was to drop the replication, resolve known conflicts manually with a data compare, recreate the replication, and reinitialize.  After that, we could use the Conflict Viewer to resolve conflicts successfully.  </p>
<p>This was a frustrating issue since the replication was allowed to be created with the period and worked completely fine, only the Conflict Viewer experienced trouble and it gave an error that did not accurately describe the issue.</p>
<p>The moral of the story is:  don’t create a publication with a period in the name.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sqlslayer.com/wp/2010/01/08/%e2%80%9crowguid-is-neither-a-datacolumn-nor-a-datarelation-for-table-summary-system-data%e2%80%9d/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Aggregate to CSV</title>
		<link>http://www.sqlslayer.com/wp/2009/11/06/aggregate-to-csv/</link>
		<comments>http://www.sqlslayer.com/wp/2009/11/06/aggregate-to-csv/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 20:25:53 +0000</pubDate>
		<dc:creator>mlakarj</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Aggregate to Comma Separated List]]></category>
		<category><![CDATA[Aggregate to Comma Separated Values]]></category>
		<category><![CDATA[Aggregate to CSV]]></category>
		<category><![CDATA[Comma Separated List]]></category>
		<category><![CDATA[Comma Separated Values]]></category>
		<category><![CDATA[Concatenating Rows]]></category>
		<category><![CDATA[CSV]]></category>
		<category><![CDATA[Rollup to Comma Separated List]]></category>
		<category><![CDATA[Rollup to Comma Separated Values]]></category>
		<category><![CDATA[Rollup to CSV]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.sqlslayer.com/wp/?p=131</guid>
		<description><![CDATA[<p>Sometimes we need to rollup string values into lists of comma separated values.  Using “FOR XML PATH” per column that you want to rollup can provide a way to do this.</p>
<p>This example was created based on work in this thread:
http://www.sqlservercentral.com/Forums/Topic802508-1672-1.aspx</p>
<p>Let’s say you have a data set like so:</p>


id
fruit
city


101
Apple
Cleveland


101
Apple
Pittsburgh


101
Banana
Pittsburgh


102
Grape
Cleveland


102
Melon
Cleveland


103
Melon
Pittsburgh


103
Melon
Cleveland


<p>and for each distinct “id”, you want [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes we need to rollup string values into lists of comma separated values.  Using “FOR XML PATH” per column that you want to rollup can provide a way to do this.</p>
<p>This example was created based on work in this thread:<br />
<a href="http://www.sqlservercentral.com/Forums/Topic802508-1672-1.aspx">http://www.sqlservercentral.com/Forums/Topic802508-1672-1.aspx</a></p>
<p>Let’s say you have a data set like so:</p>
<table border="2">
<tr>
<td><strong>id</strong></td>
<td><strong>fruit</strong></td>
<td><strong>city</strong></td>
</tr>
<tr>
<td>101</td>
<td>Apple</td>
<td>Cleveland</td>
</tr>
<tr>
<td>101</td>
<td>Apple</td>
<td>Pittsburgh</td>
</tr>
<tr>
<td>101</td>
<td>Banana</td>
<td>Pittsburgh</td>
</tr>
<tr>
<td>102</td>
<td>Grape</td>
<td>Cleveland</td>
</tr>
<tr>
<td>102</td>
<td>Melon</td>
<td>Cleveland</td>
</tr>
<tr>
<td>103</td>
<td>Melon</td>
<td>Pittsburgh</td>
</tr>
<tr>
<td>103</td>
<td>Melon</td>
<td>Cleveland</td>
</tr>
</table>
<p>and for each distinct “id”, you want a list of its distinct fruits and cities.  </p>
<p>If you put a FOR XML PATH statement for each column you want to rollup like so:</p>
<blockquote><p><code>...<br />
----------fruit---------<br />
,STUFF((SELECT DISTINCT ', ' + NULLIF(fruit,'')<br />
FROM tableToCSVRollup t2<br />
WHERE t1.id = t2.id<br />
FOR XML PATH(''),TYPE<br />
).value('.','VARCHAR(MAX)')<br />
,1,2,'') AS fruit<br />
...</code></p></blockquote>
<p>and then GROUP BY id, you’ll have a nice aggregated set.  It will even put it in alphabetical order and remove NULL and empty string values for you.</p>
<p>Complete code example:</p>
<blockquote><p><code>;WITH tableToCSVRollup (id,fruit,city)<br />
AS (<br />
		  SELECT 101,'Apple','Cleveland'<br />
UNION ALL SELECT 101,'Apple','Pittsburgh'<br />
UNION ALL SELECT 101,'Banana','Pittsburgh'<br />
UNION ALL SELECT 102,'Grape','Cleveland'<br />
UNION ALL SELECT 102,'Melon','Cleveland'<br />
UNION ALL SELECT 103,'Melon','Pittsburgh'<br />
UNION ALL SELECT 103,'Melon','Cleveland'<br />
)</p>
<p>SELECT<br />
id<br />
----------fruit---------<br />
,STUFF((SELECT DISTINCT ', ' + NULLIF(fruit,'')<br />
FROM tableToCSVRollup t2<br />
WHERE t1.id = t2.id<br />
FOR XML PATH(''),TYPE<br />
).value('.','VARCHAR(MAX)')<br />
,1,2,'') AS fruit<br />
----------city----------<br />
,STUFF((SELECT DISTINCT ', ' + NULLIF(city,'')<br />
FROM tableToCSVRollup t2<br />
WHERE t1.id = t2.id<br />
FOR XML PATH(''),TYPE<br />
).value('.','VARCHAR(MAX)')<br />
,1,2,'') AS city<br />
------------------------<br />
FROM tableToCSVRollup t1<br />
GROUP BY id<br />
ORDER BY id</code></p></blockquote>
<p>Results:</p>
<table border="2">
<tr>
<td><strong>id</strong></td>
<td><strong>fruit</strong></td>
<td><strong>city</strong></td>
</tr>
<tr>
<td>101</td>
<td>Apple, Banana</td>
<td>Cleveland, Pittsburgh</td>
</tr>
<tr>
<td>102</td>
<td>Grape, Melon</td>
<td>Cleveland</td>
</tr>
<tr>
<td>103</td>
<td>Melon</td>
<td>Cleveland, Pittsburgh</td>
</tr>
</table>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sqlslayer.com/wp/2009/11/06/aggregate-to-csv/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Memory Leak in For Loop Container?</title>
		<link>http://www.sqlslayer.com/wp/2009/10/13/memory-leak-in-for-loop-container/</link>
		<comments>http://www.sqlslayer.com/wp/2009/10/13/memory-leak-in-for-loop-container/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 01:44:55 +0000</pubDate>
		<dc:creator>buckleyc</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.sqlslayer.com/wp/?p=129</guid>
		<description><![CDATA[<p>Today, as I was working on a project, I found an opportunity to use the For Loop Container. The basic setup, was three tables, A, B, C for simplicity. </p>
<p>Table A is the Header, Table B a sub-header related to table A via an ID, and Table C related to Table B via an id. [...]]]></description>
			<content:encoded><![CDATA[<p>Today, as I was working on a project, I found an opportunity to use the For Loop Container. The basic setup, was three tables, A, B, C for simplicity. </p>
<p>Table A is the Header, Table B a sub-header related to table A via an ID, and Table C related to Table B via an id. I wanted to loop through the Id&#8217;s in table B one at a time due to the amount of data. I pulled in TableAId, MinTableBId and MaxTableBId into an object variable, Using  For Each Loop Container, I wanted to loop through each TableAId and then loop through each  TableBId, pulling records from Table C one at a time. I decided to drop a For Loop Container into the For Each Loop Container. Initially, there was no issue, everything looped through. As the iterations increased, my laptop stopped responding. I was able to see the memory was sitting at 500 megs&#8230;then 600&#8230; eventually topping out around 850 megs (There is only 1 gig of RAM on the laptop I use at work.). By this time, I had to kill the task.</p>
<p>I thought maybe it was a fluke, so I restarted (when in doubt restart right=)). Cleaned out the tables and ran again. Same result.</p>
<p>After ripping out the for loop, and using a different technique, 150 megs of RAM was consumed. I plan on doing some more tests to see if I can find more useful information for everyone, but I wanted to post this as a caution to be careful with a For Loop Container. This is with SQL 2005 SP2.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sqlslayer.com/wp/2009/10/13/memory-leak-in-for-loop-container/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Generating a Date Dimension the easy way</title>
		<link>http://www.sqlslayer.com/wp/2009/10/07/generating-a-date-dimension-the-easy-way/</link>
		<comments>http://www.sqlslayer.com/wp/2009/10/07/generating-a-date-dimension-the-easy-way/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 02:02:50 +0000</pubDate>
		<dc:creator>buckleyc</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Data Warehouse]]></category>
		<category><![CDATA[Date Dimension]]></category>
		<category><![CDATA[Dimensional Modeling]]></category>

		<guid isPermaLink="false">http://www.sqlslayer.com/wp/?p=106</guid>
		<description><![CDATA[<p>While there are different views on how to build different dimensions, there seems to be a common view of how, at least the basic information, of date dimensions looks. This can take a little time to build out. To help in building this dimension, I created a simple table valued function that takes in a [...]]]></description>
			<content:encoded><![CDATA[<p>While there are different views on how to build different dimensions, there seems to be a common view of how, at least the basic information, of date dimensions looks. This can take a little time to build out. To help in building this dimension, I created a simple table valued function that takes in a start date and returns a date dimension table.</p>
<blockquote><pre>
/*******************************************************************************************************
** Name: dbo.GenerateDateDimension
** Desc: Takes a start date and returns all dates up to the current day as a Date Dimension table.
** Auth: Cliff Buckley (SQLSlayer.com)
** Parameters: @StartDate - The starting date for the date dimension table.
** Dependancies: None
** Notes:
** Date: 10.07.2009
** Example: SELECT * FROM dbo.GenerateDateDimension('1/1/2009')
*******************************************************************************
** Change History
*******************************************************************************
** Date: Author: Description:
** -------- -------- ---------------------------------------
**
********************************************************************************************************/
CREATE FUNCTION dbo.GenerateDateDimension
(
@StartDate datetime
)
RETURNS @DimDate TABLE(DateId int,YearNumber smallint, QuarterNumber tinyint, MonthText varchar(20)
,MonthNumber tinyint,DayNumberOfMonth tinyint, DayOfWeekText varchar(20)
,DayNumberOfYear smallint,SQLDate datetime)
AS
BEGIN
DECLARE @EndDate datetime

SET @EndDate = CAST(CONVERT(varchar(8),getdate(),112) as datetime)

WHILE @StartDate &lt;= @EndDate
BEGIN
INSERT INTO @DimDate(DateId,YearNumber,QuarterNumber,MonthText,MonthNumber,DayNumberOfMonth,DayOfWeekText,DayNumberOfYear,SQLDate)
SELECT CAST(CONVERT(varchar(8),@StartDate,112) AS INT) AS DateId
,DATENAME(year,@StartDate) AS YearNumber
,DATENAME(quarter,@StartDate) AS QuarterNumber
,DATENAME(month,@StartDate) AS MonthText
,MONTH(@StartDate) AS MonthNumber
,DATENAME(day,@StartDate) AS DayOfMonthNumber
,DATENAME(weekday,@StartDate) AS DayOfWeekText
,DATENAME(dayofyear,@StartDate) AS DayNumberOfYear
,@StartDate AS SQLDate
SET @StartDate = DATEADD(d, 1, @StartDate)
END

RETURN;
END
GO
</pre>
</blockquote>
<p>Unfortunately, the formatting is lost, but you get the idea.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sqlslayer.com/wp/2009/10/07/generating-a-date-dimension-the-easy-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
