Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: SQL Expression Post Reply Post New Topic
Author Message
JohnT
Groupie
Groupie
Avatar

Joined: 20 Jan 2008
Online Status: Offline
Posts: 92
Quote JohnT Replybullet Topic: SQL Expression
     Posted: 13 May 2008 at 8:18am
I created a SQL expression under Add Command in the Database Expert.  I click OK and no errors.  When I look at my report, I don't have any data. 
From reading the help files, I think I need to run the SQL but I can't figure out how to do that.  (It's also possible that it doesn't return any data)  So, what should I do after entering the SQL expression to get data to appear on my report ?
Thank you,
John
 
IP IP Logged
Lugh
Senior Member
Senior Member
Avatar

Joined: 14 Nov 2007
Online Status: Offline
Posts: 377
Quote Lugh Replybullet Posted: 13 May 2008 at 10:32am
OK, first we ask the stupid questions.  Have you run the query in the database, to see if it returns records?  Do you have anything set up in the Select Expert?  Have you actually added the fields to the report?
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 13 May 2008 at 1:35pm
Is it a SQL "expression" or is it an actual Select query?
 
-Dell
IP IP Logged
JohnT
Groupie
Groupie
Avatar

Joined: 20 Jan 2008
Online Status: Offline
Posts: 92
Quote JohnT Replybullet Posted: 14 May 2008 at 12:57pm
I am getting closer but I am having problems with the date.  When I run this query
SELECT EMPL_TERM_DATE,
              ORGN_CODE_HIER,
              FULL_NAME,
              AS_OF_DATE,
              LOCN_DESC,
             JOB_CONTRACT_TYPE,
             JOB_END_DATE,
             PCLS_CODE,
             JOB_BEGIN_DATE,
             CURRENT_HIRE_DATE,
             ORGN_CODE_HIER
FROM   PZVEMPL A
 WHERE  EMPL_TERM_DATE IS  NOT  NULL  AND
ORGN_CODE_HIER = {?orgn}
AND AS_OF_DATE=TO_DATE('5/14/2008','MM/DD/YYYY' )
AND FULL_NAME = 'Brown, Jack N.'
and JOB_END_DATE = (SELECT MAX(JOB_END_DATE) FROM PZVEMPL B WHERE B.PIDM_KEY = A.PIDM_KEY)
 
Things work fine.  I get the record I expected.  However, I need to have the TO_DATE function work on a variable.  I setup a date variable called EndDate and entered 5/14/2008.  The query is 
 
SELECT EMPL_TERM_DATE,
              ORGN_CODE_HIER,
              FULL_NAME,
              AS_OF_DATE,
              LOCN_DESC,
             JOB_CONTRACT_TYPE,
             JOB_END_DATE,
             PCLS_CODE,
             JOB_BEGIN_DATE,
             CURRENT_HIRE_DATE,
             ORGN_CODE_HIER
FROM   PZVEMPL A
 WHERE  EMPL_TERM_DATE IS  NOT  NULL  AND
ORGN_CODE_HIER = {?orgn}
AND AS_OF_DATE=TO_DATE({?EndDate},'MM/DD/YYYY' )
AND FULL_NAME = 'Brown, Jack N.'
and JOB_END_DATE = (SELECT MAX(JOB_END_DATE) FROM PZVEMPL B WHERE B.PIDM_KEY = A.PIDM_KEY)
 
I get a message saying missing expression.  It must be on the TO_DATE line because that is the only line I changed.  (How many times have you heard that before ????)  Does the query need something special when using date variables ? 
 
I don't have access to run my query directly against the database.  I can only test in Crystal.
 
Thanks for your help,
John
 


Edited by JohnT - 14 May 2008 at 12:58pm
IP IP Logged
JohnT
Groupie
Groupie
Avatar

Joined: 20 Jan 2008
Online Status: Offline
Posts: 92
Quote JohnT Replybullet Posted: 14 May 2008 at 2:33pm
It's always the obvious.  When the field is defined as Date, you don't have to do a TO_DATE.  Seems to work now !!
 
John
 
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