<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Crystal Reports Command Parameter Conversion to Date Issue (Where Clause) in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/crystal-reports-command-parameter-conversion-to-date-issue-where-clause/qaa-p/12119132#M4528053</link>
    <description>&lt;P&gt;Hi Michael,&lt;/P&gt;&lt;P&gt;Is there any place where PERIOD is null?  If so, that might be causing your error and you'll have to account for that.&lt;/P&gt;&lt;P&gt;Also, I might look at this the other way around.  Instead of trying to cast the PERIOD as a date, I might reformat the final begin and end dates as strings in YYYYMM format.  It would look something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;IsNull(PERIOD, '000000') &amp;gt;= left(Convert(varchar, @FinalBeginDate, 112), 6) and 
IsNull(PERIOD, '000000') &amp;lt;= left(Convert(varchar, @FinalEndDate, 112), 6)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;-Dell&lt;/P&gt;</description>
    <pubDate>Thu, 19 Dec 2019 14:44:30 GMT</pubDate>
    <dc:creator>DellSC</dc:creator>
    <dc:date>2019-12-19T14:44:30Z</dc:date>
    <item>
      <title>Crystal Reports Command Parameter Conversion to Date Issue (Where Clause)</title>
      <link>https://community.sap.com/t5/technology-q-a/crystal-reports-command-parameter-conversion-to-date-issue-where-clause/qaq-p/12119131</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
  &lt;P&gt;I've created a CR with a command that has SQL hitting SQL Server. Start and End date parameters/prompts were also created.&lt;/P&gt;
  &lt;P&gt;So my command looks basically like this...&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;Declare @BeginDate AS VARCHAR(100)
Set @BeginDate = '{?BeginDate}'
Declare @EndDate AS VARCHAR(100)
Set @EndDate = '{?EndDate}'
--some manipulation is done on @BeginDate and @EndDate
Eventually @FinalBeginDate and @FinalEndDAte are set to date values via...
set @FinalBeginDate = CAST(@BeginDate as DATE)
set @FinalEndDate = CAST(@EndDate as DATE)
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Then a SELECT is run returning many fields include PERIOD which is a VARCHAR(6) defined field containing year and month values in the format YYYYMM.&lt;/P&gt;
  &lt;P&gt;I want my WHERE clause to have something like this...&lt;/P&gt;
  &lt;P&gt;SELECT...WHERE CAST(PERIOD + '10' AS DATE) &amp;gt;= @FinalBeginDate and CAST(PERIOD + '10' AS DATE) &amp;lt;= @FinalEndDate&lt;/P&gt;
  &lt;P&gt;I consistently get this error...&lt;/P&gt;
  &lt;P&gt;Failed to retrieve data from the database.&lt;/P&gt;
  &lt;P&gt;Details 22007:[Microsoft][SQL Server Native Client 11.0][SQL Server]Conversion failed when converting date and/or time from charactrer string. [Database Vendor Code: 241]&lt;/P&gt;
  &lt;P&gt;NOTE: If I leave out the WHERE condition I'm trying to create and display @FinalBeginDate and @FinalEndDate the output is 12/1/2019 and 12/31/2019. And if I display the PERIOD it is 201912. &lt;/P&gt;
  &lt;P&gt;I have attempted tons of variations of this line: &lt;/P&gt;
  &lt;P&gt;CAST(PERIOD + '10' AS DATE) &amp;gt;= @FinalBeginDate and CAST(PERIOD + '10' AS DATE) &amp;lt;= @FinalEndDate&lt;/P&gt;
  &lt;P&gt;using CONVERT, CAST, etc. on PERIOD, @FinalBeginDate and @FinalEndDate but I can't get around the error.&lt;/P&gt;
  &lt;P&gt;Anyone have any suggestions?&lt;/P&gt;
  &lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 08:32:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/crystal-reports-command-parameter-conversion-to-date-issue-where-clause/qaq-p/12119131</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2019-12-18T08:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: Crystal Reports Command Parameter Conversion to Date Issue (Where Clause)</title>
      <link>https://community.sap.com/t5/technology-q-a/crystal-reports-command-parameter-conversion-to-date-issue-where-clause/qaa-p/12119132#M4528053</link>
      <description>&lt;P&gt;Hi Michael,&lt;/P&gt;&lt;P&gt;Is there any place where PERIOD is null?  If so, that might be causing your error and you'll have to account for that.&lt;/P&gt;&lt;P&gt;Also, I might look at this the other way around.  Instead of trying to cast the PERIOD as a date, I might reformat the final begin and end dates as strings in YYYYMM format.  It would look something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;IsNull(PERIOD, '000000') &amp;gt;= left(Convert(varchar, @FinalBeginDate, 112), 6) and 
IsNull(PERIOD, '000000') &amp;lt;= left(Convert(varchar, @FinalEndDate, 112), 6)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;-Dell&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2019 14:44:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/crystal-reports-command-parameter-conversion-to-date-issue-where-clause/qaa-p/12119132#M4528053</guid>
      <dc:creator>DellSC</dc:creator>
      <dc:date>2019-12-19T14:44:30Z</dc:date>
    </item>
  </channel>
</rss>

