Solved

Query Syntax

Posted on 2013-05-21
6
175 Views
Last Modified: 2013-06-08
I am having trouble with a Query.  Everything I try doesn't work.  In short, it looks for a StudyID and if 955 = true but 985 or 986 are false, then I don't want it to show as a result.  I am trying to get a list of studies that 955 is checked on a form, and 985 and 986 are not.

StudyID      TypeCodeID      Set1Flag
8621      955                         -1
8621      985                         -1
8621      986                          0

Here is the SQL Statement.  How can I get the result I desire?
SELECT dbo_HistoEvent.StudyID, dbo_HistoEvent.TypeCodeID, dbo_HistoEvent.Set1Flag
FROM dbo_HistoEvent
WHERE (((dbo_HistoEvent.StudyID)=8621) AND ((dbo_HistoEvent.TypeCodeID)=955)) OR (((dbo_HistoEvent.StudyID)=8621) AND ((dbo_HistoEvent.TypeCodeID)=985)) OR (((dbo_HistoEvent.StudyID)=8621) AND ((dbo_HistoEvent.TypeCodeID)=986));
0
Comment
Question by:sharpapproach
6 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39185206
Post a sample of the raw data
Post a sample of the *exact* results you want
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 39185222
SELECT dbo_HistoEvent.StudyID
FROM dbo_HistoEvent
WHERE dbo_HistoEvent.StudyID=8621
AND dbo_HistoEvent.TypeCodeID= IN (955, 985, 986)
GROUP BY dbo_HistoEvent.StudyID
HAVING ABS(SUM(dbo_HistoEvent.CodeID * dbo_HistoEvent.Set1Flag)) = 955
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39186495
I am trying to get a list of studies ... (where) 955 is checked on a form
SELECT DISTINCT dbo_HistoEvent.StudyID
FROM dbo_HistoEvent
WHERE dbo_HistoEvent.TypeCodeID = 955
AND Set1Flag = -1 /* true is minus one? */

Open in new window

0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39187159
Paul,

you missed the latter part of the OPs statement:  "... , and 985 and 986 are not"
0
 
LVL 84
ID: 39187162
Is this querying a SQL Server table? If so, try changing "=-1" to "<>0" or "=1". SQL Server doesn't have a boolean field, so most use a Bit field for that. Bit fields contain values of 0 or 1 only, with 0=False and 1=True.
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39187473
I think fyed's approach is likely to be the right one here, although the having clause is 'interesting' :)

I've also just noticed this is Access, so I'm not that sure about the minus one here. My memory of Access is that 1 = true, 0 = false

as fyed points out my over simplistic approach ignores 985 and 986, so there has to be some form of aggregated view by studyid, then exclude those where 985 (or?) 986 play a part.

I should have noticed all those brackets, what is it with Access and the plethora of parentheses?
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access, hourly employee status 8 44
Null or "" 28 53
Item not found in this collection 5 35
MS Access Combobox to Disable Controls on a Separate Form 10 28
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

696 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