<?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>zlika&#039;s</title>
	<atom:link href="http://zlika.org/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://zlika.org</link>
	<description>Think SMART!</description>
	<lastBuildDate>Fri, 06 Aug 2010 03:14:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>DENSE_RANK() function in MS SQL Server</title>
		<link>http://zlika.org/index.php/2010/08/04/simple-usage-of-dense_rank-function-in-ms-sql-server/</link>
		<comments>http://zlika.org/index.php/2010/08/04/simple-usage-of-dense_rank-function-in-ms-sql-server/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 04:46:24 +0000</pubDate>
		<dc:creator>zlika</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[SSMS]]></category>

		<guid isPermaLink="false">http://zlika.org/?p=430</guid>
		<description><![CDATA[As we can read in Books Online in SQL Server
Ranking functions return a ranking value for each row in a partition. Depending on the function that is used, some rows might receive the same value as other rows. Ranking functions are nondeterministic.
I have created simple example for usage of the Ranking function DENSE_RANK(). We have [...]]]></description>
			<content:encoded><![CDATA[<p>As we can read in Books Online in SQL Server</p>
<blockquote><p>Ranking functions return a ranking value for each row in a partition. Depending on the function that is used, some rows might receive the same value as other rows. Ranking functions are nondeterministic.</p></blockquote>
<p>I have created simple example for usage of the Ranking function DENSE_RANK(). We have a database with the addresses of all the residents of a city. Many of them have changed their addresses several times. They have changed them by using web application, because the authorities have decided that&#8217;s the most convenient manner for everybody. Down the years, one user may have more then one record (change of address). We need to select only one actual address or only one precedent address per user. We need to partition the table and select only the data we need.</p>
<p>First I create the tables, keys and I populate them.</p>
<pre class="brush: sql;">USE zlika
GO

-- Create Tables and keys
CREATE TABLE [Users]
(
	[ID] INT IDENTITY (1, 1) PRIMARY KEY
	, [FirstName] VARCHAR(50)
	, [LastName] VARCHAR(50)
)
GO

CREATE TABLE [Address]
(
	[ID] INT IDENTITY (1, 1) PRIMARY KEY
	, [UserID] INT
	, [StreetNo] INT
	, [StreetName] VARCHAR(100)
	, [City] VARCHAR(100)
	, [Phone] VARCHAR(25)
	, [DateOfRegistration] DATETIME NULL
)
GO

ALTER TABLE [Address]
WITH CHECK ADD CONSTRAINT
FK_Users_ID FOREIGN KEY
(
	UserID
)
REFERENCES Users
(
	ID
)
GO

ALTER TABLE [Address]
ADD CONSTRAINT DF_Address_DateOfRegistration
	DEFAULT (GETDATE())
	FOR DateOfRegistration
GO

-- Populate Tables
INSERT INTO [Users] (FirstName, LastName) VALUES
('First', 'Smith')
, ('Second', 'George')
, ('Third', 'Thompson')
GO

SELECT * FROM Users
GO

INSERT INTO [Address] (UserID, StreetNo, StreetName, City, Phone) VALUES (1, 111, 'StreetName1', 'City1', 11111)
WAITFOR DELAY '00:00:01'
INSERT INTO [Address] (UserID, StreetNo, StreetName, City, Phone) VALUES (1, 222, 'StreetName2', 'City2', 22222)
WAITFOR DELAY '00:00:01'
INSERT INTO [Address] (UserID, StreetNo, StreetName, City, Phone) VALUES (1, 333, 'StreetName3', 'City3', 33333)
WAITFOR DELAY '00:00:01'
INSERT INTO [Address] (UserID, StreetNo, StreetName, City, Phone) VALUES (1, 444, 'StreetName4', 'City4', 44444)
WAITFOR DELAY '00:00:01'
INSERT INTO [Address] (UserID, StreetNo, StreetName, City, Phone) VALUES (1, 555, 'StreetName5', 'City5', 55555)
WAITFOR DELAY '00:00:01'
INSERT INTO [Address] (UserID, StreetNo, StreetName, City, Phone) VALUES (2, 1111, 'StreetName11', 'City11', 1111111111)
WAITFOR DELAY '00:00:01'
INSERT INTO [Address] (UserID, StreetNo, StreetName, City, Phone) VALUES (2, 2222, 'StreetName22', 'City22', 2222222222)
WAITFOR DELAY '00:00:01'
INSERT INTO [Address] (UserID, StreetNo, StreetName, City, Phone) VALUES (3, 3, 'StreetName333', 'City333', 333)
GO

SELECT * FROM [Address]
GO
</pre>
<p>Users table contains three rows as follow:</p>
<div id="attachment_436" class="wp-caption aligncenter" style="width: 233px"><a href="http://zlika.org/wp-content/uploads/2010/08/01.png" rel="lightbox[430]"><img class="size-full wp-image-436" title="Users Table" src="http://zlika.org/wp-content/uploads/2010/08/01.png" alt="" width="223" height="113" /></a><p class="wp-caption-text">Users Table</p></div>
<p>Address table contains eight rows for these three users:</p>
<div id="attachment_439" class="wp-caption aligncenter" style="width: 619px"><a href="http://zlika.org/wp-content/uploads/2010/08/02.png" rel="lightbox[430]"><img class="size-full wp-image-439" title="Address Table" src="http://zlika.org/wp-content/uploads/2010/08/02.png" alt="" width="609" height="217" /></a><p class="wp-caption-text">Address Table</p></div>
<p>We need to partition the table. That means we need to split the data according to some logic. DANSE_RANK() function does it for us. It split users by their ID (UserID), order the partitions descending by date and adds ranks.</p>
<pre class="brush: sql; highlight: [18,19];">
SELECT
	A.ID
	, A.UserID
	, U.FirstName
	, U.LastName
	, A.StreetNo
	, A.StreetName
	, A.City
	, A.Phone
	, A.DateOfRegistration
	, DENSE_RANK() OVER (PARTITION BY UserID ORDER BY DateOfRegistration DESC) AS [Rank]

FROM
	[Address] AS A
	INNER JOIN dbo.[Users] AS U
		ON A.UserID = U.ID

--WHERE
--	[Rank] = 2
GO
</pre>
<p>The result of the query is the data plus a temporary column for ranking.</p>
<div id="attachment_441" class="wp-caption aligncenter" style="width: 813px"><a href="http://zlika.org/wp-content/uploads/2010/08/03.png" rel="lightbox[430]"><img class="size-full wp-image-441  " title="Adding DENSE_RANK column" src="http://zlika.org/wp-content/uploads/2010/08/03.png" alt="" width="803" height="216" /></a><p class="wp-caption-text">Adding DENSE_RANK column (click on image)</p></div>
<p>If I try to reach the result in single query (uncommenting lines 18 and 19), I&#8217;ll get &#8220;Invalid column name &#8216;Rank&#8217;&#8221; error. The reason is that I generate the [Rank] column during the selection of the data and I can&#8217;t filter it at this time.</p>
<div id="attachment_444" class="wp-caption aligncenter" style="width: 756px"><a href="http://zlika.org/wp-content/uploads/2010/08/04.png" rel="lightbox[430]"><img class="size-full wp-image-444" title="Invalid column name 'Rank'" src="http://zlika.org/wp-content/uploads/2010/08/04.png" alt="" width="746" height="355" /></a><p class="wp-caption-text">Invalid column name &#39;Rank&#39;</p></div>
<p>To get the data that I need, I simulate a View &#8211; create a temporary table and read a filtered data from it.</p>
<pre class="brush: sql;">
USE zlika
GO

CREATE TABLE #Temp
(
	ID INT
	, [UserID] INT
	, [FirstName] VARCHAR(50)
	, [LastName] VARCHAR(50)
	, [StreetNo] INT
	, [StreetName] VARCHAR(100)
	, [City] VARCHAR(100)
	, [Phone] VARCHAR(25)
	, [DateOfRegistration] DATETIME NULL
	, [Rank] INT
)
GO

INSERT INTO #Temp
SELECT
	A.ID
	, A.UserID
	, U.FirstName
	, U.LastName
	, A.StreetNo
	, A.StreetName
	, A.City
	, A.Phone
	, DateOfRegistration, DENSE_RANK() OVER (PARTITION BY UserID ORDER BY DateOfRegistration DESC) AS [Rank]

FROM
	[Address] AS A
	INNER JOIN dbo.[Users] AS U
		ON A.UserID = U.ID
GO

SELECT
	ID
	, UserID
	, FirstName
	, LastName
	, StreetNo
	, StreetName
	, City
	, Phone
	, DateOfRegistration

FROM
	#Temp

WHERE
	[Rank] = 1

ORDER BY
	UserID
GO

DROP TABLE #Temp
GO
</pre>
<p>The result is the last address of the residents. If we need the precedent addresses, we&#8217;ll filter the [Rank] column to equals 2.</p>
<div id="attachment_445" class="wp-caption aligncenter" style="width: 768px"><a href="http://zlika.org/wp-content/uploads/2010/08/05.png" rel="lightbox[430]"><img class="size-full wp-image-445" title="DENSE_RANK result" src="http://zlika.org/wp-content/uploads/2010/08/05.png" alt="" width="758" height="115" /></a><p class="wp-caption-text">DENSE_RANK result</p></div>
<p>Félicitations</p>
<hr size="1" noshade>
<p style="font-family = verdana, tahoma, arial, sans-serif; font-size: 10px;">
<a title="DENSE_RANK() function in MS SQL Server" href="http://zlika.org/index.php/2010/08/04/simple-usage-of-dense_rank-function-in-ms-sql-server/"><b>DENSE_RANK() function in MS SQL Server</b></a> <br />
Author: zlika (Peter Lalovsky), Category: <a href="http://zlika.org/index.php/category/it/" title="View all posts in IT" rel="category tag">IT</a>, <a href="http://zlika.org/index.php/category/it/ms-sql-server/" title="View all posts in MS SQL Server" rel="category tag">MS SQL Server</a>, <a href="http://zlika.org/index.php/category/it/sql/" title="View all posts in SQL" rel="category tag">SQL</a>, <a href="http://zlika.org/index.php/2010/08/04/simple-usage-of-dense_rank-function-in-ms-sql-server/#comments">0 Comments</a>

<br />

Add to:
<a title="Share on Delicious" href="http://del.icio.us/post?url=http://zlika.org/index.php/2010/08/04/simple-usage-of-dense_rank-function-in-ms-sql-server/&title=DENSE_RANK() function in MS SQL Server">Delicious</a> | 
<a title="Share on Facebook" href="http://www.facebook.com/sharer.php?u=http://zlika.org/index.php/2010/08/04/simple-usage-of-dense_rank-function-in-ms-sql-server/&t=DENSE_RANK() function in MS SQL Server">Facebook</a> | 
<a title="Share on Twitter" href="http://twitter.com/home?status=Currently reading http://zlika.org/index.php/2010/08/04/simple-usage-of-dense_rank-function-in-ms-sql-server/">Twitter</a> | <a title="Share on Live" href="http://favorites.live.com/quickadd.aspx?url=http://zlika.org/index.php/2010/08/04/simple-usage-of-dense_rank-function-in-ms-sql-server/&title=DENSE_RANK() function in MS SQL Server">Live</a> | 
<a title="Share on Reddit" href="http://reddit.com/submit?url=http://zlika.org/index.php/2010/08/04/simple-usage-of-dense_rank-function-in-ms-sql-server/&title=DENSE_RANK() function in MS SQL Server">Reddit</a> | 
<a title="Share on Technorati" href="http://www.technorati.com/faves?add=http://zlika.org/index.php/2010/08/04/simple-usage-of-dense_rank-function-in-ms-sql-server/">Technorati</a> | 
<a title="Share on Digg" href="http://digg.com/submit?url=http://zlika.org/index.php/2010/08/04/simple-usage-of-dense_rank-function-in-ms-sql-server/&title=DENSE_RANK() function in MS SQL Server">Digg</a>

<br />

Followers: <a href="http://www.technorati.com/search/http://zlika.org/index.php/2010/08/04/simple-usage-of-dense_rank-function-in-ms-sql-server/" title="Linking blogs to this article, on Technorati">Technorati</a> | <a href="http://www.google.com/blogsearch?hl=en&q=http://zlika.org/index.php/2010/08/04/simple-usage-of-dense_rank-function-in-ms-sql-server/" title="Linking blogs to this article, on Google">Google</a>

<br />

© 2010, <a href="http://zlika.org">zlika&#039;s</a> (<a href="http://zlika.org/index.php/feed/">RSS</a>)
</p>]]></content:encoded>
			<wfw:commentRss>http://zlika.org/index.php/2010/08/04/simple-usage-of-dense_rank-function-in-ms-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>It&#8217;s good to stay only with yourself</title>
		<link>http://zlika.org/index.php/2010/07/29/its-good-to-stay-only-with-yourself/</link>
		<comments>http://zlika.org/index.php/2010/07/29/its-good-to-stay-only-with-yourself/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 02:08:37 +0000</pubDate>
		<dc:creator>zlika</dc:creator>
				<category><![CDATA[Music]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://zlika.org/?p=425</guid>
		<description><![CDATA[&#8230;but not all the time :-)

Félicitations


It&#8217;s good to stay only with yourself 
Author: zlika (Peter Lalovsky), Category: Music, Personal, 0 Comments



Add to:
Delicious &#124; 
Facebook &#124; 
Twitter &#124; Live &#124; 
Reddit &#124; 
Technorati &#124; 
Digg



Followers: Technorati &#124; Google



© 2010, zlika&#039;s (RSS)
]]></description>
			<content:encoded><![CDATA[<p>&#8230;but not all the time :-)</p>
<p><object width="500" height="306"><param name="movie" value="http://www.youtube.com/v/_GqnDROi6l4&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed  src="http://www.youtube.com/v/_GqnDROi6l4&#038;fs=1" type="application/x-shockwave-flash" width="500" height="306" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Félicitations</p>
<hr size="1" noshade>
<p style="font-family = verdana, tahoma, arial, sans-serif; font-size: 10px;">
<a title="It&#8217;s good to stay only with yourself" href="http://zlika.org/index.php/2010/07/29/its-good-to-stay-only-with-yourself/"><b>It&#8217;s good to stay only with yourself</b></a> <br />
Author: zlika (Peter Lalovsky), Category: <a href="http://zlika.org/index.php/category/music/" title="View all posts in Music" rel="category tag">Music</a>, <a href="http://zlika.org/index.php/category/personal/" title="View all posts in Personal" rel="category tag">Personal</a>, <a href="http://zlika.org/index.php/2010/07/29/its-good-to-stay-only-with-yourself/#comments">0 Comments</a>

<br />

Add to:
<a title="Share on Delicious" href="http://del.icio.us/post?url=http://zlika.org/index.php/2010/07/29/its-good-to-stay-only-with-yourself/&title=It&#8217;s good to stay only with yourself">Delicious</a> | 
<a title="Share on Facebook" href="http://www.facebook.com/sharer.php?u=http://zlika.org/index.php/2010/07/29/its-good-to-stay-only-with-yourself/&t=It&#8217;s good to stay only with yourself">Facebook</a> | 
<a title="Share on Twitter" href="http://twitter.com/home?status=Currently reading http://zlika.org/index.php/2010/07/29/its-good-to-stay-only-with-yourself/">Twitter</a> | <a title="Share on Live" href="http://favorites.live.com/quickadd.aspx?url=http://zlika.org/index.php/2010/07/29/its-good-to-stay-only-with-yourself/&title=It&#8217;s good to stay only with yourself">Live</a> | 
<a title="Share on Reddit" href="http://reddit.com/submit?url=http://zlika.org/index.php/2010/07/29/its-good-to-stay-only-with-yourself/&title=It&#8217;s good to stay only with yourself">Reddit</a> | 
<a title="Share on Technorati" href="http://www.technorati.com/faves?add=http://zlika.org/index.php/2010/07/29/its-good-to-stay-only-with-yourself/">Technorati</a> | 
<a title="Share on Digg" href="http://digg.com/submit?url=http://zlika.org/index.php/2010/07/29/its-good-to-stay-only-with-yourself/&title=It&#8217;s good to stay only with yourself">Digg</a>

<br />

Followers: <a href="http://www.technorati.com/search/http://zlika.org/index.php/2010/07/29/its-good-to-stay-only-with-yourself/" title="Linking blogs to this article, on Technorati">Technorati</a> | <a href="http://www.google.com/blogsearch?hl=en&q=http://zlika.org/index.php/2010/07/29/its-good-to-stay-only-with-yourself/" title="Linking blogs to this article, on Google">Google</a>

<br />

© 2010, <a href="http://zlika.org">zlika&#039;s</a> (<a href="http://zlika.org/index.php/feed/">RSS</a>)
</p>]]></content:encoded>
			<wfw:commentRss>http://zlika.org/index.php/2010/07/29/its-good-to-stay-only-with-yourself/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Yes It Is</title>
		<link>http://zlika.org/index.php/2010/07/12/yes-it-is/</link>
		<comments>http://zlika.org/index.php/2010/07/12/yes-it-is/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 15:53:06 +0000</pubDate>
		<dc:creator>zlika</dc:creator>
				<category><![CDATA[Music]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://zlika.org/?p=421</guid>
		<description><![CDATA[


Yes It Is 
Author: zlika (Peter Lalovsky), Category: Music, Personal, 0 Comments



Add to:
Delicious &#124; 
Facebook &#124; 
Twitter &#124; Live &#124; 
Reddit &#124; 
Technorati &#124; 
Digg



Followers: Technorati &#124; Google



© 2010, zlika&#039;s (RSS)
]]></description>
			<content:encoded><![CDATA[<p><object width="500" height="400"><param name="movie" value="http://www.youtube.com/v/qfOrGS2W3ak&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed  src="http://www.youtube.com/v/qfOrGS2W3ak&#038;fs=1" type="application/x-shockwave-flash" width="500" height="400" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<hr size="1" noshade>
<p style="font-family = verdana, tahoma, arial, sans-serif; font-size: 10px;">
<a title="Yes It Is" href="http://zlika.org/index.php/2010/07/12/yes-it-is/"><b>Yes It Is</b></a> <br />
Author: zlika (Peter Lalovsky), Category: <a href="http://zlika.org/index.php/category/music/" title="View all posts in Music" rel="category tag">Music</a>, <a href="http://zlika.org/index.php/category/personal/" title="View all posts in Personal" rel="category tag">Personal</a>, <a href="http://zlika.org/index.php/2010/07/12/yes-it-is/#comments">0 Comments</a>

<br />

Add to:
<a title="Share on Delicious" href="http://del.icio.us/post?url=http://zlika.org/index.php/2010/07/12/yes-it-is/&title=Yes It Is">Delicious</a> | 
<a title="Share on Facebook" href="http://www.facebook.com/sharer.php?u=http://zlika.org/index.php/2010/07/12/yes-it-is/&t=Yes It Is">Facebook</a> | 
<a title="Share on Twitter" href="http://twitter.com/home?status=Currently reading http://zlika.org/index.php/2010/07/12/yes-it-is/">Twitter</a> | <a title="Share on Live" href="http://favorites.live.com/quickadd.aspx?url=http://zlika.org/index.php/2010/07/12/yes-it-is/&title=Yes It Is">Live</a> | 
<a title="Share on Reddit" href="http://reddit.com/submit?url=http://zlika.org/index.php/2010/07/12/yes-it-is/&title=Yes It Is">Reddit</a> | 
<a title="Share on Technorati" href="http://www.technorati.com/faves?add=http://zlika.org/index.php/2010/07/12/yes-it-is/">Technorati</a> | 
<a title="Share on Digg" href="http://digg.com/submit?url=http://zlika.org/index.php/2010/07/12/yes-it-is/&title=Yes It Is">Digg</a>

<br />

Followers: <a href="http://www.technorati.com/search/http://zlika.org/index.php/2010/07/12/yes-it-is/" title="Linking blogs to this article, on Technorati">Technorati</a> | <a href="http://www.google.com/blogsearch?hl=en&q=http://zlika.org/index.php/2010/07/12/yes-it-is/" title="Linking blogs to this article, on Google">Google</a>

<br />

© 2010, <a href="http://zlika.org">zlika&#039;s</a> (<a href="http://zlika.org/index.php/feed/">RSS</a>)
</p>]]></content:encoded>
			<wfw:commentRss>http://zlika.org/index.php/2010/07/12/yes-it-is/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple SSIS Project &#8211; export to flat file, FTP upload, archive (create the package)</title>
		<link>http://zlika.org/index.php/2010/06/06/simple-ssis-project-part-1/</link>
		<comments>http://zlika.org/index.php/2010/06/06/simple-ssis-project-part-1/#comments</comments>
		<pubDate>Sun, 06 Jun 2010 18:26:29 +0000</pubDate>
		<dc:creator>zlika</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://zlika.org/?p=254</guid>
		<description><![CDATA[Microsoft® SQL Server™ Integration Services is the tool that connects the database to the world and works instead of us. I&#8217;ll show you how to extract simple data from the database, store the files in a the file system, rename them, upload them on FTP and report the errors to administrator if any. In this first [...]]]></description>
			<content:encoded><![CDATA[<p>Microsoft® SQL Server™ Integration Services is the tool that connects the database to the world and works instead of us. I&#8217;ll show you how to extract simple data from the database, store the files in a the file system, rename them, upload them on FTP and report the errors to administrator if any. In this first part I will create the package. Next I&#8217;ll implement it into SQL Server.</p>
<p>The steps we need are:<br />
1. Create the directories for storing the files &#8211; C:\Temp\Source\, C:\Temp\ForUpload\, C:\Temp\Archive\. If they already exist, we use them instead of create them<br />
2. Move the files from Source directory to ForUpload directory with changing of the name (adding date and time)<br />
3. Upload the renamed files on FTP server<br />
4. Move the files to Archive folder</p>
<p>First, create a new SSIS project (File &#8211;&gt; New &#8211;&gt; Project) in SQL Server Business Intelligence Development Studio.</p>
<div id="attachment_317" class="wp-caption aligncenter" style="width: 693px"><a href="http://zlika.org/wp-content/uploads/2010/03/011.png" rel="lightbox[254]"><img class="size-full wp-image-317" title="New SSIS Project" src="http://zlika.org/wp-content/uploads/2010/03/011.png" alt="" width="683" height="490" /></a><p class="wp-caption-text">New SSIS Project</p></div>
<p>Rename the package.</p>
<div id="attachment_319" class="wp-caption aligncenter" style="width: 273px"><a href="http://zlika.org/wp-content/uploads/2010/03/021.png" rel="lightbox[254]"><img class="size-full wp-image-319" title="Rename package" src="http://zlika.org/wp-content/uploads/2010/03/021.png" alt="" width="263" height="152" /></a><p class="wp-caption-text">Rename package</p></div>
<p>Create Data Source &#8211; that&#8217;s the place where we will read the data from &#8211; MS SQL Server. In Solution Explorer, right click on Data Sources &#8211;&gt; New Data Source&#8230;</p>
<div id="attachment_321" class="wp-caption aligncenter" style="width: 620px"><a href="http://zlika.org/wp-content/uploads/2010/03/031.png" rel="lightbox[254]"><img class="size-full wp-image-321" title="Create Data Source" src="http://zlika.org/wp-content/uploads/2010/03/031.png" alt="" width="610" height="535" /></a><p class="wp-caption-text">Create Data Source</p></div>
<p>To use the Data Source, I create a New Connection from the existing Data Source. Right click on Connection Managers &#8211;&gt; New Connection From Data Source&#8230;</p>
<div id="attachment_323" class="wp-caption aligncenter" style="width: 393px"><a href="http://zlika.org/wp-content/uploads/2010/03/041.png" rel="lightbox[254]"><img class="size-full wp-image-323" title="Create New Connection from Data Source" src="http://zlika.org/wp-content/uploads/2010/03/041.png" alt="" width="383" height="329" /></a><p class="wp-caption-text">Create New Connection from Data Source</p></div>
<p>Create the global variables for the directories.</p>
<div id="attachment_401" class="wp-caption aligncenter" style="width: 465px"><a href="http://zlika.org/wp-content/uploads/2010/06/06.png" rel="lightbox[254]"><img class="size-full wp-image-401" title="Create global variables" src="http://zlika.org/wp-content/uploads/2010/06/06.png" alt="" width="455" height="131" /></a><p class="wp-caption-text">Create global variables</p></div>
<p style="text-align: center;">
<p>Create the directories &#8211; Source, ForUpload, Archive. Drag the File System Task from Toolbox pane.</p>
<div id="attachment_325" class="wp-caption aligncenter" style="width: 393px"><a href="http://zlika.org/wp-content/uploads/2010/03/051.png" rel="lightbox[254]"><img class="size-full wp-image-325" title="Create Folders" src="http://zlika.org/wp-content/uploads/2010/03/051.png" alt="" width="383" height="373" /></a><p class="wp-caption-text">Create Folders</p></div>
<p>Right click on File System Task to set the properties of the folders.</p>
<div id="attachment_330" class="wp-caption aligncenter" style="width: 608px"><a href="http://zlika.org/wp-content/uploads/2010/03/07.png" rel="lightbox[254]"><img class="size-full wp-image-330 " title="Create Folder" src="http://zlika.org/wp-content/uploads/2010/03/07.png" alt="" width="598" height="541" /></a><p class="wp-caption-text">Create Folder</p></div>
<p>For Exporting the data to flat file, first, I create Data Flow Task.</p>
<div id="attachment_332" class="wp-caption aligncenter" style="width: 599px"><a href="http://zlika.org/wp-content/uploads/2010/03/08.png" rel="lightbox[254]"><img class="size-full wp-image-332" title="Create Data Flow Task" src="http://zlika.org/wp-content/uploads/2010/03/08.png" alt="" width="589" height="159" /></a><p class="wp-caption-text">Create Data Flow Task</p></div>
<p>Data Flow Tab &#8211;&gt; Toolbox &#8211;&gt; Data Flow Sources (ADO NET Source), Data Flow Transformation Source (Sort), Data Flow Destinations.</p>
<p>Edit ADO NET Source. I have written the query in SSMS, but I can build it on this step.</p>
<div id="attachment_334" class="wp-caption aligncenter" style="width: 660px"><a href="http://zlika.org/wp-content/uploads/2010/03/09.png" rel="lightbox[254]"><img class="size-full wp-image-334" title="Edit ADO NET Source" src="http://zlika.org/wp-content/uploads/2010/03/09.png" alt="" width="650" height="636" /></a><p class="wp-caption-text">Edit ADO NET Source</p></div>
<p>Edit Sort</p>
<div id="attachment_338" class="wp-caption aligncenter" style="width: 590px"><a href="http://zlika.org/wp-content/uploads/2010/03/10.png" rel="lightbox[254]"><img class="size-full wp-image-338" title="Edit Sort Transformation" src="http://zlika.org/wp-content/uploads/2010/03/10.png" alt="" width="580" height="618" /></a><p class="wp-caption-text">Edit Sort Transformation</p></div>
<p>Create Flat File Connection &#8211; Delimited</p>
<div id="attachment_339" class="wp-caption aligncenter" style="width: 560px"><a href="http://zlika.org/wp-content/uploads/2010/03/11.png" rel="lightbox[254]"><img class="size-full wp-image-339" title="Create Flat File Connection" src="http://zlika.org/wp-content/uploads/2010/03/11.png" alt="" width="550" height="562" /></a><p class="wp-caption-text">Create Flat File Connection</p></div>
<p>I chose the delimiter ($) in the Columns section</p>
<p>The next step is to rename the files by adding to filename the date and time. I use Foreach Loop Container to cover all the files in the Source folder. I move them to ForUpload folder and rename them in one step. I do it like this, because I need to know on which step the execution is failed and in that case to handle the rest of operations manually.</p>
<div id="attachment_343" class="wp-caption aligncenter" style="width: 598px"><a href="http://zlika.org/wp-content/uploads/2010/03/12.png" rel="lightbox[254]"><img class="size-full wp-image-343" title="Add Foreach Loop Container" src="http://zlika.org/wp-content/uploads/2010/03/12.png" alt="" width="588" height="330" /></a><p class="wp-caption-text">Add Foreach Loop Container</p></div>
<p>Create the local variables for Foreach Loop Container. We need to combine the file path with file name while looping the folder. In the Filename variable we will store the names of the files. To the variable Dir_ForUpload_Filename we will add the date and time.</p>
<div id="attachment_405" class="wp-caption aligncenter" style="width: 610px"><a href="http://zlika.org/wp-content/uploads/2010/06/16.png" rel="lightbox[254]"><img class="size-full wp-image-405" title="Create local variables for File Loop Container" src="http://zlika.org/wp-content/uploads/2010/06/16.png" alt="" width="600" height="189" /></a><p class="wp-caption-text">Create local variables for File Loop Container</p></div>
<p>I create expressions for Dir_ForUpload_FileName and Dir_Source_FileName variables. When I select the variable, the Properties windows (in the down-right corner of the screen) changes.</p>
<div id="attachment_411" class="wp-caption aligncenter" style="width: 402px"><a href="http://zlika.org/wp-content/uploads/2010/06/18.png" rel="lightbox[254]"><img class="size-full wp-image-411" title="Create expression for variable" src="http://zlika.org/wp-content/uploads/2010/06/18.png" alt="" width="392" height="354" /></a><p class="wp-caption-text">Create expression for variable</p></div>
<p>In the Expression field I write the expresisons:</p>
<p>1. Dir_ForUpload_FileName:</p>
<pre class="brush: vb;">
@[User::Dir_ForUpload]
+ SUBSTRING(@[User::FileName], 1, FINDSTRING(@[User::FileName], &quot;.&quot;, 1) - 1)
+ &quot;_&quot;
+ SUBSTRING((DT_WSTR, 30)GETDATE(), 1, 4)
+ &quot;-&quot;
+ SUBSTRING((DT_WSTR, 30)GETDATE(), 6, 2)
+ &quot;-&quot;
+ SUBSTRING((DT_WSTR ,30)GETDATE(), 9, 2)
+ &quot;_&quot;
+ SUBSTRING((DT_WSTR, 30)GETDATE(), 12, 2)
+ SUBSTRING((DT_WSTR, 30)GETDATE(), 15, 2)
+ SUBSTRING((DT_WSTR, 30)GETDATE(), 18, 2)
+ SUBSTRING(@[User::FileName], FINDSTRING(@[User::FileName], &quot;.&quot;, 1), LEN(@[User::FileName]))
</pre>
<p>2. Dir_Source_FileName:</p>
<pre class="brush: vb;">@[User::Dir_Source] +  @[User::FileName]</pre>
<p>Edit Foreach Loop Container. We mark a folder for loop (C:\Temp\Source\). We loop only the .txt files. In Variable Mappings section we add the FileName variable.</p>
<div id="attachment_344" class="wp-caption aligncenter" style="width: 592px"><a href="http://zlika.org/wp-content/uploads/2010/06/13.png" rel="lightbox[254]"><img class="aligncenter size-full wp-image-344" title="Setting Foreach Loop Container" src="http://zlika.org/wp-content/uploads/2010/06/13.png" alt="" width="582" height="556" /></a><p class="wp-caption-text">Setting Foreach Loop Container</p></div>
<p>Setting File System Task (inside the Foreach Loop Container)</p>
<div id="attachment_408" class="wp-caption aligncenter" style="width: 602px"><a href="http://zlika.org/wp-content/uploads/2010/06/14.png" rel="lightbox[254]"><img class="size-full wp-image-408" title="Setting File System Task" src="http://zlika.org/wp-content/uploads/2010/06/14.png" alt="" width="592" height="556" /></a><p class="wp-caption-text">Setting File System Task</p></div>
<p>FTP upload &#8211; drag the Foreach Loop Container and FTP task in it. I create local variable FileName &#8211; the same as in previous step. In Foreach Loop Editor I choose Foreach File Enumerator, C:\Temp\ForUpload\ in Folder field and *.txt in Files field.</p>
<p>Edit FTP task &#8211; I adjust the local and remote paths</p>
<div id="attachment_410" class="wp-caption aligncenter" style="width: 588px"><a href="http://zlika.org/wp-content/uploads/2010/06/17.png" rel="lightbox[254]"><img class="size-full wp-image-410" title="Setting FTP task" src="http://zlika.org/wp-content/uploads/2010/06/17.png" alt="" width="578" height="541" /></a><p class="wp-caption-text">Setting FTP task</p></div>
<p>The next step is loop for placing the files in Archive folder. I won&#8217;t explain it. It&#8217;s the same as the loop, I used to move and rename from Source to ForUpload folder.</p>
<p>The full schema of the objects looks like this:</p>
<div id="attachment_412" class="wp-caption aligncenter" style="width: 645px"><a href="http://zlika.org/wp-content/uploads/2010/06/19.png" rel="lightbox[254]"><img class="size-full wp-image-412" title="All the objects" src="http://zlika.org/wp-content/uploads/2010/06/19.png" alt="" width="635" height="397" /></a><p class="wp-caption-text">All the objects</p></div>
<p>Next I will implement the package into SSMS, I will create Scheduled Job, which will include operator notification. While executing the Job in real-time working enviroment, I will decide whether to add the Send Mail Task in SSIS package.</p>
<p><a title="Source files" href="http://www.zlika.org/wp-content/uploads/2010/06/Move-and-Rename.zip">Source files</a></p>
<p>Félicitations</p>
<hr size="1" noshade>
<p style="font-family = verdana, tahoma, arial, sans-serif; font-size: 10px;">
<a title="Simple SSIS Project &#8211; export to flat file, FTP upload, archive (create the package)" href="http://zlika.org/index.php/2010/06/06/simple-ssis-project-part-1/"><b>Simple SSIS Project &#8211; export to flat file, FTP upload, archive (create the package)</b></a> <br />
Author: zlika (Peter Lalovsky), Category: <a href="http://zlika.org/index.php/category/it/" title="View all posts in IT" rel="category tag">IT</a>, <a href="http://zlika.org/index.php/category/it/ms-sql-server/" title="View all posts in MS SQL Server" rel="category tag">MS SQL Server</a>, <a href="http://zlika.org/index.php/2010/06/06/simple-ssis-project-part-1/#comments">0 Comments</a>

<br />

Add to:
<a title="Share on Delicious" href="http://del.icio.us/post?url=http://zlika.org/index.php/2010/06/06/simple-ssis-project-part-1/&title=Simple SSIS Project &#8211; export to flat file, FTP upload, archive (create the package)">Delicious</a> | 
<a title="Share on Facebook" href="http://www.facebook.com/sharer.php?u=http://zlika.org/index.php/2010/06/06/simple-ssis-project-part-1/&t=Simple SSIS Project &#8211; export to flat file, FTP upload, archive (create the package)">Facebook</a> | 
<a title="Share on Twitter" href="http://twitter.com/home?status=Currently reading http://zlika.org/index.php/2010/06/06/simple-ssis-project-part-1/">Twitter</a> | <a title="Share on Live" href="http://favorites.live.com/quickadd.aspx?url=http://zlika.org/index.php/2010/06/06/simple-ssis-project-part-1/&title=Simple SSIS Project &#8211; export to flat file, FTP upload, archive (create the package)">Live</a> | 
<a title="Share on Reddit" href="http://reddit.com/submit?url=http://zlika.org/index.php/2010/06/06/simple-ssis-project-part-1/&title=Simple SSIS Project &#8211; export to flat file, FTP upload, archive (create the package)">Reddit</a> | 
<a title="Share on Technorati" href="http://www.technorati.com/faves?add=http://zlika.org/index.php/2010/06/06/simple-ssis-project-part-1/">Technorati</a> | 
<a title="Share on Digg" href="http://digg.com/submit?url=http://zlika.org/index.php/2010/06/06/simple-ssis-project-part-1/&title=Simple SSIS Project &#8211; export to flat file, FTP upload, archive (create the package)">Digg</a>

<br />

Followers: <a href="http://www.technorati.com/search/http://zlika.org/index.php/2010/06/06/simple-ssis-project-part-1/" title="Linking blogs to this article, on Technorati">Technorati</a> | <a href="http://www.google.com/blogsearch?hl=en&q=http://zlika.org/index.php/2010/06/06/simple-ssis-project-part-1/" title="Linking blogs to this article, on Google">Google</a>

<br />

© 2010, <a href="http://zlika.org">zlika&#039;s</a> (<a href="http://zlika.org/index.php/feed/">RSS</a>)
</p>]]></content:encoded>
			<wfw:commentRss>http://zlika.org/index.php/2010/06/06/simple-ssis-project-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Outlook 2010 Data File Location</title>
		<link>http://zlika.org/index.php/2010/05/30/outlook-2010-data-file-location/</link>
		<comments>http://zlika.org/index.php/2010/05/30/outlook-2010-data-file-location/#comments</comments>
		<pubDate>Mon, 31 May 2010 01:14:24 +0000</pubDate>
		<dc:creator>zlika</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[MS Office]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Office]]></category>
		<category><![CDATA[Outlook]]></category>

		<guid isPermaLink="false">http://zlika.org/?p=391</guid>
		<description><![CDATA[If you use Outlook 2010 and you prefer to have your data files on external hard drive, you have to point your file location as you add your account manually :-)
Félicitations


Outlook 2010 Data File Location 
Author: zlika (Peter Lalovsky), Category: IT, MS Office, 3 Comments



Add to:
Delicious &#124; 
Facebook &#124; 
Twitter &#124; Live &#124; 
Reddit &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>If you use Outlook 2010 and you prefer to have your data files on external hard drive, you have to point your file location as you add your account manually :-)</p>
<div id="attachment_392" class="wp-caption aligncenter" style="width: 687px"><a href="http://zlika.org/wp-content/uploads/2010/05/Outlook2010.png" rel="lightbox[391]"><img class="size-full wp-image-392 " title="Outlook 2010 Data File Location" src="http://zlika.org/wp-content/uploads/2010/05/Outlook2010.png" alt="" width="677" height="465" /></a><p class="wp-caption-text">Outlook 2010 Data File Location</p></div>
<p>Félicitations</p>
<hr size="1" noshade>
<p style="font-family = verdana, tahoma, arial, sans-serif; font-size: 10px;">
<a title="Outlook 2010 Data File Location" href="http://zlika.org/index.php/2010/05/30/outlook-2010-data-file-location/"><b>Outlook 2010 Data File Location</b></a> <br />
Author: zlika (Peter Lalovsky), Category: <a href="http://zlika.org/index.php/category/it/" title="View all posts in IT" rel="category tag">IT</a>, <a href="http://zlika.org/index.php/category/it/ms-office/" title="View all posts in MS Office" rel="category tag">MS Office</a>, <a href="http://zlika.org/index.php/2010/05/30/outlook-2010-data-file-location/#comments">3 Comments</a>

<br />

Add to:
<a title="Share on Delicious" href="http://del.icio.us/post?url=http://zlika.org/index.php/2010/05/30/outlook-2010-data-file-location/&title=Outlook 2010 Data File Location">Delicious</a> | 
<a title="Share on Facebook" href="http://www.facebook.com/sharer.php?u=http://zlika.org/index.php/2010/05/30/outlook-2010-data-file-location/&t=Outlook 2010 Data File Location">Facebook</a> | 
<a title="Share on Twitter" href="http://twitter.com/home?status=Currently reading http://zlika.org/index.php/2010/05/30/outlook-2010-data-file-location/">Twitter</a> | <a title="Share on Live" href="http://favorites.live.com/quickadd.aspx?url=http://zlika.org/index.php/2010/05/30/outlook-2010-data-file-location/&title=Outlook 2010 Data File Location">Live</a> | 
<a title="Share on Reddit" href="http://reddit.com/submit?url=http://zlika.org/index.php/2010/05/30/outlook-2010-data-file-location/&title=Outlook 2010 Data File Location">Reddit</a> | 
<a title="Share on Technorati" href="http://www.technorati.com/faves?add=http://zlika.org/index.php/2010/05/30/outlook-2010-data-file-location/">Technorati</a> | 
<a title="Share on Digg" href="http://digg.com/submit?url=http://zlika.org/index.php/2010/05/30/outlook-2010-data-file-location/&title=Outlook 2010 Data File Location">Digg</a>

<br />

Followers: <a href="http://www.technorati.com/search/http://zlika.org/index.php/2010/05/30/outlook-2010-data-file-location/" title="Linking blogs to this article, on Technorati">Technorati</a> | <a href="http://www.google.com/blogsearch?hl=en&q=http://zlika.org/index.php/2010/05/30/outlook-2010-data-file-location/" title="Linking blogs to this article, on Google">Google</a>

<br />

© 2010, <a href="http://zlika.org">zlika&#039;s</a> (<a href="http://zlika.org/index.php/feed/">RSS</a>)
</p>]]></content:encoded>
			<wfw:commentRss>http://zlika.org/index.php/2010/05/30/outlook-2010-data-file-location/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Congratulations! You&#8217;ve passed the Exam! :-)</title>
		<link>http://zlika.org/index.php/2010/05/26/congratulations-youve-passed-the-exam/</link>
		<comments>http://zlika.org/index.php/2010/05/26/congratulations-youve-passed-the-exam/#comments</comments>
		<pubDate>Thu, 27 May 2010 03:45:06 +0000</pubDate>
		<dc:creator>zlika</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://zlika.org/?p=386</guid>
		<description><![CDATA[I&#8217;ve passed the Exam 70-431: Microsoft® SQL Server™ 2005 &#8211; Implementation and Maintenance (Transcript ID: 907652, Access Code: 38959BBD) on May 25, 2010 at Prometric Testing Center in Montreal. What&#8217;s next? Microsoft® SQL Server™ + .NET :-)
Félicitations


Congratulations! You&#8217;ve passed the Exam! :-) 
Author: zlika (Peter Lalovsky), Category: Personal, 0 Comments



Add to:
Delicious &#124; 
Facebook &#124; 
Twitter &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve passed the Exam <a href="https://mcp.microsoft.com/authenticate/validatemcp.aspx" target="_blank">70-431: Microsoft® SQL Server™ 2005 &#8211; Implementation and Maintenance</a> <em>(Transcript ID: 907652, Access Code: 38959BBD)</em> on May 25, 2010 at Prometric Testing Center in Montreal. What&#8217;s next? Microsoft® SQL Server™ + .NET :-)</p>
<p>Félicitations</p>
<hr size="1" noshade>
<p style="font-family = verdana, tahoma, arial, sans-serif; font-size: 10px;">
<a title="Congratulations! You&#8217;ve passed the Exam! :-)" href="http://zlika.org/index.php/2010/05/26/congratulations-youve-passed-the-exam/"><b>Congratulations! You&#8217;ve passed the Exam! :-)</b></a> <br />
Author: zlika (Peter Lalovsky), Category: <a href="http://zlika.org/index.php/category/personal/" title="View all posts in Personal" rel="category tag">Personal</a>, <a href="http://zlika.org/index.php/2010/05/26/congratulations-youve-passed-the-exam/#comments">0 Comments</a>

<br />

Add to:
<a title="Share on Delicious" href="http://del.icio.us/post?url=http://zlika.org/index.php/2010/05/26/congratulations-youve-passed-the-exam/&title=Congratulations! You&#8217;ve passed the Exam! :-)">Delicious</a> | 
<a title="Share on Facebook" href="http://www.facebook.com/sharer.php?u=http://zlika.org/index.php/2010/05/26/congratulations-youve-passed-the-exam/&t=Congratulations! You&#8217;ve passed the Exam! :-)">Facebook</a> | 
<a title="Share on Twitter" href="http://twitter.com/home?status=Currently reading http://zlika.org/index.php/2010/05/26/congratulations-youve-passed-the-exam/">Twitter</a> | <a title="Share on Live" href="http://favorites.live.com/quickadd.aspx?url=http://zlika.org/index.php/2010/05/26/congratulations-youve-passed-the-exam/&title=Congratulations! You&#8217;ve passed the Exam! :-)">Live</a> | 
<a title="Share on Reddit" href="http://reddit.com/submit?url=http://zlika.org/index.php/2010/05/26/congratulations-youve-passed-the-exam/&title=Congratulations! You&#8217;ve passed the Exam! :-)">Reddit</a> | 
<a title="Share on Technorati" href="http://www.technorati.com/faves?add=http://zlika.org/index.php/2010/05/26/congratulations-youve-passed-the-exam/">Technorati</a> | 
<a title="Share on Digg" href="http://digg.com/submit?url=http://zlika.org/index.php/2010/05/26/congratulations-youve-passed-the-exam/&title=Congratulations! You&#8217;ve passed the Exam! :-)">Digg</a>

<br />

Followers: <a href="http://www.technorati.com/search/http://zlika.org/index.php/2010/05/26/congratulations-youve-passed-the-exam/" title="Linking blogs to this article, on Technorati">Technorati</a> | <a href="http://www.google.com/blogsearch?hl=en&q=http://zlika.org/index.php/2010/05/26/congratulations-youve-passed-the-exam/" title="Linking blogs to this article, on Google">Google</a>

<br />

© 2010, <a href="http://zlika.org">zlika&#039;s</a> (<a href="http://zlika.org/index.php/feed/">RSS</a>)
</p>]]></content:encoded>
			<wfw:commentRss>http://zlika.org/index.php/2010/05/26/congratulations-youve-passed-the-exam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The difference between WHERE and HAVING filters in SQL Server</title>
		<link>http://zlika.org/index.php/2010/04/26/the-difference-between-where-and-having-filters-in-sql-server/</link>
		<comments>http://zlika.org/index.php/2010/04/26/the-difference-between-where-and-having-filters-in-sql-server/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 02:44:51 +0000</pubDate>
		<dc:creator>zlika</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SSMS]]></category>

		<guid isPermaLink="false">http://zlika.org/?p=367</guid>
		<description><![CDATA[The difference between WHERE and HAVING filters in Transact-SQL queries is that WHERE clause is a filter of all the data, while HAVING filters the GROUP BY data. I&#8217;ve prepared a simple example.

USE zlika
GO

-- Create table
CREATE TABLE test (
	Date DATETIME
	, QTY INT
)
GO

-- Populate table
INSERT INTO test (Date, QTY)
SELECT '2009-05-10', 1
UNION ALL SELECT '2009-05-10', 2
UNION ALL [...]]]></description>
			<content:encoded><![CDATA[<p>The difference between WHERE and HAVING filters in Transact-SQL queries is that WHERE clause is a filter of all the data, while HAVING filters the GROUP BY data. I&#8217;ve prepared a simple example.</p>
<pre class="brush: sql;">
USE zlika
GO

-- Create table
CREATE TABLE test (
	Date DATETIME
	, QTY INT
)
GO

-- Populate table
INSERT INTO test (Date, QTY)
SELECT '2009-05-10', 1
UNION ALL SELECT '2009-05-10', 2
UNION ALL SELECT '2009-05-10', 3
UNION ALL SELECT '2009-05-11', 4
UNION ALL SELECT '2009-05-11', 5
UNION ALL SELECT '2009-05-11', 6
UNION ALL SELECT '2009-05-12', 7
UNION ALL SELECT '2009-05-12', 8
UNION ALL SELECT '2009-05-12', 9
GO

-- Check the table
SELECT
	CONVERT(CHAR(10), Date, 103) AS Date
	, QTY

FROM
	test
GO
</pre>
<p>The content of the table is as follows:</p>
<div id="attachment_369" class="wp-caption aligncenter" style="width: 189px"><a href="http://zlika.org/wp-content/uploads/2010/04/01.png" rel="lightbox[367]"><img src="http://zlika.org/wp-content/uploads/2010/04/01.png" alt="" title="Content of the table" width="179" height="232" class="size-full wp-image-369" /></a><p class="wp-caption-text">Content of the table</p></div>
<p>If we GROUP BY column QTY, the result is different sums of the QTY column:<br />
May 10, 2009, 1 + 2 + 3 = 6<br />
May 11, 2009, 4 + 5 + 6 = 15<br />
May 12, 2009, 7 + 8 + 9 = 24</p>
<pre class="brush: sql;">
USE zlika
GO

-- GROUP BY (no filters)
SELECT
	CONVERT(CHAR(10), Date, 103) AS Date
	, SUM(QTY) AS QTY

FROM
	test

GROUP BY
	Date
GO
</pre>
<div id="attachment_371" class="wp-caption aligncenter" style="width: 183px"><a href="http://zlika.org/wp-content/uploads/2010/04/02.png" rel="lightbox[367]"><img src="http://zlika.org/wp-content/uploads/2010/04/02.png" alt="" title="GROPU BY filter" width="173" height="112" class="size-full wp-image-371" /></a><p class="wp-caption-text">GROPU BY filter</p></div>
<p>If we exclude the &#8217;6&#8242; in the WHERE clause, it&#8217;s gonna be filtered before the grouping of the date. The line No. 6 will be eliminated and the May 11, 2009 will be grouped like 4 + 5 = 9.</p>
<pre class="brush: sql;">
USE zlika
GO

-- GROUP BY (WHERE filter)
SELECT
	CONVERT(CHAR(10), Date, 103) AS Date
	, SUM(QTY) AS QTY

FROM
	test

WHERE
	QTY &lt;&gt; 6

GROUP BY
	Date
GO
</pre>
<div id="attachment_374" class="wp-caption aligncenter" style="width: 184px"><a href="http://zlika.org/wp-content/uploads/2010/04/03.png" rel="lightbox[367]"><img src="http://zlika.org/wp-content/uploads/2010/04/03.png" alt="" title="WHERE filter" width="174" height="115" class="size-full wp-image-374" /></a><p class="wp-caption-text">WHERE filter</p></div>
<p>If we exclude the &#8217;6&#8242; in the HAVING clause, it&#8217;s gonna be filtered after the grouping of the date. The date that has sum of QTY column = 6 will be eliminated and the date May 10, 2009 will miss.</p>
<pre class="brush: sql;">
USE zlika
GO

-- GROUP BY (HAVING filter)
SELECT
	CONVERT(CHAR(10), Date, 103) AS Date
	, SUM(QTY) AS QTY

FROM
	test

GROUP BY
	Date

HAVING
	SUM(QTY) &lt;&gt; 6
GO
</pre>
<div id="attachment_376" class="wp-caption aligncenter" style="width: 179px"><a href="http://zlika.org/wp-content/uploads/2010/04/04.png" rel="lightbox[367]"><img src="http://zlika.org/wp-content/uploads/2010/04/04.png" alt="" title="HAVING filter" width="169" height="92" class="size-full wp-image-376" /></a><p class="wp-caption-text">HAVING filter</p></div>
<p>Clean up the test table.</p>
<pre class="brush: sql;">
USE zlika
GO

-- Clean up
DROP TABLE test
GO
</pre>
<p>Félicitations</p>
<hr size="1" noshade>
<p style="font-family = verdana, tahoma, arial, sans-serif; font-size: 10px;">
<a title="The difference between WHERE and HAVING filters in SQL Server" href="http://zlika.org/index.php/2010/04/26/the-difference-between-where-and-having-filters-in-sql-server/"><b>The difference between WHERE and HAVING filters in SQL Server</b></a> <br />
Author: zlika (Peter Lalovsky), Category: <a href="http://zlika.org/index.php/category/it/" title="View all posts in IT" rel="category tag">IT</a>, <a href="http://zlika.org/index.php/category/it/ms-sql-server/" title="View all posts in MS SQL Server" rel="category tag">MS SQL Server</a>, <a href="http://zlika.org/index.php/category/it/sql/" title="View all posts in SQL" rel="category tag">SQL</a>, <a href="http://zlika.org/index.php/2010/04/26/the-difference-between-where-and-having-filters-in-sql-server/#comments">0 Comments</a>

<br />

Add to:
<a title="Share on Delicious" href="http://del.icio.us/post?url=http://zlika.org/index.php/2010/04/26/the-difference-between-where-and-having-filters-in-sql-server/&title=The difference between WHERE and HAVING filters in SQL Server">Delicious</a> | 
<a title="Share on Facebook" href="http://www.facebook.com/sharer.php?u=http://zlika.org/index.php/2010/04/26/the-difference-between-where-and-having-filters-in-sql-server/&t=The difference between WHERE and HAVING filters in SQL Server">Facebook</a> | 
<a title="Share on Twitter" href="http://twitter.com/home?status=Currently reading http://zlika.org/index.php/2010/04/26/the-difference-between-where-and-having-filters-in-sql-server/">Twitter</a> | <a title="Share on Live" href="http://favorites.live.com/quickadd.aspx?url=http://zlika.org/index.php/2010/04/26/the-difference-between-where-and-having-filters-in-sql-server/&title=The difference between WHERE and HAVING filters in SQL Server">Live</a> | 
<a title="Share on Reddit" href="http://reddit.com/submit?url=http://zlika.org/index.php/2010/04/26/the-difference-between-where-and-having-filters-in-sql-server/&title=The difference between WHERE and HAVING filters in SQL Server">Reddit</a> | 
<a title="Share on Technorati" href="http://www.technorati.com/faves?add=http://zlika.org/index.php/2010/04/26/the-difference-between-where-and-having-filters-in-sql-server/">Technorati</a> | 
<a title="Share on Digg" href="http://digg.com/submit?url=http://zlika.org/index.php/2010/04/26/the-difference-between-where-and-having-filters-in-sql-server/&title=The difference between WHERE and HAVING filters in SQL Server">Digg</a>

<br />

Followers: <a href="http://www.technorati.com/search/http://zlika.org/index.php/2010/04/26/the-difference-between-where-and-having-filters-in-sql-server/" title="Linking blogs to this article, on Technorati">Technorati</a> | <a href="http://www.google.com/blogsearch?hl=en&q=http://zlika.org/index.php/2010/04/26/the-difference-between-where-and-having-filters-in-sql-server/" title="Linking blogs to this article, on Google">Google</a>

<br />

© 2010, <a href="http://zlika.org">zlika&#039;s</a> (<a href="http://zlika.org/index.php/feed/">RSS</a>)
</p>]]></content:encoded>
			<wfw:commentRss>http://zlika.org/index.php/2010/04/26/the-difference-between-where-and-having-filters-in-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Life is what happens to you while you&#8217;re busy making other plans</title>
		<link>http://zlika.org/index.php/2010/04/17/life-is-what-happens-to-you-while-youre-busy-making-other-plans/</link>
		<comments>http://zlika.org/index.php/2010/04/17/life-is-what-happens-to-you-while-youre-busy-making-other-plans/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 18:25:01 +0000</pubDate>
		<dc:creator>zlika</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://zlika.org/?p=353</guid>
		<description><![CDATA[John Lennon said:
Life is what happens to you while you&#8217;re busy making other plans
on the Beautiful Boy song.
I wrote a schema of my plans and what&#8217;s really happening. Now, the scheme, then I&#8217;m gonna explain it.
Explanation: Black &#8211; plans, Red &#8211; reality (favorable), Blue &#8211; reality (unfavorable).
If you think smart, you&#8217;ll be able to walk [...]]]></description>
			<content:encoded><![CDATA[<p><a title="John Lennon" href="http://en.wikipedia.org/wiki/John_Lennon" target="_blank">John Lennon</a> said:</p>
<blockquote><p>Life is what happens to you while you&#8217;re busy making other plans</p></blockquote>
<p>on the <a title="John Lennon - Beautiful Boy" href="http://www.youtube.com/watch?v=Uldu_1-JCJE" target="_blank">Beautiful Boy</a> song.</p>
<p>I wrote a schema of my plans and what&#8217;s really happening. Now, the scheme, then I&#8217;m gonna explain it.</p>
<div id="attachment_357" class="wp-caption aligncenter" style="width: 512px"><a href="http://zlika.org/wp-content/uploads/2010/04/plans.jpg" rel="lightbox[353]"><img class="size-full wp-image-357" title="Plans" src="http://zlika.org/wp-content/uploads/2010/04/plans.jpg" alt="Simple schema of our plans" width="502" height="345" /></a><p class="wp-caption-text">Plans</p></div>
<address>Explanation: Black &#8211; plans, Red &#8211; reality (favorable), Blue &#8211; reality (unfavorable).</address>
<p>If you think smart, you&#8217;ll be able to walk near the red path. It&#8217;s no good when the blue path persists.</p>
<p>In the next month I&#8217;ll take a walk on the red curve and in the same time I&#8217;am preparing myself for a <a title="Microsoft SQL Server 2005 - Implementation and Maintenance" href="http://www.microsoft.com/learning/en/us/exams/70-431.mspx" target="_blank">hard exam</a>.</p>
<p>Why?</p>
<p><object width="500" height="400"><param name="movie" value="http://www.youtube.com/v/njG7p6CSbCU&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed  src="http://www.youtube.com/v/njG7p6CSbCU&#038;fs=1" type="application/x-shockwave-flash" width="500" height="400" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Félicitations</p>
<hr size="1" noshade>
<p style="font-family = verdana, tahoma, arial, sans-serif; font-size: 10px;">
<a title="Life is what happens to you while you&#8217;re busy making other plans" href="http://zlika.org/index.php/2010/04/17/life-is-what-happens-to-you-while-youre-busy-making-other-plans/"><b>Life is what happens to you while you&#8217;re busy making other plans</b></a> <br />
Author: zlika (Peter Lalovsky), Category: <a href="http://zlika.org/index.php/category/personal/" title="View all posts in Personal" rel="category tag">Personal</a>, <a href="http://zlika.org/index.php/2010/04/17/life-is-what-happens-to-you-while-youre-busy-making-other-plans/#comments">0 Comments</a>

<br />

Add to:
<a title="Share on Delicious" href="http://del.icio.us/post?url=http://zlika.org/index.php/2010/04/17/life-is-what-happens-to-you-while-youre-busy-making-other-plans/&title=Life is what happens to you while you&#8217;re busy making other plans">Delicious</a> | 
<a title="Share on Facebook" href="http://www.facebook.com/sharer.php?u=http://zlika.org/index.php/2010/04/17/life-is-what-happens-to-you-while-youre-busy-making-other-plans/&t=Life is what happens to you while you&#8217;re busy making other plans">Facebook</a> | 
<a title="Share on Twitter" href="http://twitter.com/home?status=Currently reading http://zlika.org/index.php/2010/04/17/life-is-what-happens-to-you-while-youre-busy-making-other-plans/">Twitter</a> | <a title="Share on Live" href="http://favorites.live.com/quickadd.aspx?url=http://zlika.org/index.php/2010/04/17/life-is-what-happens-to-you-while-youre-busy-making-other-plans/&title=Life is what happens to you while you&#8217;re busy making other plans">Live</a> | 
<a title="Share on Reddit" href="http://reddit.com/submit?url=http://zlika.org/index.php/2010/04/17/life-is-what-happens-to-you-while-youre-busy-making-other-plans/&title=Life is what happens to you while you&#8217;re busy making other plans">Reddit</a> | 
<a title="Share on Technorati" href="http://www.technorati.com/faves?add=http://zlika.org/index.php/2010/04/17/life-is-what-happens-to-you-while-youre-busy-making-other-plans/">Technorati</a> | 
<a title="Share on Digg" href="http://digg.com/submit?url=http://zlika.org/index.php/2010/04/17/life-is-what-happens-to-you-while-youre-busy-making-other-plans/&title=Life is what happens to you while you&#8217;re busy making other plans">Digg</a>

<br />

Followers: <a href="http://www.technorati.com/search/http://zlika.org/index.php/2010/04/17/life-is-what-happens-to-you-while-youre-busy-making-other-plans/" title="Linking blogs to this article, on Technorati">Technorati</a> | <a href="http://www.google.com/blogsearch?hl=en&q=http://zlika.org/index.php/2010/04/17/life-is-what-happens-to-you-while-youre-busy-making-other-plans/" title="Linking blogs to this article, on Google">Google</a>

<br />

© 2010, <a href="http://zlika.org">zlika&#039;s</a> (<a href="http://zlika.org/index.php/feed/">RSS</a>)
</p>]]></content:encoded>
			<wfw:commentRss>http://zlika.org/index.php/2010/04/17/life-is-what-happens-to-you-while-youre-busy-making-other-plans/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chinese Democracy &#8211; Sorry</title>
		<link>http://zlika.org/index.php/2010/04/05/chinese-democracy-sorry/</link>
		<comments>http://zlika.org/index.php/2010/04/05/chinese-democracy-sorry/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 06:05:58 +0000</pubDate>
		<dc:creator>zlika</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://zlika.org/?p=348</guid>
		<description><![CDATA[The interesting thing about me is&#8230; Several days ago I received a letter from Microsoft. They presented me a voucher for an exam. Now I&#8217;m preparing myself for this exam. It&#8217;s a hard one, but I learn a lot :-)
Yesterday my sister told me that Slash is preparing something interesting&#8230; From song to song I [...]]]></description>
			<content:encoded><![CDATA[<p>The interesting thing about me is&#8230; Several days ago I received a letter from <a title="Microsoft" href="http://www.microsoft.com" target="_blank">Microsoft</a>. They presented me a voucher for an exam. Now I&#8217;m preparing myself for this exam. It&#8217;s a hard one, but I learn a lot :-)</p>
<p>Yesterday my sister told me that Slash is preparing <a title="Slash" href="http://slashonline.com" target="_blank">something interesting</a>&#8230; From song to song I reached &#8220;<a title="Chinese Democracy" href="http://en.wikipedia.org/wiki/Chinese_Democracy" target="_blank">Chinese Democracy</a>&#8221; by <a title="Guns N Roses" href="http://web.gunsnroses.com" target="_blank">Guns N Roses</a>. The only one thing that binds &#8220;Chinese Democracy&#8221; and Guns N Roses is <a title="Axl Rose" href="http://en.wikipedia.org/wiki/Axl_Rose" target="_blank">Axl Rose</a>. He has worked a lot and the result is&#8230; Great! Axl proved that he is a great musician! I will be nice surprised if Slash shows us something so good as &#8220;Chinese Democracy&#8221;</p>
<p><object width="500" height="400"><param name="movie" value="http://www.youtube.com/v/XP2VRQuANQQ&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed  src="http://www.youtube.com/v/XP2VRQuANQQ&#038;fs=1" type="application/x-shockwave-flash" width="500" height="400" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Félicitations</p>
<hr size="1" noshade>
<p style="font-family = verdana, tahoma, arial, sans-serif; font-size: 10px;">
<a title="Chinese Democracy &#8211; Sorry" href="http://zlika.org/index.php/2010/04/05/chinese-democracy-sorry/"><b>Chinese Democracy &#8211; Sorry</b></a> <br />
Author: zlika (Peter Lalovsky), Category: <a href="http://zlika.org/index.php/category/personal/" title="View all posts in Personal" rel="category tag">Personal</a>, <a href="http://zlika.org/index.php/2010/04/05/chinese-democracy-sorry/#comments">0 Comments</a>

<br />

Add to:
<a title="Share on Delicious" href="http://del.icio.us/post?url=http://zlika.org/index.php/2010/04/05/chinese-democracy-sorry/&title=Chinese Democracy &#8211; Sorry">Delicious</a> | 
<a title="Share on Facebook" href="http://www.facebook.com/sharer.php?u=http://zlika.org/index.php/2010/04/05/chinese-democracy-sorry/&t=Chinese Democracy &#8211; Sorry">Facebook</a> | 
<a title="Share on Twitter" href="http://twitter.com/home?status=Currently reading http://zlika.org/index.php/2010/04/05/chinese-democracy-sorry/">Twitter</a> | <a title="Share on Live" href="http://favorites.live.com/quickadd.aspx?url=http://zlika.org/index.php/2010/04/05/chinese-democracy-sorry/&title=Chinese Democracy &#8211; Sorry">Live</a> | 
<a title="Share on Reddit" href="http://reddit.com/submit?url=http://zlika.org/index.php/2010/04/05/chinese-democracy-sorry/&title=Chinese Democracy &#8211; Sorry">Reddit</a> | 
<a title="Share on Technorati" href="http://www.technorati.com/faves?add=http://zlika.org/index.php/2010/04/05/chinese-democracy-sorry/">Technorati</a> | 
<a title="Share on Digg" href="http://digg.com/submit?url=http://zlika.org/index.php/2010/04/05/chinese-democracy-sorry/&title=Chinese Democracy &#8211; Sorry">Digg</a>

<br />

Followers: <a href="http://www.technorati.com/search/http://zlika.org/index.php/2010/04/05/chinese-democracy-sorry/" title="Linking blogs to this article, on Technorati">Technorati</a> | <a href="http://www.google.com/blogsearch?hl=en&q=http://zlika.org/index.php/2010/04/05/chinese-democracy-sorry/" title="Linking blogs to this article, on Google">Google</a>

<br />

© 2010, <a href="http://zlika.org">zlika&#039;s</a> (<a href="http://zlika.org/index.php/feed/">RSS</a>)
</p>]]></content:encoded>
			<wfw:commentRss>http://zlika.org/index.php/2010/04/05/chinese-democracy-sorry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Perfect Circle &#8211; The Package</title>
		<link>http://zlika.org/index.php/2010/03/07/a-perfect-circle-the-package/</link>
		<comments>http://zlika.org/index.php/2010/03/07/a-perfect-circle-the-package/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 07:18:47 +0000</pubDate>
		<dc:creator>zlika</dc:creator>
				<category><![CDATA[Music]]></category>

		<guid isPermaLink="false">http://zlika.org/?p=310</guid>
		<description><![CDATA[If you are not capable to hear the fireflies in the night, don&#8217;t push &#8216;play&#8217; :-)

Félicitations


A Perfect Circle &#8211; The Package 
Author: zlika (Peter Lalovsky), Category: Music, 0 Comments



Add to:
Delicious &#124; 
Facebook &#124; 
Twitter &#124; Live &#124; 
Reddit &#124; 
Technorati &#124; 
Digg



Followers: Technorati &#124; Google



© 2010, zlika&#039;s (RSS)
]]></description>
			<content:encoded><![CDATA[<p>If you are not capable to hear the fireflies in the night, don&#8217;t push &#8216;play&#8217; :-)</p>
<p><object width="500" height="400"><param name="movie" value="http://www.youtube.com/v/ZNdl_vOrPbM&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed  src="http://www.youtube.com/v/ZNdl_vOrPbM&#038;fs=1" type="application/x-shockwave-flash" width="500" height="400" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Félicitations</p>
<hr size="1" noshade>
<p style="font-family = verdana, tahoma, arial, sans-serif; font-size: 10px;">
<a title="A Perfect Circle &#8211; The Package" href="http://zlika.org/index.php/2010/03/07/a-perfect-circle-the-package/"><b>A Perfect Circle &#8211; The Package</b></a> <br />
Author: zlika (Peter Lalovsky), Category: <a href="http://zlika.org/index.php/category/music/" title="View all posts in Music" rel="category tag">Music</a>, <a href="http://zlika.org/index.php/2010/03/07/a-perfect-circle-the-package/#comments">0 Comments</a>

<br />

Add to:
<a title="Share on Delicious" href="http://del.icio.us/post?url=http://zlika.org/index.php/2010/03/07/a-perfect-circle-the-package/&title=A Perfect Circle &#8211; The Package">Delicious</a> | 
<a title="Share on Facebook" href="http://www.facebook.com/sharer.php?u=http://zlika.org/index.php/2010/03/07/a-perfect-circle-the-package/&t=A Perfect Circle &#8211; The Package">Facebook</a> | 
<a title="Share on Twitter" href="http://twitter.com/home?status=Currently reading http://zlika.org/index.php/2010/03/07/a-perfect-circle-the-package/">Twitter</a> | <a title="Share on Live" href="http://favorites.live.com/quickadd.aspx?url=http://zlika.org/index.php/2010/03/07/a-perfect-circle-the-package/&title=A Perfect Circle &#8211; The Package">Live</a> | 
<a title="Share on Reddit" href="http://reddit.com/submit?url=http://zlika.org/index.php/2010/03/07/a-perfect-circle-the-package/&title=A Perfect Circle &#8211; The Package">Reddit</a> | 
<a title="Share on Technorati" href="http://www.technorati.com/faves?add=http://zlika.org/index.php/2010/03/07/a-perfect-circle-the-package/">Technorati</a> | 
<a title="Share on Digg" href="http://digg.com/submit?url=http://zlika.org/index.php/2010/03/07/a-perfect-circle-the-package/&title=A Perfect Circle &#8211; The Package">Digg</a>

<br />

Followers: <a href="http://www.technorati.com/search/http://zlika.org/index.php/2010/03/07/a-perfect-circle-the-package/" title="Linking blogs to this article, on Technorati">Technorati</a> | <a href="http://www.google.com/blogsearch?hl=en&q=http://zlika.org/index.php/2010/03/07/a-perfect-circle-the-package/" title="Linking blogs to this article, on Google">Google</a>

<br />

© 2010, <a href="http://zlika.org">zlika&#039;s</a> (<a href="http://zlika.org/index.php/feed/">RSS</a>)
</p>]]></content:encoded>
			<wfw:commentRss>http://zlika.org/index.php/2010/03/07/a-perfect-circle-the-package/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
