Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Select Case Logic Post Reply Post New Topic
Author Message
slipstrm
Newbie
Newbie
Avatar

Joined: 09 Sep 2010
Location: United States
Online Status: Offline
Posts: 4
Quote slipstrm Replybullet Topic: Select Case Logic
     Posted: 09 Sep 2010 at 6:05am
Hello all.   I am a mainframe programmer trying to make changes to a report in crystal reports.   The following statement works correctly in sql. The problem I am having is adding the case logic to crystal reports.   
SELECT 
  optionee."NAME_FIRST",
  optionee."NAME_MI",
  optionee."NAME_LAST",
  optionee."LOC_CD",
  optionee."SOC_SEC",
  case
     (select count(*) from user3_leview where le_branch=loc_cd)
        when 0 then 'XX'
        else case (select count(*) from user3_leview where le_branch=loc_cd
                   and le_year = Left(Cast(YEAR(exercise.EXER_DT) as Char),4))
           when 0 then ''
            else (select item_desc from user3_leview where le_branch=loc_cd
                  and le_year = Left(Cast(YEAR(exercise.EXER_DT) as Char),4))
       end
  end as "Descr",
  grantz."OPT_PRC",
  grantz."GRANT_DT",
  exercise."Grant_NUM",
  exercise."OPTS_EXER",
  exercise."EXER_DT",
  valuations."OPTION_VAL"
FROM
 ((SO01DB.dbo.optionee optionee 
 INNER JOIN SO01DB.dbo.grantz grantz ON optionee.OPT_NUM = grantz.OPT_NUM 
 LEFT OUTER JOIN SO01DB.dbo.exercise exercise ON optionee.OPT_NUM = 
                 exercise.OPT_NUM AND grantz.GRANT_NUM = exercise.GRANT_NUM)
WHERE 
 grantz.PLAN_TYPE = 1 OR grantz.PLAN_TYPE = 4 oR grantz.PLAN_NUM = 5
 
If anyone could point me in the right direction it would be greatly appreciated.
 
 
Thank you.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 09 Sep 2010 at 12:04pm
are you adding this as a command or are you trying to put it in the select expert (or something else)?
IP IP Logged
slipstrm
Newbie
Newbie
Avatar

Joined: 09 Sep 2010
Location: United States
Online Status: Offline
Posts: 4
Quote slipstrm Replybullet Posted: 09 Sep 2010 at 3:09pm
I tried to add it into the select expert unsuccessfully.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 10 Sep 2010 at 4:39am
the select expert will not let you write SQL like that. It is more akin to just the WHERE clause in a SQL select statement.
You can try using it as a command object.
 
IP IP Logged
slipstrm
Newbie
Newbie
Avatar

Joined: 09 Sep 2010
Location: United States
Online Status: Offline
Posts: 4
Quote slipstrm Replybullet Posted: 13 Sep 2010 at 4:20am
So, I should be able to put the SQL statements in a stored procedure and execute that within crystal?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 13 Sep 2010 at 5:11am

that is one solution. You can use a SQL view or sp as the data source.

This gives you a much more flexible way of managing the data before it gets into the report rather than using the select expert to limit data rows after the tables are brought into the report. Views and SPS usually generate much faster reports too. 
IP IP Logged
slipstrm
Newbie
Newbie
Avatar

Joined: 09 Sep 2010
Location: United States
Online Status: Offline
Posts: 4
Quote slipstrm Replybullet Posted: 15 Sep 2010 at 10:08am
Thank you for your help DBlank.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum