<?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 &#187; IT</title>
	<atom:link href="http://zlika.org/index.php/category/it/feed/" rel="self" type="application/rss+xml" />
	<link>http://zlika.org</link>
	<description>Think SMART!</description>
	<lastBuildDate>Sat, 08 Oct 2011 15:38:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>How to store UTF-8 data in SQL Server</title>
		<link>http://zlika.org/index.php/2011/03/06/how-to-store-utf-8-data-in-sql-server/</link>
		<comments>http://zlika.org/index.php/2011/03/06/how-to-store-utf-8-data-in-sql-server/#comments</comments>
		<pubDate>Sun, 06 Mar 2011 22:09:02 +0000</pubDate>
		<dc:creator>zlika</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[SSMS]]></category>
		<category><![CDATA[Transact-SQL]]></category>

		<guid isPermaLink="false">http://zlika.org/?p=704</guid>
		<description><![CDATA[Very frequently we need to use the data type UTF-8 to store a data in different languages. As described in the MSDN page the UTF-8 data type is stored in the &#8216;Samples&#8217; folder in SQL Server (Server\100\Samples\Engine\Programmability\CLR\UTF8String). You just need to activate it.

Create data type UTF-8
1. Generate a strong name key file
1.1. Open Command Prompt [...]]]></description>
			<content:encoded><![CDATA[<p>Very frequently we need to use the data type UTF-8 to store a data in different languages. As described in the <a title="Readme_UTF8 UDT Sample" href="http://msdn.microsoft.com/en-us/library/ms160893(SQL.100).aspx" target="_blank">MSDN page</a> the UTF-8 data type is stored in the &#8216;Samples&#8217; folder in SQL Server (Server\100\Samples\Engine\Programmability\CLR\UTF8String). You just need to activate it.</p>
<p><span id="more-704"></span><br />
<strong><span style="text-decoration: underline;">Create data type UTF-8</span></strong></p>
<p><strong>1. Generate a strong name key file</strong><br />
1.1. Open Command Prompt (Start &#8211;&gt; Run &#8211;&gt; &#8216;cmd&#8217;)<br />
1.2. Change directory (C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin)<br />
1.3. Generate the key (C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin&gt;sn -k &#8220;C:\Program Files\Microsoft SQL Server\100\Samples\SampleKey.snk&#8221;)</p>
<p><strong>2. Build the sample</strong><br />
2.1. Open Microsoft Visual Studio<br />
2.2. Open &#8216;C:\Program Files\Microsoft SQL Server\100\Samples\Engine\Programmability\CLR\UTF8String\CS\UTF8String.sln&#8217;<br />
2.3. Build &#8211;&gt; Build UTF8String</p>
<p><strong>3. Install UTF-8 data type</strong><br />
3.1. Open SQL Server Management Studio<br />
3.2. Open &#8216;C:\Program Files\Microsoft SQL Server\100\Samples\Engine\Programmability\CLR\UTF8String\Scripts\InstallCS.sql&#8217;<br />
3.3. Execute it<br />
3.4. Test UTF-8 data type (C:\Program Files\Microsoft SQL Server\100\Samples\Engine\Programmability\CLR\UTF8String\Scripts\Test.sql)<br />
3.4.1. Fix the error message &#8216;<span style="color: #ff0000;">Msg 6263, Level 16, State 1, Line 2<br />
Execution of user code in the .NET Framework is disabled. Enable &#8220;clr enabled&#8221; configuration option.</span>&#8216;</p>
<pre class="brush: sql;">
sp_configure 'clr enabled', 1;
RECONFIGURE;
</pre>
<p>3.4.2. Test UTF-8</p>
<pre class="brush: sql;">
DECLARE @u Utf8String;
SET @u = CONVERT(Utf8String, 'hello world');
SELECT
	@u.ToString()
	, CONVERT(varbinary(8000), @u)
	, SUBSTRING(@u.ToString(), 1, 5)
	, @u.Utf8Bytes;
</pre>
<div id="attachment_732" class="wp-caption aligncenter" style="width: 759px"><a href="http://zlika.org/wp-content/uploads/2011/03/02.png" rel="lightbox[704]"><img src="http://zlika.org/wp-content/uploads/2011/03/02.png" alt="" title="The result" width="749" height="75" class="size-full wp-image-732" /></a><p class="wp-caption-text">The result</p></div>
<p><strong><span style="text-decoration: underline;">Create PHP form to insert a UTF-8 data</span></strong></p>
<p><strong>1. Create table</strong></p>
<pre class="brush: sql;">
USE zlika;

CREATE TABLE CharsetTest
(
	[Language] VARCHAR(50)
	, [Phrase] UTF8String
);
</pre>
<p><strong>2. Create PHP form (insert.php)</strong></p>
<pre class="brush: php;">
&lt;html&gt;
&lt;head&gt;
	&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
	&lt;title&gt;Charset Test&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;?php
// Connect to SQL Server
$server = 'ZLIKA';
$username = 'zlika';
$password = 'myPassword';
$connect = mssql_connect($server, $username, $password) or die ('No server connection!');
$sqldb = mssql_select_db('zlika', $connect) or die ('No database connection!');

// Get the variables
$language = $_POST['language'];
$phrase = $_POST['phrase'];

// Insert records in the database
$query = &quot;INSERT INTO CharsetTest (Language, Phrase) SELECT '&quot; . $language . &quot;', '&quot; . $phrase . &quot;'&quot;;
$result = mssql_query($query);

// Close database connection
mssql_close($connect);
?&gt;

&lt;form action=&quot;insert.php&quot; method=&quot;post&quot;&gt;
	Language: &lt;input name=&quot;language&quot; /&gt;&lt;br /&gt;
	Phrase: &lt;input name=&quot;phrase&quot; /&gt;&lt;br /&gt;
	&lt;input type=&quot;Submit&quot; /&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>3. Insert test data</strong></p>
<blockquote><p>Bulgarian &#8211;&gt; Честита Нова Година!<br />
Arabic &#8211;&gt; سنة جديدة سعيدة!<br />
Armenian &#8212; &gt; Շնորհավոր Նոր Տարի<br />
Azarbaijani &#8211;&gt; Yeni iliniz mübarək<br />
Catalan &#8211;&gt; Feliç Any Nou!<br />
Chinese (Traditional) &#8211;&gt; 新年快樂<br />
Polish &#8211;&gt; Szczęśliwego Nowego Roku!<br />
Thai &#8211;&gt; สวัสดีปีใหม่<br />
hindi &#8211;&gt; नया साल मुबारक हो</p></blockquote>
<p><strong>4. Check the content of the table (check.php)</strong></p>
<pre class="brush: php;">
&lt;html&gt;
&lt;head&gt;
	&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
	&lt;title&gt;Charset Test&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;?php

// Connect to SQL Server
$server = 'ZLIKA';
$username = 'zlika';
$password = 'myPassword';
$connect = mssql_connect($server, $username, $password) or die ('No server connection!');
$sqldb = mssql_select_db('zlika', $connect) or die ('No database connection!');

// Select the data
$query = 'SELECT Language, Phrase.ToString() AS Phrase FROM CharsetTest';
$result = mssql_query($query);

//Retrieving data Header
echo '&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;2&quot; width=&quot;100%&quot;&gt;&lt;tr&gt;';

$i = 0;
while ($i &lt; mssql_num_fields($result))
{
	echo '&lt;th&gt;'. mssql_field_name($result, $i) . '&lt;/th&gt;';
	$i++;
}
echo '&lt;/tr&gt;';

//Retrieving rows
while ($row = mssql_fetch_array($result, MSSQL_ASSOC))
{
	echo '&lt;tr&gt;';
	foreach ($row as $data)
	{
		echo '&lt;td&gt;' . $data . '&lt;/td&gt;';
	}
	echo'&lt;/tr&gt;';
}

echo '&lt;/table&gt;';

// Close database connection
mssql_close($connect);

?&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>The result:</p>
<div id="attachment_723" class="wp-caption aligncenter" style="width: 353px"><a href="http://zlika.org/wp-content/uploads/2011/03/01.png" rel="lightbox[704]"><img class="size-full wp-image-723" title="The result" src="http://zlika.org/wp-content/uploads/2011/03/01.png" alt="" width="343" height="248" /></a><p class="wp-caption-text">The 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="How to store UTF-8 data in SQL Server" href="http://zlika.org/index.php/2011/03/06/how-to-store-utf-8-data-in-sql-server/"><b>How to store UTF-8 data 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/php/" title="View all posts in PHP" rel="category tag">PHP</a>, <a href="http://zlika.org/index.php/2011/03/06/how-to-store-utf-8-data-in-sql-server/#comments">%%comment_text%%</a>

<br />

Add to:
<a title="Share on Delicious" href="http://del.icio.us/post?url=http://zlika.org/index.php/2011/03/06/how-to-store-utf-8-data-in-sql-server/&title=How to store UTF-8 data in SQL Server">Delicious</a> | 
<a title="Share on Facebook" href="http://www.facebook.com/sharer.php?u=http://zlika.org/index.php/2011/03/06/how-to-store-utf-8-data-in-sql-server/&t=How to store UTF-8 data in SQL Server">Facebook</a> | 
<a title="Share on Twitter" href="http://twitter.com/home?status=Currently reading http://zlika.org/index.php/2011/03/06/how-to-store-utf-8-data-in-sql-server/">Twitter</a> | <a title="Share on Live" href="http://favorites.live.com/quickadd.aspx?url=http://zlika.org/index.php/2011/03/06/how-to-store-utf-8-data-in-sql-server/&title=How to store UTF-8 data in SQL Server">Live</a> | 
<a title="Share on Reddit" href="http://reddit.com/submit?url=http://zlika.org/index.php/2011/03/06/how-to-store-utf-8-data-in-sql-server/&title=How to store UTF-8 data in SQL Server">Reddit</a> | 
<a title="Share on Technorati" href="http://www.technorati.com/faves?add=http://zlika.org/index.php/2011/03/06/how-to-store-utf-8-data-in-sql-server/">Technorati</a> | 
<a title="Share on Digg" href="http://digg.com/submit?url=http://zlika.org/index.php/2011/03/06/how-to-store-utf-8-data-in-sql-server/&title=How to store UTF-8 data in SQL Server">Digg</a>

<br />

Followers: <a href="http://www.technorati.com/search/http://zlika.org/index.php/2011/03/06/how-to-store-utf-8-data-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/2011/03/06/how-to-store-utf-8-data-in-sql-server/" title="Linking blogs to this article, on Google">Google</a>

<br />

© 2011, <a href="http://zlika.org">zlika&#039;s</a> (<a href="http://zlika.org/index.php/feed/">RSS</a>)
</p>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://zlika.org/index.php/2011/03/06/how-to-store-utf-8-data-in-sql-server/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MaraK</title>
		<link>http://zlika.org/index.php/2011/02/17/marak/</link>
		<comments>http://zlika.org/index.php/2011/02/17/marak/#comments</comments>
		<pubDate>Thu, 17 Feb 2011 16:41:01 +0000</pubDate>
		<dc:creator>zlika</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://zlika.org/?p=712</guid>
		<description><![CDATA[I&#8217;m starting a project for management of a small store, using C# and SQL Server Express.
Félicitations


MaraK 
Author: zlika (Peter Lalovsky), Category: C#, IT, MS SQL Server, %%comment_text%%



Add to:
Delicious &#124; 
Facebook &#124; 
Twitter &#124; Live &#124; 
Reddit &#124; 
Technorati &#124; 
Digg



Followers: Technorati &#124; Google



© 2011, zlika&#039;s (RSS)

Feed enhanced by Better Feed from  Ozh
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m starting a project for management of a small store, using C# and SQL Server Express.</p>
<p>Félicitations</p>
<hr size="1" noshade>
<p style="font-family = verdana, tahoma, arial, sans-serif; font-size: 10px;">
<a title="MaraK" href="http://zlika.org/index.php/2011/02/17/marak/"><b>MaraK</b></a> <br />
Author: zlika (Peter Lalovsky), Category: <a href="http://zlika.org/index.php/category/it/csharp/" title="View all posts in C#" rel="category tag">C#</a>, <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/2011/02/17/marak/#comments">%%comment_text%%</a>

<br />

Add to:
<a title="Share on Delicious" href="http://del.icio.us/post?url=http://zlika.org/index.php/2011/02/17/marak/&title=MaraK">Delicious</a> | 
<a title="Share on Facebook" href="http://www.facebook.com/sharer.php?u=http://zlika.org/index.php/2011/02/17/marak/&t=MaraK">Facebook</a> | 
<a title="Share on Twitter" href="http://twitter.com/home?status=Currently reading http://zlika.org/index.php/2011/02/17/marak/">Twitter</a> | <a title="Share on Live" href="http://favorites.live.com/quickadd.aspx?url=http://zlika.org/index.php/2011/02/17/marak/&title=MaraK">Live</a> | 
<a title="Share on Reddit" href="http://reddit.com/submit?url=http://zlika.org/index.php/2011/02/17/marak/&title=MaraK">Reddit</a> | 
<a title="Share on Technorati" href="http://www.technorati.com/faves?add=http://zlika.org/index.php/2011/02/17/marak/">Technorati</a> | 
<a title="Share on Digg" href="http://digg.com/submit?url=http://zlika.org/index.php/2011/02/17/marak/&title=MaraK">Digg</a>

<br />

Followers: <a href="http://www.technorati.com/search/http://zlika.org/index.php/2011/02/17/marak/" 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/2011/02/17/marak/" title="Linking blogs to this article, on Google">Google</a>

<br />

© 2011, <a href="http://zlika.org">zlika&#039;s</a> (<a href="http://zlika.org/index.php/feed/">RSS</a>)
</p>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://zlika.org/index.php/2011/02/17/marak/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Equal Action to Identical Databases</title>
		<link>http://zlika.org/index.php/2010/11/15/equal-action-to-identical-databases/</link>
		<comments>http://zlika.org/index.php/2010/11/15/equal-action-to-identical-databases/#comments</comments>
		<pubDate>Mon, 15 Nov 2010 05:42:58 +0000</pubDate>
		<dc:creator>zlika</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Transact-SQL]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[SSMS]]></category>

		<guid isPermaLink="false">http://zlika.org/?p=636</guid>
		<description><![CDATA[If I administer 345 identical databases I can do equal action to all of them (or some of them) easy by selecting the names of the databases, generate dynamic code, execute it and select the result and the errors (is any).

In this example I will select the names of the databases, create dynamic code and [...]]]></description>
			<content:encoded><![CDATA[<p>If I administer 345 identical databases I can do equal action to all of them (or some of them) easy by selecting the names of the databases, generate dynamic code, execute it and select the result and the errors (is any).</p>
<p><span id="more-636"></span><br />
In this example I will select the names of the databases, create dynamic code and execute it. Next, in case of result or errors &#8211; create temporary &#8216;Result&#8217; or/and &#8216;Errors&#8217; table/s. The database zlika1 differs (column name &#8216;FirstName1&#8242; on line 16) from the others to generate an error. </p>
<pre class="brush: sql; highlight: [16];">
-- Create databases
CREATE DATABASE zlika1
CREATE DATABASE zlika2
CREATE DATABASE zlika3
GO

-- Create Tables
CREATE TABLE zlika1.dbo.Names
(
	FirstName NVARCHAR(50)
	, LastName NVARCHAR(50)
)

CREATE TABLE zlika2.dbo.Names
(
	FirstName1 NVARCHAR(50)
	, LastName NVARCHAR(50)
)

CREATE TABLE zlika3.dbo.Names
(
	FirstName NVARCHAR(50)
	, LastName NVARCHAR(50)
)

-- Populate Tables
INSERT INTO zlika1.dbo.Names VALUES ('z_FirstName', 'z_Lastname')
INSERT INTO zlika2.dbo.Names VALUES ('z1_FirstName', 'z1_Lastname')
INSERT INTO zlika3.dbo.Names VALUES ('z2_FirstName', 'z2_Lastname')
GO
</pre>
<p>And the script&#8230; The code that will be executes to all databases is on line 42. in this example I select the first and last names of the &#8216;Names&#8217; table from all databases which name starts with &#8216;zlika&#8217;.</p>
<pre class="brush: sql; highlight: [42];">
USE master
GO

-- Declare variables
DECLARE @DBName NVARCHAR(100), @Rows INT, @SQL VARCHAR(max)

-- Delete Temp Table
IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE [name] LIKE '#TempTable%')
	DROP TABLE #TempTable

IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE [name] LIKE '#Result%')
	DROP TABLE #Result

IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE [name] LIKE '#Errors%')
	DROP TABLE #Errors

-- Populate Temp Table
SELECT [name]
INTO #TempTable
FROM sys.databases
WHERE [name] LIKE 'zlika%'

-- Count rows in Temp Table
SELECT @Rows = COUNT([name])
FROM #TempTable

-- Cycle
WHILE (@Rows) &gt; 0
BEGIN
	SELECT TOP 1 @DBName = [name] FROM #TempTable
	---------- Do Something Start ----------
	BEGIN TRY
		IF NOT EXISTS (SELECT * FROM tempdb..sysobjects WHERE [name] LIKE '#Result%')
			BEGIN
				CREATE TABLE #Result
				(
					DatabaseName NVARCHAR(50)
					, FirstName NVARCHAR(50)
					, LastName NVARCHAR(50)
				)
			END
		SELECT @SQL = 'INSERT INTO #Result SELECT ''' + @DBName + ''', FirstName, LastName FROM ' + @DBName + '.dbo.Names'
		EXEC (@SQL)
	END TRY

	BEGIN CATCH
		IF NOT EXISTS (SELECT * FROM tempdb..sysobjects WHERE [name] LIKE '#Errors%')
			BEGIN
				CREATE TABLE #Errors
				(
					DatabaseName NVARCHAR(100)
					, ErrorNumber INT
					, ErrorMessage NVARCHAR(250)
				)
			END
		INSERT INTO #Errors VALUES (@DBName, ERROR_NUMBER(), ERROR_MESSAGE())
	END CATCH
	---------- Do Something End ----------
	DELETE FROM #TempTable WHERE [name] = @DBName
	SET @Rows = @Rows - 1
END

IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE [name] LIKE '#Result%')
	SELECT *
	FROM #Result

IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE [name] LIKE '#Errors%')
	SELECT *
	FROM #Errors

-- Clean up
DROP TABLE #TempTable

IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE [name] LIKE '#Result%')
	DROP TABLE #Result

IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE [name] LIKE '#Errors%')
	DROP TABLE #Errors
GO
</pre>
<p>The result &#8211; two rows, corresponding to &#8216;zlika1&#8242; and &#8216;zlika3&#8242; databases and one error, corresponding to &#8216;zlika2&#8242; database.<br />
<div id="attachment_671" class="wp-caption aligncenter" style="width: 472px"><a href="http://zlika.org/wp-content/uploads/2010/11/01.png" rel="lightbox[636]"><img src="http://zlika.org/wp-content/uploads/2010/11/01.png" alt="" title="Result - two selected rows and one error" width="462" height="194" class="size-full wp-image-671" /></a><p class="wp-caption-text">Result - two selected rows and one error</p></div></p>
<p>Félicitations</p>
<hr size="1" noshade>
<p style="font-family = verdana, tahoma, arial, sans-serif; font-size: 10px;">
<a title="Equal Action to Identical Databases" href="http://zlika.org/index.php/2010/11/15/equal-action-to-identical-databases/"><b>Equal Action to Identical Databases</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/sql/" title="View all posts in Transact-SQL" rel="category tag">Transact-SQL</a>, <a href="http://zlika.org/index.php/2010/11/15/equal-action-to-identical-databases/#comments">%%comment_text%%</a>

<br />

Add to:
<a title="Share on Delicious" href="http://del.icio.us/post?url=http://zlika.org/index.php/2010/11/15/equal-action-to-identical-databases/&title=Equal Action to Identical Databases">Delicious</a> | 
<a title="Share on Facebook" href="http://www.facebook.com/sharer.php?u=http://zlika.org/index.php/2010/11/15/equal-action-to-identical-databases/&t=Equal Action to Identical Databases">Facebook</a> | 
<a title="Share on Twitter" href="http://twitter.com/home?status=Currently reading http://zlika.org/index.php/2010/11/15/equal-action-to-identical-databases/">Twitter</a> | <a title="Share on Live" href="http://favorites.live.com/quickadd.aspx?url=http://zlika.org/index.php/2010/11/15/equal-action-to-identical-databases/&title=Equal Action to Identical Databases">Live</a> | 
<a title="Share on Reddit" href="http://reddit.com/submit?url=http://zlika.org/index.php/2010/11/15/equal-action-to-identical-databases/&title=Equal Action to Identical Databases">Reddit</a> | 
<a title="Share on Technorati" href="http://www.technorati.com/faves?add=http://zlika.org/index.php/2010/11/15/equal-action-to-identical-databases/">Technorati</a> | 
<a title="Share on Digg" href="http://digg.com/submit?url=http://zlika.org/index.php/2010/11/15/equal-action-to-identical-databases/&title=Equal Action to Identical Databases">Digg</a>

<br />

Followers: <a href="http://www.technorati.com/search/http://zlika.org/index.php/2010/11/15/equal-action-to-identical-databases/" 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/11/15/equal-action-to-identical-databases/" 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>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://zlika.org/index.php/2010/11/15/equal-action-to-identical-databases/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SELECT * or SELECT [Column Name] in IF statement in MS SQL Server</title>
		<link>http://zlika.org/index.php/2010/10/31/select-or-select-column-name-in-if-statement-in-ms-sql-server/</link>
		<comments>http://zlika.org/index.php/2010/10/31/select-or-select-column-name-in-if-statement-in-ms-sql-server/#comments</comments>
		<pubDate>Sun, 31 Oct 2010 19:02:32 +0000</pubDate>
		<dc:creator>zlika</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[Transact-SQL]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Optimization]]></category>

		<guid isPermaLink="false">http://zlika.org/?p=554</guid>
		<description><![CDATA[When we decide how to manipulate the data, we use IF statement verification. For example if we export information about merchant sales, we have two common groups of merchants &#8211; these we scan (with serial numbers) and these we don&#8217;t scan. For both of them we use two BEGIN&#8230; END blocks. To verify the type [...]]]></description>
			<content:encoded><![CDATA[<p>When we decide how to manipulate the data, we use IF statement verification. For example if we export information about merchant sales, we have two common groups of merchants &#8211; these we scan (with serial numbers) and these we don&#8217;t scan. For both of them we use two BEGIN&#8230; END blocks. To verify the type we use IF statement which searches for a row in &#8216;RegisteredScans&#8217; table.</p>
<p><span id="more-554"></span> We can write the IF statement like:</p>
<pre class="brush: sql; highlight: [4];">
...
IF EXISTS
(
	SELECT *
	FROM RegisteredScans
	WHERE...
)
BEGIN
	...
END
...
</pre>
<p>or:</p>
<pre class="brush: sql; highlight: [4];">
...
IF EXISTS
(
	SELECT [Column Name]
	FROM RegisteredScans
	WHERE [Column Name]...
)
BEGIN
	...
END
...
</pre>
<p>The difference is that we select ALL or only the column that we use to verify the truth of the IF statement.</p>
<p>I created an example to demonstrate the difference between SELECT * and SELECT [Column Name]. First I need to know which table has most rows in AdventureWorks2008 database. On <a title="List tables and count rows" href="http://sqlserver2000.databases.aspfaq.com/how-do-i-get-a-list-of-sql-server-tables-and-their-row-counts.html" target="_blank">this address</a> I found the following script:</p>
<pre class="brush: sql;">
USE AdventureWorks2008
GO

ALTER PROCEDURE dbo.listTableRowCounts
AS
BEGIN
	SET NOCOUNT ON

	DECLARE @SQL VARCHAR(255)
	SET @SQL = 'DBCC UPDATEUSAGE (' + DB_NAME() + ')'
	EXEC(@SQL)

	CREATE TABLE #foo
	(
		tablename VARCHAR(255)
        , rc INT
	)

	INSERT #foo
	EXEC sp_msForEachTable
		'SELECT PARSENAME(''?'', 1),
		COUNT(*) FROM ?'
END

	SELECT tablename, rc
	FROM #foo
	ORDER BY rc DESC

	DROP TABLE #foo
GO
</pre>
<p>Then I executed the stored procedure</p>
<pre class="brush: sql;">
USE AdventureWorks2008
GO

EXEC dbo.listTableRowCounts
GO
</pre>
<p>And I found that the table &#8216;SalesOrderDetail&#8217; contains 121317 rows (most in the database). Next I wrote a script which uses Start time and End time to calculate the duration of execution of a code. In our example the code is:</p>
<pre class="brush: sql; highlight: [1];">
SELECT *
FROM SalesOrderDetail
GO
</pre>
<p>and</p>
<pre class="brush: sql; highlight: [1];">
SELECT SalesOrderID
FROM SalesOrderDetail
GO
</pre>
<p>When I select all the columns, the time for the operation is 6.594 seconds</p>
<pre class="brush: sql; highlight: [12];">
USE AdventureWorks2008
GO

-- Declare variables
DECLARE @Start TIME
DECLARE @End TIME

-- Set start time
SET @Start = GETDATE()

-- Operation
SELECT *
FROM Sales.SalesOrderDetail

-- Set end time
SET @End = GETDATE()

-- Calculate the difference in times
SELECT DATEDIFF(MS, @Start, @End) AS Milliseconds
GO
</pre>
<div id="attachment_558" class="wp-caption aligncenter" style="width: 517px"><a href="http://zlika.org/wp-content/uploads/2010/10/01.png" rel="lightbox[554]"><img class="size-full wp-image-558" title="SELECT * FROM..." src="http://zlika.org/wp-content/uploads/2010/10/01.png" alt="" width="507" height="164" /></a><p class="wp-caption-text">SELECT * FROM...</p></div>
<p>When I select the &#8216;SalesOrderID&#8217; column, the time for the operation is 2.470 seconds</p>
<div id="attachment_559" class="wp-caption aligncenter" style="width: 160px"><a href="http://zlika.org/wp-content/uploads/2010/10/02.png" rel="lightbox[554]"><img class="size-full wp-image-559" title="SELECT SalesOrderID FROM..." src="http://zlika.org/wp-content/uploads/2010/10/02.png" alt="" width="150" height="289" /></a><p class="wp-caption-text">SELECT SalesOrderID FROM...</p></div>
<p>When I select &#8216;rowguid&#8217; column, the time for the operation is 3.234 seconds</p>
<div id="attachment_560" class="wp-caption aligncenter" style="width: 344px"><a href="http://zlika.org/wp-content/uploads/2010/10/03.png" rel="lightbox[554]"><img class="size-full wp-image-560" title="SELECT rowguid FROM..." src="http://zlika.org/wp-content/uploads/2010/10/03.png" alt="" width="334" height="199" /></a><p class="wp-caption-text">SELECT rowguid FROM...</p></div>
<p>The difference between &#8216;SalesOrderID&#8217; and &#8216;rowguid&#8217; columns is that &#8216;SalesOrderID&#8217; is Primary Key, i.e. it&#8217;s indexed.</p>
<p>Félicitations</p>
<hr size="1" noshade>
<p style="font-family = verdana, tahoma, arial, sans-serif; font-size: 10px;">
<a title="SELECT * or SELECT [Column Name] in IF statement in MS SQL Server" href="http://zlika.org/index.php/2010/10/31/select-or-select-column-name-in-if-statement-in-ms-sql-server/"><b>SELECT * or SELECT [Column Name] in IF statement 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 Transact-SQL" rel="category tag">Transact-SQL</a>, <a href="http://zlika.org/index.php/2010/10/31/select-or-select-column-name-in-if-statement-in-ms-sql-server/#comments">%%comment_text%%</a>

<br />

Add to:
<a title="Share on Delicious" href="http://del.icio.us/post?url=http://zlika.org/index.php/2010/10/31/select-or-select-column-name-in-if-statement-in-ms-sql-server/&title=SELECT * or SELECT [Column Name] in IF statement 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/10/31/select-or-select-column-name-in-if-statement-in-ms-sql-server/&t=SELECT * or SELECT [Column Name] in IF statement 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/10/31/select-or-select-column-name-in-if-statement-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/10/31/select-or-select-column-name-in-if-statement-in-ms-sql-server/&title=SELECT * or SELECT [Column Name] in IF statement in MS SQL Server">Live</a> | 
<a title="Share on Reddit" href="http://reddit.com/submit?url=http://zlika.org/index.php/2010/10/31/select-or-select-column-name-in-if-statement-in-ms-sql-server/&title=SELECT * or SELECT [Column Name] in IF statement in MS SQL Server">Reddit</a> | 
<a title="Share on Technorati" href="http://www.technorati.com/faves?add=http://zlika.org/index.php/2010/10/31/select-or-select-column-name-in-if-statement-in-ms-sql-server/">Technorati</a> | 
<a title="Share on Digg" href="http://digg.com/submit?url=http://zlika.org/index.php/2010/10/31/select-or-select-column-name-in-if-statement-in-ms-sql-server/&title=SELECT * or SELECT [Column Name] in IF statement in MS SQL Server">Digg</a>

<br />

Followers: <a href="http://www.technorati.com/search/http://zlika.org/index.php/2010/10/31/select-or-select-column-name-in-if-statement-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/10/31/select-or-select-column-name-in-if-statement-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>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://zlika.org/index.php/2010/10/31/select-or-select-column-name-in-if-statement-in-ms-sql-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Select server logins and their roles in SQL Server</title>
		<link>http://zlika.org/index.php/2010/10/24/select-server-logins-and-their-roles-in-sql-server/</link>
		<comments>http://zlika.org/index.php/2010/10/24/select-server-logins-and-their-roles-in-sql-server/#comments</comments>
		<pubDate>Sun, 24 Oct 2010 21:25:37 +0000</pubDate>
		<dc:creator>zlika</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[SSMS]]></category>
		<category><![CDATA[Transact-SQL]]></category>

		<guid isPermaLink="false">http://zlika.org/?p=540</guid>
		<description><![CDATA[To view all the server logins and their roles I use the system view sys.syslogins and CASE to convert 1 to &#8220;Yes&#8221; and 0 to &#8220;No&#8221;.


-- Select all database logins and their server roles
USE master
GO

SELECT
	[name] AS [Login]
	, CASE sysadmin WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' ELSE 'N/A' END AS [sysadmin]
	, CASE securityadmin WHEN [...]]]></description>
			<content:encoded><![CDATA[<p>To view all the server logins and their roles I use the system view <a title="sys.syslogins" href="http://msdn.microsoft.com/en-us/library/ms178593.aspx" target="_blank">sys.syslogins</a> and <a title="CASE" href="http://msdn.microsoft.com/en-us/library/ms181765.aspx" target="_blank">CASE</a> to convert 1 to &#8220;Yes&#8221; and 0 to &#8220;No&#8221;.</p>
<p><span id="more-540"></span></p>
<pre class="brush: sql;">
-- Select all database logins and their server roles
USE master
GO

SELECT
	[name] AS [Login]
	, CASE sysadmin WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' ELSE 'N/A' END AS [sysadmin]
	, CASE securityadmin WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' ELSE 'N/A' END AS [securityadmin]
	, CASE serveradmin WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' ELSE 'N/A' END AS [serveradmin]
	, CASE setupadmin WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' ELSE 'N/A' END AS [setupadmin]
	, CASE processadmin WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' ELSE 'N/A' END AS [processadmin]
	, CASE diskadmin WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' ELSE 'N/A' END AS [diskadmin]
	, CASE dbcreator WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' ELSE 'N/A' END AS [dbcreator]

FROM sys.syslogins
GO
</pre>
<p>Félicitations</p>
<hr size="1" noshade>
<p style="font-family = verdana, tahoma, arial, sans-serif; font-size: 10px;">
<a title="Select server logins and their roles in SQL Server" href="http://zlika.org/index.php/2010/10/24/select-server-logins-and-their-roles-in-sql-server/"><b>Select server logins and their roles 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/2010/10/24/select-server-logins-and-their-roles-in-sql-server/#comments">%%comment_text%%</a>

<br />

Add to:
<a title="Share on Delicious" href="http://del.icio.us/post?url=http://zlika.org/index.php/2010/10/24/select-server-logins-and-their-roles-in-sql-server/&title=Select server logins and their roles in SQL Server">Delicious</a> | 
<a title="Share on Facebook" href="http://www.facebook.com/sharer.php?u=http://zlika.org/index.php/2010/10/24/select-server-logins-and-their-roles-in-sql-server/&t=Select server logins and their roles in SQL Server">Facebook</a> | 
<a title="Share on Twitter" href="http://twitter.com/home?status=Currently reading http://zlika.org/index.php/2010/10/24/select-server-logins-and-their-roles-in-sql-server/">Twitter</a> | <a title="Share on Live" href="http://favorites.live.com/quickadd.aspx?url=http://zlika.org/index.php/2010/10/24/select-server-logins-and-their-roles-in-sql-server/&title=Select server logins and their roles in SQL Server">Live</a> | 
<a title="Share on Reddit" href="http://reddit.com/submit?url=http://zlika.org/index.php/2010/10/24/select-server-logins-and-their-roles-in-sql-server/&title=Select server logins and their roles in SQL Server">Reddit</a> | 
<a title="Share on Technorati" href="http://www.technorati.com/faves?add=http://zlika.org/index.php/2010/10/24/select-server-logins-and-their-roles-in-sql-server/">Technorati</a> | 
<a title="Share on Digg" href="http://digg.com/submit?url=http://zlika.org/index.php/2010/10/24/select-server-logins-and-their-roles-in-sql-server/&title=Select server logins and their roles in SQL Server">Digg</a>

<br />

Followers: <a href="http://www.technorati.com/search/http://zlika.org/index.php/2010/10/24/select-server-logins-and-their-roles-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/10/24/select-server-logins-and-their-roles-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>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://zlika.org/index.php/2010/10/24/select-server-logins-and-their-roles-in-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Filegroups and Autogrowth in MS SQL Server</title>
		<link>http://zlika.org/index.php/2010/09/18/filegroups-and-autogrowth-in-ms-sql-server/</link>
		<comments>http://zlika.org/index.php/2010/09/18/filegroups-and-autogrowth-in-ms-sql-server/#comments</comments>
		<pubDate>Sun, 19 Sep 2010 03:27:10 +0000</pubDate>
		<dc:creator>zlika</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SSMS]]></category>
		<category><![CDATA[Transact-SQL]]></category>

		<guid isPermaLink="false">http://zlika.org/?p=464</guid>
		<description><![CDATA[Yesterday I was asked about the way a table is stored in several files in a filegroup.

The current example explains it. First, I create a database, containing two secondary data files in a filegroup.

CREATE DATABASE zlika ON PRIMARY
(
	NAME = N'zlika'
	, FILENAME = N'C:\Databases\zlika.mdf'
)
,

FILEGROUP zlikaGroup
(
	NAME = N'fg1_1'
	, FILENAME = N'C:\Databases\fg1_1.ndf'
)
,
(
	NAME = N'fg1_2'
	, FILENAME = N'C:\Databases\fg1_2.ndf'
)

LOG ON
(
	NAME [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I was asked about the way a table is stored in several files in a filegroup.</p>
<p><span id="more-464"></span></p>
<p>The current example explains it. First, I create a database, containing two secondary data files in a filegroup.</p>
<pre class="brush: sql;">
CREATE DATABASE zlika ON PRIMARY
(
	NAME = N'zlika'
	, FILENAME = N'C:\Databases\zlika.mdf'
)
,

FILEGROUP zlikaGroup
(
	NAME = N'fg1_1'
	, FILENAME = N'C:\Databases\fg1_1.ndf'
)
,
(
	NAME = N'fg1_2'
	, FILENAME = N'C:\Databases\fg1_2.ndf'
)

LOG ON
(
	NAME = N'zlika_log'
	, FILENAME = N'C:\Databases\zlika_log.ldf'
)
GO
</pre>
<p>The sizes of the files are as follow:</p>
<div id="attachment_465" class="wp-caption aligncenter" style="width: 182px"><a href="http://zlika.org/wp-content/uploads/2010/09/01.jpg" rel="lightbox[464]"><img class="size-full wp-image-465" title="File sizes after creation of the database" src="http://zlika.org/wp-content/uploads/2010/09/01.jpg" alt="" width="172" height="73" /></a><p class="wp-caption-text">File sizes after creation of the database</p></div>
<p>Next I create a table that stores its rows in the filegroup</p>
<pre class="brush: sql;">
USE zlika
GO

CREATE TABLE TestTable
(
	ID INT IDENTITY NOT NULL
	, FirstName VARCHAR(50) NOT NULL
	, LastName VARCHAR(50) NOT NULL
)
ON zlikaGroup
GO
</pre>
<p>I populate the table with any information</p>
<pre class="brush: sql;">
USE zlika
GO

INSERT INTO TestTable VALUES ('George', 'Henderson')
GO 50000
</pre>
<p>The sizes of the files are as follow:</p>
<div id="attachment_467" class="wp-caption aligncenter" style="width: 181px"><a href="http://zlika.org/wp-content/uploads/2010/09/02.jpg" rel="lightbox[464]"><img class="size-full wp-image-467" title="File sizes after the population of the table" src="http://zlika.org/wp-content/uploads/2010/09/02.jpg" alt="" width="171" height="69" /></a><p class="wp-caption-text">File sizes after the population of the table</p></div>
<p>I execute the same script and check the sizes of the files once again:</p>
<div id="attachment_468" class="wp-caption aligncenter" style="width: 182px"><a href="http://zlika.org/wp-content/uploads/2010/09/03.jpg" rel="lightbox[464]"><img class="size-full wp-image-468" title="File sizes after adding more data" src="http://zlika.org/wp-content/uploads/2010/09/03.jpg" alt="" width="172" height="69" /></a><p class="wp-caption-text">File sizes after adding more data</p></div>
<p>The answer is: MS SQL Server stores the data in several files in a filegroup according to their Autogrowth settings. The database I have created autogrows the secondary data files by 1MB:</p>
<div id="attachment_469" class="wp-caption aligncenter" style="width: 585px"><a href="http://zlika.org/wp-content/uploads/2010/09/04.jpg" rel="lightbox[464]"><img class="size-full wp-image-469" title="The properties of the database - Files" src="http://zlika.org/wp-content/uploads/2010/09/04.jpg" alt="" width="575" height="118" /></a><p class="wp-caption-text">The properties of the database - Files</p></div>
<p>Félicitations</p>
<hr size="1" noshade>
<p style="font-family = verdana, tahoma, arial, sans-serif; font-size: 10px;">
<a title="Filegroups and Autogrowth in MS SQL Server" href="http://zlika.org/index.php/2010/09/18/filegroups-and-autogrowth-in-ms-sql-server/"><b>Filegroups and Autogrowth 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/2010/09/18/filegroups-and-autogrowth-in-ms-sql-server/#comments">%%comment_text%%</a>

<br />

Add to:
<a title="Share on Delicious" href="http://del.icio.us/post?url=http://zlika.org/index.php/2010/09/18/filegroups-and-autogrowth-in-ms-sql-server/&title=Filegroups and Autogrowth 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/09/18/filegroups-and-autogrowth-in-ms-sql-server/&t=Filegroups and Autogrowth 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/09/18/filegroups-and-autogrowth-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/09/18/filegroups-and-autogrowth-in-ms-sql-server/&title=Filegroups and Autogrowth in MS SQL Server">Live</a> | 
<a title="Share on Reddit" href="http://reddit.com/submit?url=http://zlika.org/index.php/2010/09/18/filegroups-and-autogrowth-in-ms-sql-server/&title=Filegroups and Autogrowth in MS SQL Server">Reddit</a> | 
<a title="Share on Technorati" href="http://www.technorati.com/faves?add=http://zlika.org/index.php/2010/09/18/filegroups-and-autogrowth-in-ms-sql-server/">Technorati</a> | 
<a title="Share on Digg" href="http://digg.com/submit?url=http://zlika.org/index.php/2010/09/18/filegroups-and-autogrowth-in-ms-sql-server/&title=Filegroups and Autogrowth in MS SQL Server">Digg</a>

<br />

Followers: <a href="http://www.technorati.com/search/http://zlika.org/index.php/2010/09/18/filegroups-and-autogrowth-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/09/18/filegroups-and-autogrowth-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>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://zlika.org/index.php/2010/09/18/filegroups-and-autogrowth-in-ms-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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[Transact-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 a [...]]]></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().</p>
<p><span id="more-430"></span></p>
<p>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 Transact-SQL" rel="category tag">Transact-SQL</a>, <a href="http://zlika.org/index.php/2010/08/04/simple-usage-of-dense_rank-function-in-ms-sql-server/#comments">%%comment_text%%</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>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></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>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. </p>
<p><span id="more-254"></span></p>
<p>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">%%comment_text%%</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>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://zlika.org/index.php/2010/06/06/simple-ssis-project-part-1/feed/</wfw:commentRss>
		<slash:comments>4</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, %%comment_text%%



Add to:
Delicious &#124; 
Facebook &#124; 
Twitter &#124; Live &#124; 
Reddit &#124; 
Technorati [...]]]></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>
<p><span id="more-391"></span></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">%%comment_text%%</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>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></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[IT]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Microsoft]]></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: IT, Personal, %%comment_text%%



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/it/" title="View all posts in IT" rel="category tag">IT</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/05/26/congratulations-youve-passed-the-exam/#comments">%%comment_text%%</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>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></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>
	</channel>
</rss>

