<?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>3VL - SQL Server Development</title>
	<atom:link href="http://3vl.co.uk/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://3vl.co.uk</link>
	<description>SQL Server Development</description>
	<lastBuildDate>Fri, 28 May 2010 15:32:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>error 5 RESTORE HEADERONLY Error when Restoring a Database</title>
		<link>http://3vl.co.uk/?p=86</link>
		<comments>http://3vl.co.uk/?p=86#comments</comments>
		<pubDate>Fri, 28 May 2010 15:32:06 +0000</pubDate>
		<dc:creator>David Bainbridge</dc:creator>
				<category><![CDATA[Errors]]></category>
		<category><![CDATA[Workarounds]]></category>

		<guid isPermaLink="false">http://3vl.co.uk/?p=86</guid>
		<description><![CDATA[I recieved the following error when trying to restore from a .bak file:
error 5
RESTORE HEADERONLY
The error while very frustrating was easy to work around. I simply changed my logon to &#8216;Local System&#8217; and was able to restore the backup.
To take you through the process step by step I:
1) Navigate to SQL Server Confiuration Manager
2) Right [...]]]></description>
			<content:encoded><![CDATA[<p>I recieved the following error when trying to restore from a .bak file:</p>
<p>error 5<br />
RESTORE HEADERONLY</p>
<p>The error while very frustrating was easy to work around. I simply changed my logon to &#8216;Local System&#8217; and was able to restore the backup.</p>
<p>To take you through the process step by step I:</p>
<p>1) Navigate to SQL Server Confiuration Manager</p>
<p>2) Right click on the instance you are using</p>
<p>3) Click on properties</p>
<p>4) Select thethe Logon Tab</p>
<p>5) Click on built in account</p>
<p>6) select &#8216;Local System&#8217; from the drop down</p>
<p>7) Apply and ok your way out of the menus.</p>
]]></content:encoded>
			<wfw:commentRss>http://3vl.co.uk/?feed=rss2&amp;p=86</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Previous Working Day Function</title>
		<link>http://3vl.co.uk/?p=83</link>
		<comments>http://3vl.co.uk/?p=83#comments</comments>
		<pubDate>Tue, 27 Apr 2010 08:14:07 +0000</pubDate>
		<dc:creator>David Bainbridge</dc:creator>
				<category><![CDATA[Functions]]></category>

		<guid isPermaLink="false">http://3vl.co.uk/?p=83</guid>
		<description><![CDATA[I have been asked to create a function which works out the previous working day.
The logic for this function is as follows:
If the current day is a sunday or Monday then pick the previous friday
Else pick the previous day.
I was then able to get the current day using DatePart(weekday,{CurrentDate}) and create the following function:
CREATE FUNCTION [...]]]></description>
			<content:encoded><![CDATA[<p>I have been asked to create a function which works out the previous working day.</p>
<p>The logic for this function is as follows:</p>
<blockquote><p>If the current day is a sunday or Monday then pick the previous friday<br />
Else pick the previous day.</p></blockquote>
<p>I was then able to get the current day using DatePart(weekday,{CurrentDate}) and create the following function:</p>
<blockquote><p>CREATE FUNCTION [dbo].[FUN_Previous_Working_Day] (@CurrentDate DATETIME)</p>
<p>RETURNS DATETIME<br />
AS<br />
BEGIN<br />
DECLARE @PreviousDate DATETIME<br />
DECLARE @Day INT<br />
SET  @Day = DATEPART(weekday,@CurrentDate)</p>
<p>IF  @Day = 7<br />
SET  @PreviousDate = DATEADD(d,-2,@CurrentDate)<br />
ELSE<br />
IF  @Day = 1<br />
SET  @PreviousDate = DATEADD(d,-3,@CurrentDate)<br />
ELSE<br />
SET  @PreviousDate = DATEADD(d,-1,@CurrentDate)</p>
<p>RETURN @PreviousDate<br />
END<br />
GO</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://3vl.co.uk/?feed=rss2&amp;p=83</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tables without Indexes</title>
		<link>http://3vl.co.uk/?p=81</link>
		<comments>http://3vl.co.uk/?p=81#comments</comments>
		<pubDate>Wed, 21 Apr 2010 08:14:42 +0000</pubDate>
		<dc:creator>David Bainbridge</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://3vl.co.uk/?p=81</guid>
		<description><![CDATA[Indexes are one of the most important factors in determining query performance. Luckily the code for determining which tables lack a valid index is relatively simple:
SELECT   SCHEMA_NAME(schema_id) AS Schema,
  name AS Table
FROM   sys.tables
WHERE   OBJECTPROPERTY(OBJECT_ID,&#8217;IsIndexed&#8217;) = 0
ORDER BY schema_name, table_name;
GO
]]></description>
			<content:encoded><![CDATA[<p>Indexes are one of the most important factors in determining query performance. Luckily the code for determining which tables lack a valid index is relatively simple:</p>
<blockquote><p>SELECT   SCHEMA_NAME(schema_id) AS Schema,<br />
  name AS Table<br />
FROM   sys.tables<br />
WHERE   OBJECTPROPERTY(OBJECT_ID,&#8217;IsIndexed&#8217;) = 0<br />
ORDER BY schema_name, table_name;<br />
GO</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://3vl.co.uk/?feed=rss2&amp;p=81</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Filtered Index</title>
		<link>http://3vl.co.uk/?p=78</link>
		<comments>http://3vl.co.uk/?p=78#comments</comments>
		<pubDate>Tue, 20 Apr 2010 09:42:57 +0000</pubDate>
		<dc:creator>David Bainbridge</dc:creator>
				<category><![CDATA[Query Optimisation]]></category>

		<guid isPermaLink="false">http://3vl.co.uk/?p=78</guid>
		<description><![CDATA[SQL Server 2008 introduced a lot of new features one of which is filtered indexes. Filtered indexes can be used as an alternative to indexed views and partitioning to improve data retrieval performance on large tables.
A filtered index is a non-clustered index with a where clause. The index will only contain the rows which satisfy [...]]]></description>
			<content:encoded><![CDATA[<p>SQL Server 2008 introduced a lot of new features one of which is filtered indexes. Filtered indexes can be used as an alternative to indexed views and partitioning to improve data retrieval performance on large tables.</p>
<p>A filtered index is a non-clustered index with a where clause. The index will only contain the rows which satisfy the where clause. This means the index will require less storage space and have better performance.</p>
<p>To create the filtered index the syntax is relatively simple:</p>
<blockquote><p>CREATE NONCLUSTERED INDEX {INDEX_NAME}<br />
ON {TABLE}({FIELD})<br />
WHERE {FIELD} &#8212; Insert Where criteria here.<br />
GO</p></blockquote>
<p>The query optimiser should pick the best index to use however you can use a hint to force the query optimiser to use the filtered index:</p>
<blockquote><p>SELECT * FROM {TABLE} WITH(INDEX({INDEX_NAME}))<br />
WHERE {FIELD}</p></blockquote>
<p>While they give a performance boost there are two main limitations with using a filtered index. Firstly they are only created on a single table. Second, complex criteria like the LIKE clause are not allowed.</p>
]]></content:encoded>
			<wfw:commentRss>http://3vl.co.uk/?feed=rss2&amp;p=78</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>From Queries to Stored Procedures</title>
		<link>http://3vl.co.uk/?p=76</link>
		<comments>http://3vl.co.uk/?p=76#comments</comments>
		<pubDate>Mon, 19 Apr 2010 15:56:10 +0000</pubDate>
		<dc:creator>David Bainbridge</dc:creator>
				<category><![CDATA[Beginning SQL Server]]></category>

		<guid isPermaLink="false">http://3vl.co.uk/?p=76</guid>
		<description><![CDATA[Basic Stored Procedures are incredibly simple.
If you write the following query:
SELECT Column1, Column2 FROM Table1
The equivilent stored procedure would be:
CREATE PROCEDURE StoredProcedure
AS
SELECT Column1, Column2 FROM Table1
GO
To call it simply type:
EXEC dbo.StoredProcedure
And execute.
]]></description>
			<content:encoded><![CDATA[<p>Basic Stored Procedures are incredibly simple.</p>
<p>If you write the following query:</p>
<blockquote><p>SELECT Column1, Column2 FROM Table1</p></blockquote>
<p>The equivilent stored procedure would be:</p>
<blockquote><p>CREATE PROCEDURE StoredProcedure<br />
AS<br />
SELECT Column1, Column2 FROM Table1<br />
GO</p></blockquote>
<p>To call it simply type:</p>
<blockquote><p>EXEC dbo.StoredProcedure</p></blockquote>
<p>And execute.</p>
]]></content:encoded>
			<wfw:commentRss>http://3vl.co.uk/?feed=rss2&amp;p=76</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Copy a View into a Table</title>
		<link>http://3vl.co.uk/?p=74</link>
		<comments>http://3vl.co.uk/?p=74#comments</comments>
		<pubDate>Mon, 19 Apr 2010 15:54:14 +0000</pubDate>
		<dc:creator>David Bainbridge</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://3vl.co.uk/?p=74</guid>
		<description><![CDATA[A simple way to copy data from a view to a table:
SELECT * INTO {Table} FROM {View}
]]></description>
			<content:encoded><![CDATA[<p>A simple way to copy data from a view to a table:</p>
<p>SELECT * INTO {Table} FROM {View}</p>
]]></content:encoded>
			<wfw:commentRss>http://3vl.co.uk/?feed=rss2&amp;p=74</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Every other page is blank</title>
		<link>http://3vl.co.uk/?p=72</link>
		<comments>http://3vl.co.uk/?p=72#comments</comments>
		<pubDate>Mon, 19 Apr 2010 15:52:44 +0000</pubDate>
		<dc:creator>David Bainbridge</dc:creator>
				<category><![CDATA[Errors]]></category>
		<category><![CDATA[SSRS]]></category>

		<guid isPermaLink="false">http://3vl.co.uk/?p=72</guid>
		<description><![CDATA[I am frequently asked the question &#8220;Why does a blank page get inserted every other page in an SSRS report?&#8221;
The solution is usually simple. The Body of your report could be too large for your page. Simply make sure that the Body of your report added to the left and right margin is less than [...]]]></description>
			<content:encoded><![CDATA[<p>I am frequently asked the question &#8220;Why does a blank page get inserted every other page in an SSRS report?&#8221;</p>
<p>The solution is usually simple. The Body of your report could be too large for your page. Simply make sure that the Body of your report added to the left and right margin is less than the page width.</p>
<p>Usually it will be the margins that push you over the limit.</p>
]]></content:encoded>
			<wfw:commentRss>http://3vl.co.uk/?feed=rss2&amp;p=72</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configure an SSIS package to run through SQL Server Agent</title>
		<link>http://3vl.co.uk/?p=69</link>
		<comments>http://3vl.co.uk/?p=69#comments</comments>
		<pubDate>Thu, 15 Apr 2010 12:28:20 +0000</pubDate>
		<dc:creator>David Bainbridge</dc:creator>
				<category><![CDATA[SSIS]]></category>
		<category><![CDATA[SQL Server Agent]]></category>

		<guid isPermaLink="false">http://3vl.co.uk/?p=69</guid>
		<description><![CDATA[I recently created a SSIS package which copied data from an Oracle DB to a SQL Server Database. The pacage I created using BIDS worked fine when executed by me but wouldn&#8217;t run via agent.
A quick search located this knowledge base article. http://support.microsoft.com/kb/918760.
This entry focuses method 4, my prefered method.
Use SSIS Package Configuration Files.
The default [...]]]></description>
			<content:encoded><![CDATA[<p>I recently created a SSIS package which copied data from an Oracle DB to a SQL Server Database. The pacage I created using BIDS worked fine when executed by me but wouldn&#8217;t run via agent.</p>
<p>A quick search located this knowledge base article. <a href="http://support.microsoft.com/kb/918760">http://support.microsoft.com/kb/918760</a>.</p>
<p>This entry focuses method 4, my prefered method.</p>
<p>Use SSIS Package Configuration Files.</p>
<p>The default security setting when a package is created is to save passwords and other sensitive information within the package with a user key. This means only the account that created the package can access and run it. This is not very helpful when you need the SQL Server Agent Account to run the package. To solve this we will create an XML file which stores the password and can be accessed by the package by anyone. This raises fresh security concerns which I solved by placing the configuration file on the server.</p>
<p>To create the XML File:</p>
<p>1) load the package into the designer.<br />
2) Double click on the package in the solution explorer pane.<br />
3) Click on Add&#8230;<br />
4) Select XML Configuration File as Configuration Type.<br />
5) Select specify Configuration Settings directly.<br />
6) Click on Browse.<br />
7) Select where you want to save your file and name it eg Config.dtsConfig.<br />
8 ) Click next.<br />
9) Expand Connection Managers -&gt; Oracle Connection -&gt; Properties.<br />
10) Select Password.<br />
11) Click next.<br />
12) Change the configuration name.<br />
13) Click Finish and close.<br />
Now navigate to package properties and change the ProtectionLevel to DontSaveSensitive. This tells the package that the password will be recieved from the XML file and won&#8217;t be saved with the package.</p>
<p>Navigate to the xml file and open it up with the XML editor of your choice (I prefer notepad).</p>
<p>To run the package from SQL Server Agent:</p>
<p>1) Open SQL Server Management Studio.<br />
2) Expand the Server.<br />
3) Expand SQL Server Agent.<br />
4) Right click on jobs and click on New Job.<br />
5) Create a Step.<br />
6) Call the step something meaningful.<br />
7) Select File System as Package Source.<br />
8 ) Under the Package tab search for the package file.<br />
9) Click OK</p>
<p>When the job is executed it will retrieve the Oracle Server Password from the XML File, connect and Execute.</p>
]]></content:encoded>
			<wfw:commentRss>http://3vl.co.uk/?feed=rss2&amp;p=69</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Index Fragmentation Part 2</title>
		<link>http://3vl.co.uk/?p=64</link>
		<comments>http://3vl.co.uk/?p=64#comments</comments>
		<pubDate>Thu, 15 Apr 2010 10:49:18 +0000</pubDate>
		<dc:creator>David Bainbridge</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Database Optimisation]]></category>

		<guid isPermaLink="false">http://3vl.co.uk/?p=64</guid>
		<description><![CDATA[Further to my previous post Index Fragmentation you can use the following script to automatically rebuild and reorganize indexes.
I have it installed in an agent job that runs daily:
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;
&#8211; Rebuild the Indexes in EBS
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;
&#8211; Declare the Variables
DECLARE  @Table_ID  int,
   @Index_ID  int,
   @Pages   bigint,
   @Index_Name sysname,
   @Fragmentation float,
   @Table_Name sysname,
   @Alter   varchar(200)
&#8211; Declare the Cursor
DECLARE Indexes CURSOR FOR
SELECT  ID.object_id AS Table_ID
  ,ID.index_id AS Index_ID
  ,ID.page_count [...]]]></description>
			<content:encoded><![CDATA[<p>Further to my previous post <a title="Index Fragmentation" href="http://3vl.co.uk/?p=43" target="_self">Index Fragmentation</a> you can use the following script to automatically rebuild and reorganize indexes.</p>
<p>I have it installed in an agent job that runs daily:</p>
<blockquote><p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
&#8211; Rebuild the Indexes in EBS<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>&#8211; Declare the Variables<br />
DECLARE  @Table_ID  int,<br />
   @Index_ID  int,<br />
   @Pages   bigint,<br />
   @Index_Name sysname,<br />
   @Fragmentation float,<br />
   @Table_Name sysname,<br />
   @Alter   varchar(200)</p>
<p>&#8211; Declare the Cursor<br />
DECLARE Indexes CURSOR FOR</p>
<p>SELECT  ID.object_id AS Table_ID<br />
  ,ID.index_id AS Index_ID<br />
  ,ID.page_count AS Pages<br />
  ,I.name AS Index_Name<br />
  ,ID.Avg_Fragmentation_In_Percent AS Fragmentation<br />
  ,T.name AS Table_Name</p>
<p>FROM  sys.dm_db_index_physical_stats (db_id(), NULL,NULL, NULL, NULL) AS ID<br />
JOIN  sys.indexes AS I WITH(NOLOCK)<br />
ON   ID.Object_id = I.Object_id<br />
 AND   ID.Index_id = I.Index_id<br />
JOIN sys.objects AS T<br />
ON  T.object_id = I.object_id<br />
WHERE  I.name IS NOT NULL</p>
<p>OPEN Indexes<br />
FETCH Indexes INTO @Table_ID,<br />
     @Index_ID,<br />
     @Pages,<br />
     @Index_Name,<br />
     @Fragmentation,<br />
     @Table_Name </p>
<p>&#8211; Start the Processing Loop<br />
WHILE @@Fetch_Status = 0<br />
   BEGIN</p>
<p> IF @Fragmentation &gt;30<br />
 BEGIN<br />
  set @alter = &#8216;ALTER INDEX &#8216; + @Index_Name + &#8216; ON &#8216; + @Table_Name + &#8216; REBUILD&#8217;;<br />
  exec(@alter);<br />
 END<br />
 ELSE IF @Fragmentation &gt;10<br />
 BEGIN<br />
  set @alter = &#8216;ALTER INDEX &#8216; + @Index_Name + &#8216; ON &#8216; + @Table_Name + &#8216; REORGANIZE&#8217;;<br />
  exec(@alter);<br />
 END</p>
<p> &#8211; Perform Row-by-row Processing.<br />
 &#8211; Get the Next Row<br />
 FETCH Indexes INTO @Table_ID,<br />
      @Index_ID,<br />
      @Pages,<br />
      @Index_Name,<br />
      @Fragmentation,<br />
      @Table_Name<br />
 END</p>
<p>CLOSE Indexes</p>
<p>DEALLOCATE Indexes</p>
<p>RETURN</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://3vl.co.uk/?feed=rss2&amp;p=64</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Case Manipulation</title>
		<link>http://3vl.co.uk/?p=62</link>
		<comments>http://3vl.co.uk/?p=62#comments</comments>
		<pubDate>Thu, 15 Apr 2010 09:38:39 +0000</pubDate>
		<dc:creator>David Bainbridge</dc:creator>
				<category><![CDATA[Strings]]></category>

		<guid isPermaLink="false">http://3vl.co.uk/?p=62</guid>
		<description><![CDATA[When printing off address lables I noticed the title field was all different cases: MR mr Mr and mR abounded.
This doesnt look very professional on letters!
Microsoft provides Ucase to make a text field upper case and Lcase to make it lower case. Its easy to combine the two to make a field have capital first [...]]]></description>
			<content:encoded><![CDATA[<p>When printing off address lables I noticed the title field was all different cases: MR mr Mr and mR abounded.</p>
<p>This doesnt look very professional on letters!</p>
<p>Microsoft provides Ucase to make a text field upper case and Lcase to make it lower case. Its easy to combine the two to make a field have capital first letters and lower case for the remainder:</p>
<blockquote><p>Ucase(left({Field},1)) &amp; Lcase(right({Field},len({Field})-1))</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://3vl.co.uk/?feed=rss2&amp;p=62</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
