Report Design
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Report Design
Message Icon Topic: Like but not like Post Reply Post New Topic
Author Message
NCBeach4Me
Newbie
Newbie
Avatar

Joined: 28 Sep 2009
Location: United States
Online Status: Offline
Posts: 15
Quote NCBeach4Me Replybullet Topic: Like but not like
     Posted: 26 May 2010 at 2:46am
I'm whatever you would consider before a Crystal begninner.  It basically boggles my brain.  Here's my issue...
 
Two fields in my report:
Acct#    and    district.
 
Each acct# can have multiple districts.  So essentially one could look like this:
 
Acct#             district
12345            downtown
12345 (same)uptown
12345 (same)midtown
 
So...when I try to do a select query and choose any acct# that do not have a district of downtown....I still get ones like this one that are listed in uptown or midtown.  Because Crystal thinks, 'Okay...I won't give you the one that says downtown for that acct # but I'll give you the ones that DON'T say downtown because they fit your simple logic."
 
I understand why Crystal does this...I just don't understand how to get the results I want.  Basically...I want any and all acct#'s that look do NOT have downtown listed for them.
 
For example, I would want one that looks like this:
 
Acct#           district
4567            uptown
4567            midtown
 
This one doesn't have downtown as a district.  I want only these to show up in my report.
 
I'm not sure if this is something I do in Grouping or if it's something I do with an if else statement.  I'm SQL stupid too...so be gentle if that's my recourse.
 
And thanks in advance for any help!
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 28 May 2010 at 3:34am
the simplest solution is to write a stored proc that does something like:
 
select acct, district
into #temp
from sometable
 
delete from #temp
where acct in (select acct from #temp where district = 'downtown')
 
this will delete all accounts that have a district downtown...and any other districts attached to that account.
 
HTH
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 02 Jun 2010 at 7:20am
Or you can write a command that looks something like this:
Select *
from accounts
  inner join district on accounts.account_number = district.account_number
where not exists(
  Select 1
  from district as d2
  where d2.account_number = accounts.account_number
    and d2.district = {?District}
Create a Parameter called District for the command (do this in the Command window, NOT in the main parameters in Crystal!)  Or, if you'll always be running this report to exclude just Downtown, you can just put the string 'Downtown' in your command instead of creating the parameter.
 
-Dell
 
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