Select Distinct problem 
Author Message
 Select Distinct problem

I am having trouble selecting distinct records in my query.  Is it possible
to use "distinct" in CR?

molly



Fri, 03 Nov 2000 03:00:00 GMT  
 Select Distinct problem

I had the same problem.  The way to fix it (per Seagate Support) is:

How to do SELECT DISTINCT

 Product: PR Version: 3.0, 4.0, 4.5
 Database: SQL/ODBC  Platform: WIN3x
Type: TIP Status: NEW

Problem:
User is creating reports off SQL/ODBC database and wants to print only
distinct records.

Crystal Reports does not allow you to modify the SELECT clause. You
consequently cannot   add the 'DISTINCT' word to the SELECT statement to
make the server return only the distinct records.

Solution:
Crystal Reports forbids changing only the first SELECT clause in the SQL
It does allow you to add another SELECT clause.

 Here is a way to get Crystal Reports to do a SELECT DISTINCT:

 1. Copy the entire SQL statement of the report and duplicate it.
Add a 'UNION' clause between the 2 SQL statements.

 2. Modify the WHERE clause of the first SQL to say 'WHERE 0=1'.
If the SQL does not have a WHERE clause, add one.  'WHERE 0=1' makes the
first SQL a dummy SQL that does not select any records.

 3. Modify the second SQL to read 'SELECT DISTINCT'.  Since this
is the second SELECT statement in the SQL, Crystal Reports will allow
you to modify it and add the 'DISTINCT' word.

The final SQL should be like:

SELECT
  <field list>
FROM
  <table lis>
WHERE
  0=1

UNION

SELECT DISTINCT
  <field list>
FROM
  <table list>
WHERE
  <record criteria>

c1301957

 How to use the DISTINCT clause in the SQL query

 Product: PR         Version: 4.00
 Database: ORACLESQL Platform: WIN3x
 Type: TIP         Status: SVG

 Problem:
 How to use the DISTINCT clause in the SQL query

 Solution:
 Since the SELECT statement of the SQL query cannot be edited,
the  DISTINCT  clause cannot be used directly in the SQL query.

 There are workarounds which may be useful , depending  on what
you need to do in the report.

 1.Format field to Suppress if duplicate . NOTE: The suppression
will not affect totals or counts,

 2. If only one field has to be distinct ,  use a selection
formula that compares the field's value in the current record with its
value in the previous one. If the records can be delivered to CRW sorted
by that specific field (done by editing the SQL query), a selection
formula such as  the following should filter out duplicates:

  StringVar name;
  BooleanVar same := {table.name} = name;
  name := {table.name};
  not same

 This technique will  work only with SQL databases or local
databases accessed through ODBC because it relies on the records being
sorted before they're read by CRW.
  c1143503


Quote:
>I am having trouble selecting distinct records in my query.  Is it possible
>to use "distinct" in CR?

>molly



Mon, 06 Nov 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Select Distinct Problem

2. Select Distinct problem from VB

3. SELECT DISTINCT problem (adVarWChar VS. adLongVarChar)

4. SELECT DISTINCT and memo field problem?

5. Problem using SELECT DISTINCT

6. Problem with Memo field in SELECT DISTINCT queries

7. SELECT DISTINCT yields more than SELECT

8. Change SELECT to SELECT DISTINCT?

9. SELECT works, but SELECT DISTINCT fails

10. Does Access support SELECT Count(DISTINCT fieldname) ...

11. VB select distinct Fax, Co_nam from tableA doesn't

12. Why does SELECT COUNT(DISTINCT price) .. not work

 

 
Powered by phpBB® Forum Software