<?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>Luke Hayler - SQL Server developer &#187; expressions</title>
	<atom:link href="http://www.lukehayler.com/tag/expressions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lukehayler.com</link>
	<description>A blog about Integration services, Reporting services, and the things that interest me</description>
	<lastBuildDate>Wed, 08 Sep 2010 11:36:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Setting the SQL Command Property using Expressions in SSIS 2005</title>
		<link>http://www.lukehayler.com/2010/03/setting-the-sql-command-property-using-expressions-in-ssis-2005/</link>
		<comments>http://www.lukehayler.com/2010/03/setting-the-sql-command-property-using-expressions-in-ssis-2005/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 12:15:00 +0000</pubDate>
		<dc:creator>Luke Hayler</dc:creator>
				<category><![CDATA[Integration Services]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[data sources]]></category>
		<category><![CDATA[expressions]]></category>
		<category><![CDATA[properties]]></category>
		<category><![CDATA[sql server 2005]]></category>
		<category><![CDATA[SSIS]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://www.lukehayler.com/2010/03/setting-the-sql-command-property-using-expressions-in-ssis-2005/</guid>
		<description><![CDATA[&#160;
OLE DB Source Adapter
The OLE DB source connection has several Access Modes:

Openrowset 
Openrowset From Variable 
SQL Command 
SQL Command From Variable 

For now, I am going to focus on the SQL Command options. Using the SQL Command Access Mode requires you to set the SqlCommand property (typing in your SQL query directly), effectively ‘hard coding’ [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<h4>OLE DB Source Adapter</h4>
<p>The OLE DB source connection has several <em>Access Modes:</em></p>
<ul>
<li>Openrowset </li>
<li>Openrowset From Variable </li>
<li>SQL Command </li>
<li>SQL Command From Variable </li>
</ul>
<p>For now, I am going to focus on the SQL Command options. Using the <em>SQL Command</em> Access Mode requires you to set the SqlCommand property (typing in your SQL query directly), effectively ‘hard coding’ the sql statement into the package. Using the <em>SQL Command From Variable</em> option allows you to set the SqlCommand property using a variable and subsequently by using an expression. </p>
<p><a href="http://www.lukehayler.com/wp-content/uploads/2010/03/SSIS2005_DataSource_AccessMode_Properties_OLEDBSource.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SSIS2005_DataSource_AccessMode_Properties_OLEDBSource" border="0" alt="SSIS2005_DataSource_AccessMode_Properties_OLEDBSource" src="http://www.lukehayler.com/wp-content/uploads/2010/03/SSIS2005_DataSource_AccessMode_Properties_OLEDBSource_thumb.png" width="560" height="268" /></a></p>
<p>&#160;</p>
<h4>Data Reader Source</h4>
<p>The Data Reader Source connection has only one Access Mode, and that is <em>SQL Command</em>. Don’t ask me why. At this level you can only set the SqlCommand property by typing in your query, or indeed, copy &amp; paste. </p>
<p><a href="http://www.lukehayler.com/wp-content/uploads/2010/03/SSIS2005_DataSource_AccessMode_Properties_DataReaderSource.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SSIS2005_DataSource_AccessMode_Properties_DataReaderSource" border="0" alt="SSIS2005_DataSource_AccessMode_Properties_DataReaderSource" src="http://www.lukehayler.com/wp-content/uploads/2010/03/SSIS2005_DataSource_AccessMode_Properties_DataReaderSource_thumb.png" width="560" height="272" /></a> </p>
<p>&#160;</p>
<h4>Using an Expression to set the SqlCommand Property</h4>
<p>“So then,” you ask, “how might I set the SqlCommand property for each of these Data Sources when it seems that I can’t?”. Here’s how. Let’s first concentrate on the OLE DB Source:</p>
<ol>
<li>Create a new Variable of type string and set your SQL statement </li>
<li>Open up the OLE DB Source and select the ‘SQL Command from Variable’ option </li>
<li>Now, select the the variable created in step 1 as the variable that contains the SQL statement </li>
</ol>
<p><a href="http://www.lukehayler.com/wp-content/uploads/2010/03/SSIS2005_DataAccessMode_OLEDBSource_Editor.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SSIS2005_DataAccessMode_OLEDBSource_Editor" border="0" alt="SSIS2005_DataAccessMode_OLEDBSource_Editor" src="http://www.lukehayler.com/wp-content/uploads/2010/03/SSIS2005_DataAccessMode_OLEDBSource_Editor_thumb.png" width="520" height="200" /></a> </p>
<p>At this point your OLE DB source is defined by the query that you have set in the Variable. We now need to create the expression that will define the query at runtime. We do this by navigating to the variable’s properties, setting the <em>EvaluateAsExpression </em>property to <strong>True</strong> and then configuring the expression in the <em>Expression</em> property.</p>
<p>Moving on to the Data Reader Source. With this adapter we only have the option of setting the SqlCommand directly. Or so I thought until recently. If you switch to the Control Flow design surface and select the Data Flow task that contains the Data Reader Source adapter, you will be able to set the SqlCommand using an expression.</p>
<ol>
<li>Select the Data Flow task to bring up its properties </li>
<li>Click the ellipsis (…) to bring up the Expression Editor </li>
<li>Select the [DataReader Source].[SqlCommand] Property </li>
<li>Set your expression. </li>
</ol>
<p><a href="http://www.lukehayler.com/wp-content/uploads/2010/03/SSIS2005_DataSource_AccessMode_Properties_DataFlowTask_Expressions.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SSIS2005_DataSource_AccessMode_Properties_DataFlowTask_Expressions" border="0" alt="SSIS2005_DataSource_AccessMode_Properties_DataFlowTask_Expressions" src="http://www.lukehayler.com/wp-content/uploads/2010/03/SSIS2005_DataSource_AccessMode_Properties_DataFlowTask_Expressions_thumb.png" width="560" height="262" /></a> </p>
<p><a href="http://www.lukehayler.com/wp-content/uploads/2010/03/SSIS2005_DataSource_AccessMode_Properties_DataFlowTask_ExpressionProperties.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SSIS2005_DataSource_AccessMode_Properties_DataFlowTask_ExpressionProperties" border="0" alt="SSIS2005_DataSource_AccessMode_Properties_DataFlowTask_ExpressionProperties" src="http://www.lukehayler.com/wp-content/uploads/2010/03/SSIS2005_DataSource_AccessMode_Properties_DataFlowTask_ExpressionProperties_thumb.png" width="560" height="382" /></a> </p>
<p>Using variables &amp; expressions to set your queries enables you to centralise your queries, use configuration files to set database connections and capture the queries you are running in logging operations.&#160;&#160; </p>
]]></content:encoded>
			<wfw:commentRss>http://www.lukehayler.com/2010/03/setting-the-sql-command-property-using-expressions-in-ssis-2005/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The DatePart() Function in SSRS</title>
		<link>http://www.lukehayler.com/2009/11/the-datepart-function-in-ssrs/</link>
		<comments>http://www.lukehayler.com/2009/11/the-datepart-function-in-ssrs/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 08:00:00 +0000</pubDate>
		<dc:creator>Luke Hayler</dc:creator>
				<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[collections]]></category>
		<category><![CDATA[dateinterval]]></category>
		<category><![CDATA[datepart]]></category>
		<category><![CDATA[dates]]></category>
		<category><![CDATA[expressions]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[SSRS]]></category>

		<guid isPermaLink="false">http://www.lukehayler.com/2009/11/the-datepart-function-in-ssrs/</guid>
		<description><![CDATA[Using the DatePart() Function in SSRS can be tricky, even at the best of times. I have pulled my hair out too often trying to remember what syntax should be used, so have resorted to writing down all my findings. This is so that you don’t have to go through the same agony &#38; frustration [...]]]></description>
			<content:encoded><![CDATA[<p>Using the DatePart() Function in SSRS can be tricky, even at the best of times. I have pulled my hair out too often trying to remember what syntax should be used, so have resorted to writing down all my findings. This is so that you don’t have to go through the same agony &amp; frustration as I did, as well as for my own benefit (my memory is shot…)</p>
<p>What it does: Returns an Integer containing the specified part of a given date</p>
<blockquote><p><strong>Syntax</strong>: DatePart(interval, date[,firstdayofweek[,firstweekofyear]])</p>
</blockquote>
<p>There are two ways to use this function:</p>
<ul>
<li>Using the DateInterval collection </li>
<li>Using a string expression </li>
</ul>
<h5>&#160;</h5>
<h5>Using the DateInterval Collection</h5>
<p>Let’s start with an example:</p>
<blockquote><p>To return the current month: =DatePart(DateInterval.Month, Today())</p>
</blockquote>
<p>Now, in the expression builder (in BIDS), it will look like there’s something the matter with what we have just written:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8747F07C-CDE8-481f-B0DF-C6CFD074BF67:12d6157d-8b28-4296-909e-c5d87f979888" class="wlWriterEditableSmartContent"><a href="http://www.lukehayler.com/wp-content/uploads/2009/11/SSRS_DatePartFunction_18x6.png" title="Only 'Clippy' is missing...there is nothing wrong with this expression" rel="thumbnail"><img border="0" src="http://www.lukehayler.com/wp-content/uploads/2009/11/SSRS_DatePartFunction_1.png" width="425" height="112" /></a></div>
<p>You can ignore this, the expression <u>will</u> work. An important point to note when using the DateInterval collection, is that you <u>must</u> use a date that is of type Datetime. If you use a string representation of a date (“2009/11/13”), then you’ll need to convert this to Datetime using <em>CDate(“2009/11/13”) </em>before the expression will work. Thus: </p>
<blockquote><p>This will work:&#160; =DatePart(DateInterval.Month, CDate(“2009/11/13”))</p>
<p>This won’t:&#160; = DatePart(DateInterval.Month, “2009/11/13”)</p>
</blockquote>
</p>
<p>When you use the DatePart function to identify the day of the week you can specify what the <em>First Day Of The Week</em> is (defaults to Sunday if this is not specified). You can do this by accessing the <strong>FirstDayOfWeek</strong> collection. Example &#8211; To Return the day of the week, specifying Monday as the first day of the week:</p>
<blockquote><p>DatePart(DateInterval.Weekday, CDate(“2009/11/13”), FirstDayOfWeek.Monday) <strong>returns 5 (Friday)</strong></p>
</blockquote>
<h5>All the possibilities for using the DatePart() function with the DateInterval Collection:</h5>
<p>The following table shows all the possibilities for the DatePart Function using the DateInterval collection. All expressions use a Parameter called MyDate (type = Datetime), which has a value of “2009/11/13 12:34:23”</p>
<table border="1" cellspacing="0" cellpadding="2" width="585">
<tbody>
<tr>
<td valign="top" width="535"><strong>Expression</strong></td>
<td valign="top" width="48"><strong>Result</strong></td>
</tr>
<tr>
<td valign="top" width="535">DatePart(DateInterval.Second, Parameters!MyDate.Value)</td>
<td valign="top" width="48">23</td>
</tr>
<tr>
<td valign="top" width="535">DatePart(DateInterval.Minute, Parameters!MyDate.Value)</td>
<td valign="top" width="48">34</td>
</tr>
<tr>
<td valign="top" width="535">DatePart(DateInterval.Hour, Parameters!MyDate.Value)</td>
<td valign="top" width="48">12</td>
</tr>
<tr>
<td valign="top" width="535">DatePart(DateInterval.Weekday, Parameters!MyDate.Value, FirstDayOfWeek.Monday)</td>
<td valign="top" width="48">5</td>
</tr>
<tr>
<td valign="top" width="535">DatePart(DateInterval.Day, Parameters!MyDate.Value)</td>
<td valign="top" width="48">13</td>
</tr>
<tr>
<td valign="top" width="535">DatePart(DateInterval.DayOfYear, Parameters!MyDate.Value)</td>
<td valign="top" width="48">317</td>
</tr>
<tr>
<td valign="top" width="535">DatePart(DateInterval.WeekOfYear, Parameters!MyDate.Value)</td>
<td valign="top" width="48">46</td>
</tr>
<tr>
<td valign="top" width="535">DatePart(DateInterval.Month, Parameters!MyDate.Value)</td>
<td valign="top" width="48">11</td>
</tr>
<tr>
<td valign="top" width="535">DatePart(DateInterval.Quarter, Parameters!MyDate.Value)</td>
<td valign="top" width="48">4</td>
</tr>
<tr>
<td valign="top" width="535">DatePart(DateInterval.Year, Parameters!MyDate.Value)</td>
<td valign="top" width="48">2009</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<h5>Using a String Expression</h5>
<p>Again, let’s start with an example:</p>
<blockquote><p>To return the current month:&#160; =DatePart(“m”, Today())</p>
</blockquote>
<p>Using a String expression for your <em>interval </em>enables you to use a date that is of datatype String:</p>
<blockquote><p>=DatePart(“m”, “2009/11/13”)</p>
</blockquote>
<h5>All the possibilities for using the DatePart() function with a String Expression:</h5>
<p>As noted previously, using a string expression for the interval allows you to use a date value that is of the String datatype. You can of course use a Datetime value if you wish to.</p>
<p>This table shows all the possibilities for the DatePart function using a String Expression for the <em>interval.</em> All expressions use a Parameter called MyDate (type = String), which has a value of “2009/11/13 12:34:23”</p>
<table border="1" cellspacing="0" cellpadding="2" width="586">
<tbody>
<tr>
<td valign="top" width="101"><strong>Date Part</strong></td>
<td valign="top" width="430"><strong>Expression</strong></td>
<td valign="top" width="53"><strong>Result</strong></td>
</tr>
<tr>
<td valign="top" width="101">Second</td>
<td valign="top" width="430">DatePart(“s”, Parameters!MyDate.Value)</td>
<td valign="top" width="53">23</td>
</tr>
<tr>
<td valign="top" width="101">Minute</td>
<td valign="top" width="430">DatePart(“n”, Parameters!MyDate.Value)</td>
<td valign="top" width="53">34</td>
</tr>
<tr>
<td valign="top" width="101">Hours</td>
<td valign="top" width="430">DatePart(“h”, Parameters!MyDate.Value)</td>
<td valign="top" width="53">12</td>
</tr>
<tr>
<td valign="top" width="101">Day of Week</td>
<td valign="top" width="430">DatePart(“w”, Parameters!MyDate.Value, FirstDayOfWeek.Monday)</td>
<td valign="top" width="53">5</td>
</tr>
<tr>
<td valign="top" width="101">Day of Month</td>
<td valign="top" width="430">DatePart(“d”, Parameters!MyDate.Value)</td>
<td valign="top" width="53">13</td>
</tr>
<tr>
<td valign="top" width="101">Day of Year</td>
<td valign="top" width="430">DatePart(“y”, Parameters!MyDate.Value)</td>
<td valign="top" width="53">317</td>
</tr>
<tr>
<td valign="top" width="101">Week of Year</td>
<td valign="top" width="430">DatePart(“ww”, Parameters!MyDate.Value)</td>
<td valign="top" width="53">46</td>
</tr>
<tr>
<td valign="top" width="101">Month</td>
<td valign="top" width="430">DatePart(“m”, Parameters!MyDate.Value)</td>
<td valign="top" width="53">11</td>
</tr>
<tr>
<td valign="top" width="101">Quarter</td>
<td valign="top" width="430">DatePart(“q”, Parameters!MyDate.Value)</td>
<td valign="top" width="53">4</td>
</tr>
<tr>
<td valign="top" width="101">Year</td>
<td valign="top" width="430">DatePart(“yyyy”, Parameters!MyDate.Value)</td>
<td valign="top" width="53">2009</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<h5>Is there a preferred method?</h5>
<p>Ultimately, no. At the end of the day, all the results are the same. What is my preference? I use the DateInterval collection, mainly becuase I like that fact that you can’t get confused about which date part you are using (w/ww, y/yyyy, n….). It’s very clear to anyone who is reading the code that (for example) DateInterval.WeekOfYear refers to the week of the year and nothing else. It also forces you to use a Datetime Value, which safeguards against invalid dates (sort of).</p>
<p>I hope this clears things up a little!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lukehayler.com/2009/11/the-datepart-function-in-ssrs/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>The CHOOSE() Function in SSRS</title>
		<link>http://www.lukehayler.com/2009/07/the-choose-function-in-ssrs/</link>
		<comments>http://www.lukehayler.com/2009/07/the-choose-function-in-ssrs/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 18:00:45 +0000</pubDate>
		<dc:creator>Luke Hayler</dc:creator>
				<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[expressions]]></category>

		<guid isPermaLink="false">http://www.lukehayler.com/?p=74</guid>
		<description><![CDATA[BOL’s description of the CHOOSE() Function: “Selects and returns a value from a list or arguments”. The syntax of the function is as follows:
=CHOOSE(index, expression_1 [, expression_2] [, expression_3] [, expression_4] &#8230;[, expression_n])
So, the Choose() function uses an Index (of type Double) to ‘choose’ one of a list of supplied values/expressions. For example;
=CHOOSE(Index, “Red”, “Yellow”, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://msdn.microsoft.com/en-us/library/824bz7dy.aspx">BOL’s description of the CHOOSE() Function</a>: “Selects and returns a value from a list or arguments”. The syntax of the function is as follows:</p>
<p><strong>=CHOOSE(index, expression_1 [, expression_2] [, expression_3] [, expression_4] &#8230;[, expression_n])</strong></p>
<p>So, the Choose() function uses an <strong>Index </strong>(of type Double) to ‘choose’ one of a list of supplied <strong>values/expressions</strong>. For example;</p>
<p>=CHOOSE(Index, “Red”, “Yellow”, “Green”, “Grey”, “Black”, “White”)</p>
<p>When Index = 3, then the result is “<strong><em>Green</em></strong>”. When Index = 5, then the result is “<strong><em>Black</em></strong>”</p>
<p>Let’s look at a practical example:</p>
<p>I have a report (a simple chart at this stage) that relies on any one of a number of values to decide which metric to display – these values are provided to the user via a parameterized drop down list in the report, they simply choose which metric they want and the appropriate data is displayed. In the chart, I use an expression to decide on which metric is to be used based on the value returned by the parameter. Previously, I would have used an IIF() statement to do this, although I now have 7 values and this makes the IIF() statement far too ‘involved’.</p>
<p>Figure 1. shows the <strong>Metrics </strong>parameter and some of the values used:</p>
<div id="attachment_75" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-75" title="Fig 1. Setting the Metrics Parameter Values" src="http://www.lukehayler.com/wp-content/uploads/2009/07/choose-function-parameters-example-300x235.jpg" alt="Fig 1. Setting the Metrics Parameter Values" width="300" height="235" /><p class="wp-caption-text">Fig 1. Setting the Metrics Parameter Values</p></div>
<p>The expression that is used in the chart (to get the data) is as follows:</p>
<p><strong>=CHOOSE(Parameters!Metrics.Value, Fields!TotalItems.Value, Fields!OpenItems.Value, Fields!ClosedItems.Value, Fields!AveragePrice.Value, Fields!GrossProfit.Value)</strong></p>
<p><strong> </strong></p>
<div id="attachment_76" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-76" title="Fig 2. Setting the Expression for the Data Values" src="http://www.lukehayler.com/wp-content/uploads/2009/07/SSRS-CHOOSE-Function-300x270.jpg" alt="Fig 2. Setting the Expression for the Data Values" width="300" height="270" /><p class="wp-caption-text">Fig 2. Setting the Expression for the Data Values</p></div>
<p>When the user selects <strong><em>Total Items</em></strong> from the Parameter drop-down, a value of ‘1’ is passed to the CHOOSE() function which in turn selects <strong><em>Fields!TotalItems.Value</em></strong> as the data to use in the Chart Object. I have also used this expression to set the appropriate Series Label value.</p>
<p>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lukehayler.com/2009/07/the-choose-function-in-ssrs/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The DateAdd() Function in SSRS</title>
		<link>http://www.lukehayler.com/2009/07/the-dateadd-function-in-ssrs/</link>
		<comments>http://www.lukehayler.com/2009/07/the-dateadd-function-in-ssrs/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 08:00:36 +0000</pubDate>
		<dc:creator>Luke Hayler</dc:creator>
				<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[dates]]></category>
		<category><![CDATA[expressions]]></category>
		<category><![CDATA[syntax]]></category>

		<guid isPermaLink="false">http://www.lukehayler.com/?p=9</guid>
		<description><![CDATA[Getting acquainted
The DateAdd() function. According to BOL this &#8220;Returns a date to which a specified time interval has been added&#8221;. The structure of the function is as follows:
DateAdd(interval, number, date)
It&#8217;s a Date!
Like most first dates, getting to grips with this function and understanding its &#8216;needs&#8217; is a tricky process. Initially, you may have attempted to [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Getting acquainted</strong></p>
<p>The DateAdd() function. According to BOL this &#8220;Returns a date to which a specified time interval has been added&#8221;. The structure of the function is as follows:</p>
<p><em>DateAdd(interval, number, date)</em></p>
<p><strong>It&#8217;s a Date!</strong></p>
<p>Like most first dates, getting to grips with this function and understanding its &#8216;needs&#8217; is a tricky process. Initially, you may have attempted to use the tried-and-trusted methods (aka &#8217;syntax&#8217;), <em>DateAdd(mm, 1, Now()). </em>No. Ok, let&#8217;s try <em>DateAdd(&#8216;mm&#8217;, 1, now())</em>. Nope. What about <em>DateAdd(month, 1, Now()). </em>Good luck with that&#8230;Yes. It&#8217;s a little mystifying.</p>
<p><strong>Score!</strong></p>
<p>There are a couple of ways to achieve the desired result with this function. 1.) use the <em>DateInterval</em> collection, or 2.) use the date part abbreviations. My recommendation? Use the DateInterval collection. Using the abbreviations, there is a chance that something will be calculated differently to what you&#8217;d expect (I explain a little further on). The <em>DateInterval</em> collection can be found in the Object Browser and looks like this:</p>
<div id="attachment_45" class="wp-caption aligncenter" style="width: 297px"><img class="size-full wp-image-45" title="The DateInterval Collection" src="http://www.lukehayler.com/wp-content/uploads/2009/07/DateAdd_DateIntervals.jpg" alt="A list of all the Intervals in the DateInterval collection" width="287" height="237" /><p class="wp-caption-text">Fig 1. A list of all the Intervals in the DateInterval collection</p></div>
<p>&#8220;So how do you use this in the function?&#8221; I hear you ask.</p>
<p><em>=DateAdd(<strong>DateInterval.Month</strong>, 1, Today())</em> which gives you a date 1 month from today.</p>
<p>This will work for all the intervals listed in Fig 1. above.</p>
<p>If you don&#8217;t want to use this method and instead want to use the abbreviations then there are a few things to be weary of. For instance, using <em>DateAdd(&#8220;w&#8221;, 1, Today())</em> does not yield a date 1 <strong>week</strong> from today, but rather 1 <strong>day</strong> from today. This happens with a couple of other abbreviations as well. The reason is that &#8220;w&#8221; represents &#8220;weekday&#8221; not &#8220;week&#8221;. Here is an shortlist of the abbreviations that do work:</p>
<ul>
<li>Days ["dd"] &#8211; DateAdd(&#8220;dd&#8221;, 1, today())</li>
<li>Weeks ["ww"] &#8211; DateAdd(&#8220;ww&#8221;, 1, today())</li>
<li>Months ["mm"] &#8211; DateAdd(&#8220;mm&#8221;, 1, today())</li>
<li>Years ["yyyy"] &#8211; DateAdd(&#8220;yyyy&#8221;, 1, today())</li>
</ul>
<p>For a full list of abbreviations and further explanation, msdn delivers <a href="http://msdn.microsoft.com/en-us/library/cb7z8yf9(VS.85).aspx">here</a>.</p>
<p>Hopefully this clears up a little of the confusion surrounding the DateAdd() function and the intervals that need to be specified. Of course, if there are other methods that can be used or I&#8217;m all ears.</p>
<p>I like keep an open mind. When working with windows, one must.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lukehayler.com/2009/07/the-dateadd-function-in-ssrs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
