?
Solved

sql expression field "having clause"

Posted on 2007-04-10
9
Medium Priority
?
807 Views
Last Modified: 2013-12-18
how to use a "having clause" in sql expression fields for crystal report 10(vs.net 2005)?
0
Comment
Question by:vielkacarolina1239
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 4

Expert Comment

by:ramumorla
ID: 18887239
Hey This is Oracle 10.x group.............
0
 
LVL 26

Expert Comment

by:Kurt Reinhardt
ID: 18887458
If you don't already know, a SQL Expression is essentially a subquery (either correlated or uncorrelated) in the SELECT clause that Crystal generates as part of it's SQL (Database|Show SQL Query).  As such, you must return a single, distinct value for the SQL Expression field.  Here's a sample of syntax I would use (Oracle SQL Server databases require the parentheses around the SQL in the SQL Expression editor):

(
SELECT DISTINCT
  field
FROM
  table
WHERE
  condition
)

If you want a HAVING clause, then you would use a statement like this:

(
SELECT DISTINCT
  field
FROM
  table
WHERE
  condition
GROUP BY
  field
HAVING
  COUNT(field) > 1
)

~Kurt
0
 

Author Comment

by:vielkacarolina1239
ID: 18889669
so let say the first sql statement have been generated by crystal if i want a having clause i just need to write a subquery and include my where clause along with the having clause. I already provided a where clause which is weekending=(select max(weekending) from table ) now I need to include a having clasue after this, I cannot put it together because weekending=........ represent just the where clause, and i tried creating a subquery with the two sql statement and it gives me the error(to many values).

(select sum("DIGITAL_MARKETING"."CURRENT_WEEK_UNITS"),sum("DIGITAL_MARKETING"."PRIOR_WEEK_UNITS")
 from "DIGITAL_MARKETING"
 having sum("DIGITAL_MARKETING"."CURRENT_WEEK_UNITS")>0 or sum("DIGITAL_MARKETING"."PRIOR_WEEK_UNITS")>0)
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 42

Expert Comment

by:frodoman
ID: 18889838
vielkacarolina1239,

Can you clarify if this is really a sql expression field?  If so, then as rhinok pointed out you must return a single result.  You're selecting two aggregate values coming back - if you want to do that you'll need to use two sql expression fields and split this into two parts...

frodoman
0
 
LVL 7

Expert Comment

by:RainMan82
ID: 18889853
use a group by in order to use a having....
0
 

Author Comment

by:vielkacarolina1239
ID: 18889888
I already have a field expression for the weekending=(select max(weekending) from table), so i would have to split the above query in order to get what I want.
0
 
LVL 26

Accepted Solution

by:
Kurt Reinhardt earned 2000 total points
ID: 18889889
The reason this query doesn't work is because it returns more than one column.  Once again, because a SQL Expression is a subquery in the SELECT clause of the main query generated by the report, it can only return a single distinct value.  Here's  a sample of the SQL that Crystal generates when a SQL Expression is created:

SELECT
  `ENTITY`.`ENTITY`,
  `PRACENT`.`NAME`,
  `PRACENT`.`PRACNO`,
  (
  SELECT DISTINCT
    'Y'
  FROM
    SUBSTAN
  WHERE
    PRACNO = PRACENT."PRACNO"
    AND PAST = 'N'
    AND ADDR1 <> 'INQY'
  )
FROM
  `database`.`dbo`.`ENTITY` `ENTITY`
  INNER JOIN `database`.`dbo`.`PRACENT` `PRACENT` ON `ENTITY`.`ENTITY`=`PRACENT`.`ENTITY`
ORDER BY
  `ENTITY`.`ENTITY`

The part in parentheses is the SQL Expression field.  Notice, it only returns a single, distinct value for each record.  If you need multiple values, then you need multiple SQL Expression fields.

~Kurt

0
 

Author Comment

by:vielkacarolina1239
ID: 18889995
Thanks for the help really appreciate it.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question