<?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>Cogniza &#187; SQL Server</title>
	<atom:link href="http://cogniza.com/wordpress/tag/sql-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://cogniza.com/wordpress</link>
	<description>Business-Intelligence Specialists</description>
	<lastBuildDate>Sat, 30 Apr 2011 13:22:21 +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>SQL Server: Date Arithmetic</title>
		<link>http://cogniza.com/wordpress/2009/11/05/sql-server-date-arithmetic/</link>
		<comments>http://cogniza.com/wordpress/2009/11/05/sql-server-date-arithmetic/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 02:32:24 +0000</pubDate>
		<dc:creator>Craig Buchanan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Technique]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://www.cogniza.com/blog/?p=106</guid>
		<description><![CDATA[Useful, dynamically-generated dates for SQL Server.

--[1st day  of current month]: use the GetDate(), Month(), and Year() functions to determine the current month and year.   Build a string using these values in MM/01/YYYY format.  Convert the String to DateTime.
 CAST( CAST( Month(GetDate()) AS Char(2) ) + '/01/' + CAST( Year(GetDate()) AS Char(4)) [...]]]></description>
			<content:encoded><![CDATA[<p>Useful, dynamically-generated dates for SQL Server.<span id="more-106"></span><br />
<code><br />
--[1st day  of current month]: use the GetDate(), Month(), and Year() functions to determine the current month and year.   Build a string using these values in MM/01/YYYY format.  Convert the String to DateTime.<br />
 CAST( CAST( Month(GetDate()) AS Char(2) ) + '/01/' + CAST( Year(GetDate()) AS Char(4)) AS DateTime)<br />
</code><code><br />
--[Last day of current month]: add a month to [1st day of current month], then subtract a day.<br />
DateAdd(m, 1, CAST( CAST( Month(GetDate()) AS Char(2) ) + '/01/' + CAST( Year(GetDate()) AS Char(4)) AS DateTime)) -1<br />
</code><code><br />
--[1st day of prior month]: subtract a month from [1st day of current month].<br />
DateAdd(m, -1, CAST( CAST( Month(GetDate()) AS Char(2) ) + '/01/' + CAST( Year(GetDate()) AS Char(4)) AS DateTime))<br />
</code><code><br />
--[Last day of prior month]:  subtract a day from [1st day of current month].<br />
CAST( CAST( Month(GetDate()) AS Char(2) ) + '/01/' + CAST( Year(GetDate()) AS Char(4)) AS DateTime) -1<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://cogniza.com/wordpress/2009/11/05/sql-server-date-arithmetic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server: MaximumDate() Function</title>
		<link>http://cogniza.com/wordpress/2007/01/26/sql-server/</link>
		<comments>http://cogniza.com/wordpress/2007/01/26/sql-server/#comments</comments>
		<pubDate>Fri, 26 Jan 2007 15:04:05 +0000</pubDate>
		<dc:creator>Craig Buchanan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Transact-SQL]]></category>

		<guid isPermaLink="false">http://www.cogniza.com/blog/?p=96</guid>
		<description><![CDATA[A SQL Server, scalar-value function that returns the greater of two dates.]]></description>
			<content:encoded><![CDATA[<p>A SQL Server, scalar-value function that returns the greater of two dates.<span id="more-96"></span></p>
<pre>set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

/*----------------------------------------------------------------------------------------------------
Author:        Craig Buchanan
Date:        2/6/2006
Description:    Returns the greater of two dates
Parameters:    @Date1 - datetime to be compared
@Date2 - datetime to be compared
----------------------------------------------------------------------------------------------------*/
CREATE FUNCTION [dbo].[MaximumDate] (
@Date1    datetime,
@Date2    datetime
)

RETURNS datetime AS
BEGIN

RETURN CASE
WHEN @Date1 IS NULL AND @Date2 IS NULL THEN NULL
WHEN @Date1 IS NULL THEN @Date2
WHEN @Date2 IS NULL THEN @Date1
WHEN @Date1 &gt; @Date2 THEN @Date1
WHEN @Date2 &gt; @Date1 THEN @Date2
WHEN @Date2 = @Date1 THEN @Date2
ELSE NULL
END

END</pre>
]]></content:encoded>
			<wfw:commentRss>http://cogniza.com/wordpress/2007/01/26/sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server: MinimumDate() Function</title>
		<link>http://cogniza.com/wordpress/2007/01/26/sql-server-minimumdate-function/</link>
		<comments>http://cogniza.com/wordpress/2007/01/26/sql-server-minimumdate-function/#comments</comments>
		<pubDate>Fri, 26 Jan 2007 15:02:30 +0000</pubDate>
		<dc:creator>Craig Buchanan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Transact-SQL]]></category>

		<guid isPermaLink="false">http://www.cogniza.com/blog/?p=95</guid>
		<description><![CDATA[A SQL Server, scalar-value function that returns the lessor of two dates.
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
/*----------------------------------------------------------------------------------------------------
Author:        Craig Buchanan
Date:        2/6/2006
Description:    Returns the lessor of two dates
Parameters:    @Date1 - datetime to be compared
@Date2 - datetime to be [...]]]></description>
			<content:encoded><![CDATA[<p>A SQL Server, scalar-value function that returns the lessor of two dates.<span id="more-95"></span></p>
<pre>set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
/*----------------------------------------------------------------------------------------------------
Author:        Craig Buchanan
Date:        2/6/2006
Description:    Returns the lessor of two dates
Parameters:    @Date1 - datetime to be compared
@Date2 - datetime to be compared
----------------------------------------------------------------------------------------------------*/
CREATE FUNCTION [dbo].[MinimumDate] (
@Date1    datetime,
@Date2    datetime
)
RETURNS datetime AS
BEGIN

RETURN CASE
WHEN @Date1 IS NULL AND @Date2 IS NULL THEN NULL
WHEN @Date1 IS NULL THEN @Date2
WHEN @Date2 IS NULL THEN @Date1
WHEN @Date1 &lt; @Date2 THEN @Date1
WHEN @Date2 &lt; @Date1 THEN @Date2
WHEN @Date2 = @Date1 THEN @Date2
ELSE NULL
END

END</pre>
]]></content:encoded>
			<wfw:commentRss>http://cogniza.com/wordpress/2007/01/26/sql-server-minimumdate-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server: Import DTS Packages using a Script</title>
		<link>http://cogniza.com/wordpress/2006/11/16/sql-server-import-dts-packages-using-a-script/</link>
		<comments>http://cogniza.com/wordpress/2006/11/16/sql-server-import-dts-packages-using-a-script/#comments</comments>
		<pubDate>Thu, 16 Nov 2006 19:09:14 +0000</pubDate>
		<dc:creator>Craig Buchanan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[VB Script]]></category>

		<guid isPermaLink="false">http://www.cogniza.com/blog/?p=87</guid>
		<description><![CDATA[Use a VB Script file to import .DTS files into the local Sql Server database.]]></description>
			<content:encoded><![CDATA[<p>Use a VB Script file to import .DTS files into the local Sql Server database.</p>
<p><span id="more-87"></span></p>
<p><code><br />
'determine current file location<br />
Dim Path: Path=Left(WScript.ScriptFullName,Len(WScript.ScriptFullName)-Len(WScript.ScriptName)-1)</code><code>'.DTS files to be imported<br />
Dim Sources: Sources = Array("File0.dts","File1.dts")</code></p>
<p>&#8216;import each file<br />
Dim i<br />
For i = 0 To Ubound(Sources)<br />
Import Path &amp; &#8220;\&#8221; &amp; Sources(i)<br />
Next</p>
<p>Sub Import(FilePath)</p>
<p>Dim P: Set P = CreateObject(&#8220;DTS.Package&#8221;)<br />
With P<br />
.LoadFromStorageFile FilePath, &#8220;&#8221;<br />
&#8216;import to local database, using a trusted connection<br />
.SaveToSQLServer &#8220;(local)&#8221;, , ,256<br />
End With</p>
<p>Set P = Nothing</p>
<p>End Sub</p>
]]></content:encoded>
			<wfw:commentRss>http://cogniza.com/wordpress/2006/11/16/sql-server-import-dts-packages-using-a-script/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sql Server: DateRanges() Function</title>
		<link>http://cogniza.com/wordpress/2006/05/25/sql-server-dateranges-function/</link>
		<comments>http://cogniza.com/wordpress/2006/05/25/sql-server-dateranges-function/#comments</comments>
		<pubDate>Thu, 25 May 2006 16:37:08 +0000</pubDate>
		<dc:creator>Craig Buchanan</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Date/Time]]></category>
		<category><![CDATA[Transact-SQL]]></category>

		<guid isPermaLink="false">http://www.cogniza.com/blog/?p=79</guid>
		<description><![CDATA[This user-defined function creates a table of date ranges.]]></description>
			<content:encoded><![CDATA[<p>This user-defined function creates a table of date ranges.<span id="more-79"></span></p>
<p><code> --================================================================================<br />
--Author:    Craig <a href="mailto:Buchanan;craig.buchanan@cogniza.com" title="Linkification: mailto:Buchanan;craig.buchanan@cogniza.com" class="linkification-ext" style="color: #ffcc33">Buchanan;craig.buchanan@cogniza.com</a><br />
--Purpose:    Generates a table of data ranges (the most recent 12 months, plus<br />
--        three of Crystal Reports named-date ranges: MonthToDate,LastFullMonth<br />
--        and YearToDate<br />
--Parameters:    None<br />
--Returns:    a table of date range values<br />
--================================================================================<br />
DROP FUNCTION dbo.DateRanges<br />
GO<br />
CREATE FUNCTION dbo.DateRanges ()<br />
RETURNS @DateRangeTable TABLE (<br />
[Sequence]    decimal,<br />
StartDate    smalldatetime,<br />
EndDate        smalldatetime,<br />
Value        varchar(25),<br />
[Description]    varchar(20)<br />
)<br />
AS<br />
BEGIN<br />
--grab the system's date/time (using a view)<br />
DECLARE @EndDate    Datetime<br />
SELECT    @EndDate = Now<br />
FROM    dbo.GetNow<br />
--calculate the first date of the current month<br />
DECLARE @FirstOfMonth    Datetime<br />
SET @FirstOfMonth = CONVERT(VARCHAR,DatePart(m,@EndDate)) + '/1/' + CONVERT(CHAR(4),DatePart(yyyy,@EndDate))<br />
--calculate the first day of the month, 12 months ago<br />
DECLARE @StartDate    Datetime<br />
SET @StartDate = DateAdd(m,-12,@FirstOfMonth)<br />
--create a sequence number generator<br />
DECLARE @i        int<br />
SET @i = 1<br />
--insert 12 months of data<br />
WHILE @StartDate &lt; @FirstOfMonth<br />
BEGIN<br />
INSERT INTO @DateRangeTable (<br />
[Sequence],<br />
StartDate,<br />
EndDate,<br />
Value,<br />
[Description]<br />
)<br />
VALUES    (<br />
@i,<br />
@StartDate,<br />
DateAdd(m,1,@StartDate)-1,<br />
--create a value in the format i;StartDate:EndDate<br />
--ensure i is 0 padded<br />
Right( '0' + convert(varchar, @i), 2) + ';' +<br />
CONVERT(CHAR(10),@StartDate,110) + ':' +<br />
CONVERT(CHAR(10),DateAdd(m,1,@StartDate)-1,110),<br />
DATENAME(mm, @StartDate) + ' ' + CONVERT(VARCHAR,DATEPART(yyyy, @StartDate))<br />
)<br />
--add a month; increment counter<br />
SET @StartDate = DateAdd(m,1,@StartDate)<br />
SET @i = @i + 1<br />
END<br />
--add crystal report data ranges in the format index;DateRange<br />
--'Year to Date'<br />
INSERT INTO @DateRangeTable ([Sequence],StartDate,EndDate,Value,[Description])<br />
VALUES    (<br />
@i,<br />
'1/1/' + CONVERT(CHAR(4),DatePart(yyyy, @EndDate)),<br />
CONVERT(CHAR(10),@EndDate,110),<br />
Right( '0' + convert(varchar, @i), 2) + ';YearToDate','Year To Date'<br />
)<br />
SET @i = @i + 1<br />
--'Last Full Month'<br />
INSERT INTO @DateRangeTable ([Sequence],StartDate,EndDate,Value,[Description])<br />
VALUES    (<br />
@i,<br />
CONVERT(CHAR(10),DateAdd(m,-1,@FirstOfMonth),110),<br />
CONVERT(CHAR(10),@FirstOfMonth-1,110),<br />
Right( '0' + convert(varchar, @i), 2) + ';LastFullMonth','Last Full Month'<br />
)<br />
SET @i = @i + 1<br />
--'Month to Date'<br />
INSERT INTO @DateRangeTable ([Sequence],StartDate,EndDate,Value,[Description])<br />
VALUES    (<br />
@i,<br />
CONVERT(VARCHAR,DatePart(m, @EndDate)) + '/1/' + CONVERT(CHAR(4),DatePart(yyyy, @EndDate)),<br />
CONVERT(CHAR(10),@EndDate,110),<br />
Right( '0' + convert(varchar, @i), 2) + ';MonthToDate','Month To Date'<br />
)<br />
SET @i = @i + 1<br />
RETURN<br />
END<br />
GO<br />
GRANT SELECT ON dbo.DateRanges TO PUBLIC<br />
GO</code></p>
<p><a href="/wordpress/wp-content/uploads/2006/05/DateRanges.sql.txt" id="p80">DateRanges SQL Script</a></p>
]]></content:encoded>
			<wfw:commentRss>http://cogniza.com/wordpress/2006/05/25/sql-server-dateranges-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sql Server: GetNow View</title>
		<link>http://cogniza.com/wordpress/2006/05/25/sql-server-getnow-view/</link>
		<comments>http://cogniza.com/wordpress/2006/05/25/sql-server-getnow-view/#comments</comments>
		<pubDate>Thu, 25 May 2006 13:38:14 +0000</pubDate>
		<dc:creator>Craig Buchanan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Transact-SQL]]></category>

		<guid isPermaLink="false">http://www.cogniza.com/blog/?p=78</guid>
		<description><![CDATA[The Sql Server GETDATE() function not allowed in the body of user-defined functions, as it is non-deterministic. The GetNow view provides a means to generate a system date/time that can be used in Sql Server user-defined functions.]]></description>
			<content:encoded><![CDATA[<p>The Sql Server GETDATE() function not allowed in the body of user-defined functions, as it is non-deterministic.  The GetNow view provides a means to generate a system date/time that can be used in Sql Server user-defined functions.</p>
<p><span id="more-78"></span><code>DROP VIEW  dbo.GetNow<br />
GO<br />
CREATE VIEW dbo.GetNow AS<br />
SELECT    GetDate() Now<br />
GO<br />
GRANT SELECT ON dbo.GetNow TO PUBLIC<br />
GO</code></p>
]]></content:encoded>
			<wfw:commentRss>http://cogniza.com/wordpress/2006/05/25/sql-server-getnow-view/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Business Objects Enterprise: Create a Dynamic List of Date Ranges</title>
		<link>http://cogniza.com/wordpress/2006/05/24/business-objects-enterprise-create-a-dynamic-list-of-date-ranges/</link>
		<comments>http://cogniza.com/wordpress/2006/05/24/business-objects-enterprise-create-a-dynamic-list-of-date-ranges/#comments</comments>
		<pubDate>Wed, 24 May 2006 17:38:23 +0000</pubDate>
		<dc:creator>Craig Buchanan</dc:creator>
				<category><![CDATA[Business Objects Enterprise]]></category>
		<category><![CDATA[Crystal Reports]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Technique]]></category>
		<category><![CDATA[Business Objects]]></category>
		<category><![CDATA[Business View]]></category>
		<category><![CDATA[Date/Time]]></category>
		<category><![CDATA[Parameters]]></category>

		<guid isPermaLink="false">http://www.cogniza.com/blog/?p=61</guid>
		<description><![CDATA[Add a dynamic, date-range parameter to a report which includes the most recent 12 months, plus Crystal Reports' Month-to-Date and Year-to-Date ranges.]]></description>
			<content:encoded><![CDATA[<p>Add a dynamic, date-range parameter to a report which includes the most recent 12 months, plus Crystal Reports&#8217; Month-to-Date and Year-to-Date ranges.</p>
<p><a href="/wordpress/wp-content/uploads/2006/05/Date-Range%20Parameter.png" target="_new"><img src="/wordpress/wp-content/uploads/2006/05/Date-Range%20Parameter.png" alt="Date-Range Parameter" id="image62" border="0" height="90" width="128" /></a><span id="more-61"></span></p>
<h2>Objective</h2>
<p>Give the report</p>
<h2>Instructions</h2>
<h3>Create the Sql Server Components</h3>
<p>A Sql Server user-defined function (see <a href="http://www.cogniza.com/wordpress/2006/05/25/sql-server-dateranges-function" target="_new">Sql Server: DateRanges Function</a>) will dynamically create the values that are needed for the this project. This function needs a Sql Server view (see <a href="http://www.cogniza.com/wordpress/2006/05/25/sql-server-getnow-view" target="_new">Sql Server: GetNow View</a>) to generate the system&#8217;s current date/time.</p>
<h3>Create Data Connection</h3>
<ol>
<li>Open the Business View Manager and log in.</li>
<li>Create a new Data Connection.</li>
<li>Configure the Data Connection to attach to the appropriate Sql Server database.</li>
<li>Save the Data Connection as &#8216;Sql Server DC&#8217;.</li>
</ol>
<h3>Create a Data Foundation</h3>
<ol>
<li>In the Business View Manager, create a Data Foundation.</li>
<li>Select &#8216;Sql Server DC&#8217; as the Data Connection.</li>
<li>Save the Data Foundation as &#8216;Sql Server DF&#8217;.</li>
</ol>
<h3>Create a Business View</h3>
<ol>
<li>In the Business View Manager, create a Business View.</li>
<li>Save the Business View as &#8216;Sql Server BV&#8217;.</li>
</ol>
<h3>Create a Command Object</h3>
<ol>
<li>Create a Command Object in the Data Foundation. Add the following text to the Command Object:</li>
<p><code>SELECT *<br />
FROM dbo.DateRanges()<br />
ORDER BY Sequence DESC </code></p>
<li>Save the Command Object as &#8216;DateRanges&#8217;.</li>
</ol>
<p><a href="/wordpress/wp-content/uploads/2006/05/Create%20Command%20Object.png" target="_new"><img src="/wordpress/wp-content/uploads/2006/05/Create%20Command%20Object.thumbnail.png" alt="Create Command Object" id="image65" border="0" height="80" width="128" /></a></p>
<p><a href="/wordpress/wp-content/uploads/2006/05/Data%20Foundation.png" target="_new"><img src="/wordpress/wp-content/uploads/2006/05/Data%20Foundation.thumbnail.png" alt="Data Foundation" id="image75" border="0" height="94" width="128" /></a></p>
<h3>Create a Business Element</h3>
<ol>
<li>Create a new Business Element in the Business View Manager.</li>
<li>Add the Description and Value fields from the &#8216;DateRanges&#8217; Command Object.</li>
<li>Save the Business Element as &#8216;DateRanges&#8217;.</li>
</ol>
<p><a href="/wordpress/wp-content/uploads/2006/05/Business%20Element.png" target="_new"><img src="/wordpress/wp-content/uploads/2006/05/Business%20Element.thumbnail.png" alt="Business Element" id="image63" border="0" height="94" width="128" /></a></p>
<h3>Add Business Element to Business View</h3>
<ol>
<li>Open the Business View.</li>
<li>From the &#8216;Insert&#8217; menu, select &#8216;Insert Business Elements&#8230;&#8217;.</li>
<li>Locate and select the &#8216;DateRanges&#8217; Business Element, click &#8216;Add&#8217;, then &#8216;Close&#8217;.</li>
</ol>
<p><a href="/wordpress/wp-content/uploads/2006/05/Business%20View.png" target="_new"><img src="/wordpress/wp-content/uploads/2006/05/Business%20View.thumbnail.png" alt="Business View" id="image64" border="0" height="94" width="128" /></a></p>
<h3>Create the List of Values</h3>
<ol>
<li>Create a new List of Value in the Business View Manager.</li>
<li>Select the desired Business View from the &#8216;Select Business View&#8217; window.</li>
<li>Enter &#8216;Date Range LoV&#8217; in the &#8216;Name&#8217; textbox.</li>
<li>Expand the &#8216;DateRanges&#8217; Business Element in the &#8216;Available Fields&#8217; list.</li>
<li>Select &#8216;Value&#8217;, then click the &#8216;&gt;&#8217; button.</li>
<li>Check &#8216;Sort by Value in Descending Order&#8217;.</li>
<li>Choose &#8216;Description&#8217; from the &#8216;Description Field&#8217; dropdown list.</li>
<li>Click &#8216;OK&#8217; to save the List of Values.</li>
</ol>
<p><a href="/wordpress/wp-content/uploads/2006/05/Create%20List%20of%20Values.png" target="_new"><img src="/wordpress/wp-content/uploads/2006/05/Create%20List%20of%20Values.thumbnail.png" alt="Create List of Values" id="image66" border="0" height="96" width="112" /></a></p>
<h3>Examine Repository</h3>
<p>Open the Repository Explorer in the Business View Manager.  The list of objects for the Date Range Parameter should resemble this list:</p>
<p><a href="/wordpress/wp-content/uploads/2006/05/Repository%20Explorer.png" target="_new"><img src="/wordpress/wp-content/uploads/2006/05/Repository%20Explorer.thumbnail.png" alt="Repository Explorer" id="image76" border="0" height="96" width="111" /></a></p>
<h3>Create the Dynamic Parameter</h3>
<ol>
<li>Create a new report using Crystal Reports XI.</li>
<li>Connect to the Repository that contains the &#8216;Sql Server BV&#8217; Business View.</li>
<li>Create a new parameter, named &#8216;Date Range&#8217;.  Leave the &#8216;Prompt Group Text&#8217; textfield blank.</li>
<li>Select &#8216;Dynamic&#8217; from the &#8216;List of Values&#8217; dropdown list.</li>
<li>Select the Existing radio button and choose &#8216;Date Range LoV&#8217; from the list.</li>
<li>Click &#8216;Create Parameter&#8217; in the &#8216;Parameters&#8217; column of the &#8216;Choose a Data Source&#8217; group.</li>
<li>Set &#8216;Prompt Text&#8217; to &#8216;Choose Date Range&#8217;.</li>
<li>Set &#8216;Sort Order&#8217; to &#8216;Descending by Value&#8217;.</li>
<li>Set &#8216;Prompt With Description Only&#8217; to &#8216;True&#8217;.</li>
<li>Click &#8216;OK&#8217; to save the parameter.</li>
</ol>
<p><a href="/wordpress/wp-content/uploads/2006/05/Create%20Parameter.png" target="_new"><img src="/wordpress/wp-content/uploads/2006/05/Create%20Parameter.Thumbnail.png" alt="Create Parameter" id="image67" border="0" height="96" width="114" /></a></p>
<h3>Modify the Report</h3>
<ol>
<li>Add the CDateTime Custom Function to the report (see <a href="http://www.cogniza.com/blog/?p=77" title="Crystal Reports: CDateRange Function">Crystal Reports: CDateTime</a>).</li>
<li>Add a Custom Function named &#8216;getDateRange&#8217; (see below) to the report.</li>
<li>Edit the Record Selection Formula. Add the following code:<br />
<code>//set the database field to the value that is extracted from the 'Date Range' parameter<br />
{table.date_field} IN getDateRange({?Date Range})</code></li>
<li>Add a formula field to display the date range.  Add the following code to the formula:<br />
<code>CStr(Minimum(getDateRange ({?Date Range}))) + " - " + CStr(Maximum(getDateRange ({?Date Range})))</code><br />
Add the formula field to the report.</li>
</ol>
<h2>Summary</h2>
<p>When the report is run, the parameter form will resemble:</p>
<p><a href="/wordpress/wp-content/uploads/2006/05/Date-Range%20Parameter.png" target="_new"><img src="/wordpress/wp-content/uploads/2006/05/Date-Range%20Parameter.png" alt="Date-Range Parameter" id="image62" border="0" height="90" width="128" /></a></p>
<p><a href="/wordpress/wp-content/uploads/2006/05/Dynamic%20Date-Range%20Parameter.zip" id="p70">Dynamic Date-Range Parameter Sample</a></p>
<h2>getDateRange Custom Function</h2>
<p><code> '--------------------------------------------------------------------------------<br />
'Author:        Craig <a href="mailto:Buchanan;craig.buchanan@cogniza.com" style="color: #ffcc33" class="linkification-ext" title="Linkification: mailto:Buchanan;craig.buchanan@cogniza.com">Buchanan;craig.buchanan@cogniza.com</a><br />
'Purpose:       Convert a string value into its equivalent Date Range<br />
'Parameters:    text - a string in the format index;startDate:endDate<br />
'               or index;NamedDateRange<br />
'               e.g. 1;1/1/2006:12/31/2006 or 2;MonthToDate<br />
'Returns:       Date Range<br />
'--------------------------------------------------------------------------------<br />
Function getDateRange (text as string) As Date Range<br />
If Instr(text,";")=0 Then Exit Function<br />
Dim value as string: value = Split(text,";")(2)<br />
If Instr(value,":")=0 Then<br />
getDateRange = CDateRange (value)<br />
Else<br />
Dim startDate as Date: startDate = Cdate(Split(value,":")(1))<br />
dim endDate as Date: endDate = cdate(Split(value,":")(2))<br />
getDateRange = startDate to endDate<br />
End If<br />
End Function</code></p>
]]></content:encoded>
			<wfw:commentRss>http://cogniza.com/wordpress/2006/05/24/business-objects-enterprise-create-a-dynamic-list-of-date-ranges/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

