Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

sql expression field "having clause"

Posted on 2007-04-10
9
Medium Priority
?
815 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to recover a database from a user managed backup

609 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