Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: filter Post Reply Post New Topic
Author Message
AdamField
Groupie
Groupie


Joined: 04 Jun 2009
Online Status: Offline
Posts: 88
Quote AdamField Replybullet Topic: filter
    Posted: 12 Jun 2009 at 6:01am
Hey all,
 
Maybe this is a stupid question but i'm kind of stuck on it
 
i have this big list with 2 column's (actualy there more but that's not the problem)
 
Document   //     user
 
000001               user1
000001               user1
000001               user1
000002               user2
000002               user2
000003               user3
000003               user1
000004               user1
000004               user1
000005               user1
000005               user2
000005               user3
000006               user4
000006               user4
 
this is SQL and i made a distinct view to group them on document
 
SELECT DISTINCT TOP 100 PERCENT h_document, h_user
FROM         dbo.hissto
 
this gives me:
000001               user1
000002               user2
000003               user3
000003               user1
000004               user1
000005               user1
000005               user2
000005               user3 
000006               user4
 
this is the info i have my CR
now i need to or in CR or in SQL filter the documents with more as 1 user (i only need the first one)
is there a way to filter this on record lvl or to adjust the SQL to i get
 
000001               user1
000002               user2
000003               user3
000004               user1
000005               user1
000006               user4
 
 
Tnx for the feedback on this !!
 
Greetings
Tom
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 12 Jun 2009 at 7:07am
SELECT DISTINCT TOP 100 PERCENT h_document, h_user
FROM         dbo.hissto
GROUP BY h_document, h_user
HAVING COUNT(*) > 1 
 
I think this is it, either that or:
SELECT DISTINCT TOP 100 PERCENT h_document, h_user
FROM         dbo.hissto
HAVING COUNT(*) > 1 
GROUP BY h_document, h_user
I never remember, I don't use this that often.
 
HTH
IP IP Logged
AdamField
Groupie
Groupie


Joined: 04 Jun 2009
Online Status: Offline
Posts: 88
Quote AdamField Replybullet Posted: 12 Jun 2009 at 7:15am
Tnx for the repley Lockwelle but i'm afraid it's not working :(
the formula works but the info in the return is still with double document numbers i'm afraid
 
but again thank you for the effort of making the replay!!
 
Greetings
 
Tom
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 12 Jun 2009 at 7:21am
Sorry missed a line (that you only need the top 1 for multi user)
 
SELECT DISTINCT TOP 100 PERCENT h_document, h_user
FROM         dbo.hissto
 JOIN (SELECT DISTINCT TOP 1 h_document, h_user
  FROM         dbo.hissto
  GROUP BY h_document)ss ON ss.h_document = hissto.h_document AND ss.h_user = hissto.h_user
 
 
give this a try.
 
I thought that you only wanted the documents with multiple users, this should return just the first record for each document, regardless of number or users.
 
IP IP Logged
AdamField
Groupie
Groupie


Joined: 04 Jun 2009
Online Status: Offline
Posts: 88
Quote AdamField Replybullet Posted: 17 Jun 2009 at 5:09am
Tnx for the reply lockwelle.
 
Tested this and added some info and right now i have this:
 
SELECT     TOP 100 PERCENT x.h_document, x.h_user, x.RecCount
FROM         (SELECT     h_document, h_user, COUNT(*) AS RecCount
                       FROM          dbo.hissto
                       GROUP BY h_document, h_user) x INNER JOIN
                          (SELECT     h_document, MIN(RecCount) AS RecCount
                            FROM          (SELECT     h_document, h_user, COUNT(*) AS RecCount
                                                    FROM          dbo.hissto
                                                    GROUP BY h_document, h_user) y
                            GROUP BY h_document) z ON x.RecCount = z.RecCount AND x.h_document = z.h_document
WHERE     (SUBSTRING(x.h_document, 1, 1) IN ('F', 'K'))
ORDER BY x.h_document
 
and works great
 
 
tnx for the feedback and the help
 
Tom
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.031 seconds.