Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Query Syntax

Posted on 2013-05-21
6
Medium Priority
?
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 48

Accepted Solution

by:
Dale Fye earned 1500 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 49

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 48

Expert Comment

by:Dale Fye
ID: 39187159
Paul,

you missed the latter part of the OPs statement:  "... , and 985 and 986 are not"
0
 
LVL 85
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 49

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…

618 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