Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: SQl for just one line Post Reply Post New Topic
Author Message
carstowal
Groupie
Groupie


Joined: 31 Jul 2008
Online Status: Offline
Posts: 80
Quote carstowal Replybullet Topic: SQl for just one line
     Posted: 02 Nov 2009 at 9:01am
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 03 Nov 2009 at 6:34am
select top 1 *...
will return just the first record.
IP IP Logged
carstowal
Groupie
Groupie


Joined: 31 Jul 2008
Online Status: Offline
Posts: 80
Quote carstowal Replybullet Posted: 03 Nov 2009 at 7:58am
I was misleading in my question.  my apologies

I don't really want just one row where (WORKORDER_BASE_ID = '141605')

I only had that workorder_base_ID in the command so I could evaluate whether or not the results were correct.

I really want one row for each existing workorder_base_ID where

(WORKORDER_SUB_ID = 0)
AND (TYPE = 'I')
AND (CUST_ORDER_ID IS NOT NULL)

IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 04 Nov 2009 at 6:05am
use a group header or group footer, then suppress the detail section, or use a stored proc to return just one row using a select distinct.
IP IP Logged
carstowal
Groupie
Groupie


Joined: 31 Jul 2008
Online Status: Offline
Posts: 80
Quote carstowal Replybullet Posted: 04 Nov 2009 at 6:33am
I can't suppress details or my totals will be wrong.

I don't know how to do or what a stored procedure is. 

I can create a view of the table but I still need the SQL statement to do that.

I don't know how Distinct can help me.  I don't want every distinct combination.


There can be multiple Cust_Order_ID to any given WorkOrder_Base_ID
There can be multiple WorkOrder_Base_ID to any given Cust_Order_ID
in addition the Cust_Order_ID could be NULL.

I don't care which Cust_Order_ID the results return, as long as it only returns one Cust_Order_ID per WorkOrder_Base_ID and Cust_Order_ID isn't NULL

Example:

ROW   WO                  CO
row1...123.................AAA
row2...123.................BBB
row3...123.................AAA
row4...456.................AAA
row5...456.................CCC
row6...456.................<NULL>

I want my results to return
only (1) of Rows 1, 2, 3 -don't care which
and
only (1) of Rows 4, 5     -don't care which
but
NEVER Row 6

IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 04 Nov 2009 at 6:36am
if you are using the aggregate functions, like sum, average, or count, suppressing details will not affect them. 
 
It would look like you only want the header or the footer of a group based on WO.  A header will give you the row1 and footer will give row3 in the above example.
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