<?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 IF statement in Command window in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538710#M111476</link>
    <description>&lt;P&gt;OK. I see why it's doing that.&lt;/P&gt;
  &lt;P&gt;Add a common 'column' alias for Fiscal_Year and year columns.&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;IF '{?YearType}' = 'Fiscal'
BEGIN 
SELECT fiscal_year Year, 
station_response_area_category, 
count(*) as Incident_count 
FROM dw_prod.dbo.vw_unit_response 
WHERE fiscal_year between '{?BeginYear}' and '{?EndYear}'
GROUP BY fiscal_year,station_response_area_category 
END 
IF '{?YearType}' = 'Calendar' 
BEGIN 
SELECT year Year, 
station_response_area_category, 
count(*) as Incident_count 
FROM dw_prod.dbo.vw_unit_response 
WHERE year between '{?BeginYear}' and '{?EndYear}'
GROUP BY year,station_response_area_category 
END&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;&lt;STRONG&gt;-Abhilash&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 16 Jan 2018 17:58:54 GMT</pubDate>
    <dc:creator>abhilash_kumar</dc:creator>
    <dc:date>2018-01-16T17:58:54Z</dc:date>
    <item>
      <title>Crystal Reports IF statement in Command window</title>
      <link>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaq-p/538694</link>
      <description>&lt;P&gt;Hello.&lt;/P&gt;
  &lt;P&gt;I'm trying to create a report that depends on what a user enters, a different SELECT statement is to run. For example, if a user enters a calendar year value, then a SELECT statement for the calendar year runs. If a user enters a fiscal year value, then a SELECT statement for the fiscal year runs. I didn't even know that I could do this from the Command windows to begin with. My code looks like:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;IF ( ({?BeginCY}) = ' ' )
BEGIN
select fiscal_year,station_response_area_category, count(*) as Incident_count
from dw_prod.dbo.vw_unit_response
where fiscal_year between {?BeginFY} and {?EndFY}
group by fiscal_year,station_response_area_category
END
ELSE 
BEGIN
select year,station_response_area_category, count(*) as Incident_count
from dw_prod.dbo.vw_unit_response
where year between {?BeginCY} and {?EndCY}
group by year, fiscal_year,station_response_area_category
END
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Of course the code isn't working right now. I'm trying to figure out how to do the IF section... Please help.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 14:02:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaq-p/538694</guid>
      <dc:creator>former_member548403</dc:creator>
      <dc:date>2018-01-11T14:02:19Z</dc:date>
    </item>
    <item>
      <title>Re: Crystal Reports IF statement in Command window</title>
      <link>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538695#M111461</link>
      <description>&lt;P&gt;Hi Kenshin,&lt;/P&gt;
  &lt;P&gt;Here's what I would do:&lt;/P&gt;
  &lt;P&gt;1. Create a parameter in the Command Window called "YearSelection". It would have two static values in its list:&lt;/P&gt;
  &lt;UL&gt;
   &lt;LI&gt;Calendar Year&lt;/LI&gt;
   &lt;LI&gt;Fiscal Year&lt;/LI&gt;
  &lt;/UL&gt;
  &lt;P&gt;2. Create two parameters to accept the Start and End years. You can name them "BeginYear" and "EndYear"&lt;/P&gt;
  &lt;P&gt;3. Modify the SQL to use this code:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;DECLARE @YearType varchar 
SET @YearType = {?YearSelection} 

IF @YearType = 'Fiscal Year' 
BEGIN 
SELECT fiscal_year, 
station_response_area_category, 
count(*) as Incident_count 
FROM dw_prod.dbo.vw_unit_response 
WHERE fiscal_year between {?BeginYear} and {?EndYear} 
GROUP BY fiscal_year,station_response_area_category 
END 

IF @YearType = 'Calendar Year' 
BEGIN 
SELECT year, 
station_response_area_category, 
count(*) as Incident_count 
FROM dw_prod.dbo.vw_unit_response 
WHERE year between {?BeginYear} and {?EndYear} 
GROUP BY year,station_response_area_category 
END&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Make sure to add the list of values to the "YearSelection" prompt by editing the parameter from the "Field Explorer".&lt;/P&gt;
  &lt;P&gt;When this report is run, the user will be prompted for three prompts:&lt;/P&gt;
  &lt;UL&gt;
   &lt;LI&gt;Year Type Selection&lt;/LI&gt;
   &lt;LI&gt;Start Year&lt;/LI&gt;
   &lt;LI&gt;End Year&lt;/LI&gt;
  &lt;/UL&gt;
  &lt;P&gt;When the user selects Year Type = 'Calendar Year', the report returns data for the Calendar year based on the date range in the Start and End prompt.&lt;/P&gt;
  &lt;P&gt;When the user selects Year Type = 'Fiscal Year', the report returns data for the Fiscal year based on the date range in the Start and End prompt.&lt;/P&gt;
  &lt;P&gt;I hope this helps.&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;-Abhilash&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2018 08:07:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538695#M111461</guid>
      <dc:creator>abhilash_kumar</dc:creator>
      <dc:date>2018-01-12T08:07:51Z</dc:date>
    </item>
    <item>
      <title>Re: Crystal Reports IF statement in Command window</title>
      <link>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538696#M111462</link>
      <description>&lt;P&gt;Thanks, Abhilash, as usual!&lt;/P&gt;
  &lt;P&gt;I followed your instruction, and I'm getting an error right now. When I run the report, I get an error and it says, syntax near 'Year'. I presume the error is due to a parameter and am trying to debug this thing. &lt;/P&gt;
  &lt;P&gt;In the meantime, any idea about the error?&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 13:16:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538696#M111462</guid>
      <dc:creator>former_member548403</dc:creator>
      <dc:date>2018-01-16T13:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: Crystal Reports IF statement in Command window</title>
      <link>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538697#M111463</link>
      <description>&lt;P&gt;Hi Kenshin,&lt;/P&gt;
  &lt;P&gt;Try running the query in the database. Replace the parameter fields with static values:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;DECLARE @YearType varchar 
SET @YearType = 'Fiscal Year'

IF @YearType = 'Fiscal Year' 
BEGIN 
SELECT fiscal_year, 
station_response_area_category, 
count(*) as Incident_count 
FROM dw_prod.dbo.vw_unit_response 
WHERE fiscal_year between 2016 and 2017 
GROUP BY fiscal_year,station_response_area_category 
END 

IF @YearType = 'Calendar Year' 
BEGIN 
SELECT year, 
station_response_area_category, 
count(*) as Incident_count 
FROM dw_prod.dbo.vw_unit_response 
WHERE year between 2016 and 2017 
GROUP BY year,station_response_area_category 
END&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jan 2018 13:20:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538697#M111463</guid>
      <dc:creator>abhilash_kumar</dc:creator>
      <dc:date>2018-01-16T13:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: Crystal Reports IF statement in Command window</title>
      <link>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538698#M111464</link>
      <description>&lt;P&gt;It seems to be fine in the database. I get, "Command(s) completed successfully."&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 13:32:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538698#M111464</guid>
      <dc:creator>former_member548403</dc:creator>
      <dc:date>2018-01-16T13:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: Crystal Reports IF statement in Command window</title>
      <link>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538699#M111465</link>
      <description>&lt;P&gt;Do you see any results?&lt;/P&gt;
  &lt;P&gt;Could you check if the datatype of the parameters and the fields match?&lt;/P&gt;
  &lt;P&gt;For e.g. datatype of the parameters {?BeginYear} and {?EndYear} should be same.&lt;/P&gt;
  &lt;P&gt;You may also try enclosing the parameters in quotes like so:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;WHERE year between '{?BeginYear}' and '{?EndYear}'&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jan 2018 13:35:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538699#M111465</guid>
      <dc:creator>abhilash_kumar</dc:creator>
      <dc:date>2018-01-16T13:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: Crystal Reports IF statement in Command window</title>
      <link>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538700#M111466</link>
      <description>&lt;P&gt;No, sir. It did not give me any result other than the message.&lt;/P&gt;
  &lt;P&gt;The datatype of the parameters is 'varchar' in the database. So I think the datatype is correct here.&lt;/P&gt;
  &lt;P&gt;I also tried enclosing the parameters in quotes, but the same syntax error...&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 13:41:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538700#M111466</guid>
      <dc:creator>former_member548403</dc:creator>
      <dc:date>2018-01-16T13:41:31Z</dc:date>
    </item>
    <item>
      <title>Re: Crystal Reports IF statement in Command window</title>
      <link>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538701#M111467</link>
      <description>&lt;P&gt;OK. I tried this and this doesn't give me any error, BUT it doesn't ask to select a year type when I try to refresh...&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;DECLARE @YearType varchar
--SET @YearType = {?YearType}

IF '{?YearType}' = 'Fiscal'
BEGIN 
SELECT fiscal_year, 
station_response_area_category, 
count(*) as Incident_count 
FROM dw_prod.dbo.vw_unit_response 
WHERE fiscal_year between '2016' and '2017' 
GROUP BY fiscal_year,station_response_area_category 
END 

IF '{?YearType}' = 'Calendar' 
BEGIN 
SELECT year, 
station_response_area_category, 
count(*) as Incident_count 
FROM dw_prod.dbo.vw_unit_response 
WHERE year between '2016' and '2017' 
GROUP BY year,station_response_area_category 
END
&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jan 2018 14:12:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538701#M111467</guid>
      <dc:creator>former_member548403</dc:creator>
      <dc:date>2018-01-16T14:12:31Z</dc:date>
    </item>
    <item>
      <title>Re: Crystal Reports IF statement in Command window</title>
      <link>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538702#M111468</link>
      <description>&lt;P&gt;Do you still have the YearType prompt in the command window?&lt;/P&gt;
  &lt;P&gt;Have you trued without the quotes?&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;-Abhilash&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 14:15:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538702#M111468</guid>
      <dc:creator>abhilash_kumar</dc:creator>
      <dc:date>2018-01-16T14:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: Crystal Reports IF statement in Command window</title>
      <link>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538703#M111469</link>
      <description>&lt;P&gt;Yes, and now it seems to be running all right. A HUGE THANKS TO YOU!!&lt;/P&gt;
  &lt;P&gt;My next question is, how do I show the result - fiscal year data to the calendar year data, upon user selection? I guess I could modify the code to show both calendar and fiscal data and create a formula to show the one that user select? &lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 14:21:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538703#M111469</guid>
      <dc:creator>former_member548403</dc:creator>
      <dc:date>2018-01-16T14:21:22Z</dc:date>
    </item>
    <item>
      <title>Re: Crystal Reports IF statement in Command window</title>
      <link>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538704#M111470</link>
      <description>&lt;P&gt;Expand the Field Explorer &amp;gt; Look for the 'YearType' selection prompt.&lt;/P&gt;
  &lt;P&gt;Drag and drop this prompt on the Report Header and it should display what is selected.&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;-Abhilash&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 14:23:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538704#M111470</guid>
      <dc:creator>abhilash_kumar</dc:creator>
      <dc:date>2018-01-16T14:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: Crystal Reports IF statement in Command window</title>
      <link>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538705#M111471</link>
      <description>&lt;P&gt;It's like one mountain after another...The reports does ask me to select the year type, but it's not asking for the begin and end year, even though the parameters are in the code. What could it be now?...&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;IF '{?YearType}' = 'Fiscal'
BEGIN 
SELECT fiscal_year, 
station_response_area_category, 
count(*) as Incident_count 
FROM dw_prod.dbo.vw_unit_response 
WHERE fiscal_year between '{?BeginYear}' and '{?EndYear}'
GROUP BY fiscal_year,station_response_area_category 
END 


IF '{?YearType}' = 'Calendar' 
BEGIN 
SELECT year, 
station_response_area_category, 
count(*) as Incident_count 
FROM dw_prod.dbo.vw_unit_response 
WHERE year between '{?BeginYear}' and '{?EndYear}'
GROUP BY year,station_response_area_category 
END&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jan 2018 14:28:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538705#M111471</guid>
      <dc:creator>former_member548403</dc:creator>
      <dc:date>2018-01-16T14:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: Crystal Reports IF statement in Command window</title>
      <link>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538706#M111472</link>
      <description>&lt;P&gt;Are the BeginYear and EndYear in the command prompt?&lt;/P&gt;
  &lt;P&gt;Do you see them to the right in the prompts panel?&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;-Abhilash&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 14:38:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538706#M111472</guid>
      <dc:creator>abhilash_kumar</dc:creator>
      <dc:date>2018-01-16T14:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: Crystal Reports IF statement in Command window</title>
      <link>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538707#M111473</link>
      <description>&lt;P&gt;They are in the command prompt, but weirdly I wasn't prompted for them until I added them to the report design section....&lt;/P&gt;
  &lt;P&gt;About the data selection between fiscal and calendar, I did try your suggestion of dragging the 'Year Type" to the report header, but if I refresh with different year type, the report cannot process and throws an error: &lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;One of more fields could not be found in the result set. Use verify database to update the report.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 14:44:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538707#M111473</guid>
      <dc:creator>former_member548403</dc:creator>
      <dc:date>2018-01-16T14:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: Crystal Reports IF statement in Command window</title>
      <link>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538708#M111474</link>
      <description>&lt;P&gt;OK and what happens after you 'verify database'?&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;-Abhilash&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 15:09:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538708#M111474</guid>
      <dc:creator>abhilash_kumar</dc:creator>
      <dc:date>2018-01-16T15:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Crystal Reports IF statement in Command window</title>
      <link>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538709#M111475</link>
      <description>&lt;P&gt;Then it brings the data, but I have to do this each time when I switch from fiscal to calendar and so on.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 15:42:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538709#M111475</guid>
      <dc:creator>former_member548403</dc:creator>
      <dc:date>2018-01-16T15:42:04Z</dc:date>
    </item>
    <item>
      <title>Re: Crystal Reports IF statement in Command window</title>
      <link>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538710#M111476</link>
      <description>&lt;P&gt;OK. I see why it's doing that.&lt;/P&gt;
  &lt;P&gt;Add a common 'column' alias for Fiscal_Year and year columns.&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;IF '{?YearType}' = 'Fiscal'
BEGIN 
SELECT fiscal_year Year, 
station_response_area_category, 
count(*) as Incident_count 
FROM dw_prod.dbo.vw_unit_response 
WHERE fiscal_year between '{?BeginYear}' and '{?EndYear}'
GROUP BY fiscal_year,station_response_area_category 
END 
IF '{?YearType}' = 'Calendar' 
BEGIN 
SELECT year Year, 
station_response_area_category, 
count(*) as Incident_count 
FROM dw_prod.dbo.vw_unit_response 
WHERE year between '{?BeginYear}' and '{?EndYear}'
GROUP BY year,station_response_area_category 
END&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;&lt;STRONG&gt;-Abhilash&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 17:58:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538710#M111476</guid>
      <dc:creator>abhilash_kumar</dc:creator>
      <dc:date>2018-01-16T17:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: Crystal Reports IF statement in Command window</title>
      <link>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538711#M111477</link>
      <description>&lt;P&gt;Thank you! Saved my butt again!&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 19:25:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/crystal-reports-if-statement-in-command-window/qaa-p/538711#M111477</guid>
      <dc:creator>former_member548403</dc:creator>
      <dc:date>2018-01-16T19:25:34Z</dc:date>
    </item>
  </channel>
</rss>

