Full Version: Using Sql To Force Groups
UtterAccess Discussion Forums > Microsoft® Access > Access Queries
DataDay
Hello,

I'd like to have custom grouping in my query. I'd like it group the "DataStatus" (the second column) into two groups one where "datastatus" equal 1 and a second group with everything else. So that everything that is not 1 will be grouped together.

So this:
TimePoint |DataStatus|CountOfTimePoint
6 |1 |281
6 |<>1|21

Instead of this:
TimePoint| DataStatus|CountOfTimePoint
6 |1 |281
6 |2 |1
6 |3 |1
6 |4 |1
6 |5 |7
6 |7 |8
6 |8 |3


Is that possible? Here's my SQL

SELECT tblDataCollectionPatients.TimePoint, tblDataCollectionPatients.DataStatus, Count(tblDataCollectionPatients.TimePoint) AS CountOfTimePoint
FROM tblDataCollectionPatients
GROUP BY tblDataCollectionPatients.TimePoint, tblDataCollectionPatients.DataStatus
HAVING (((tblDataCollectionPatients.DataStatus) Is Not Null));

Thanks for your help
niesz
Try:

SELECT a.TimePoint, IIF(a.DataStatus = 1, "1", "<>1") as NewDataStatus , Count(a.TimePoint) AS CountOfTimePoint
FROM tblDataCollectionPatients a
WHERE a.DataStatus Is Not Null
GROUP BY a.TimePoint, IIF(a.DataStatus = 1, "1", "<>1")
DataDay
That works. Thank you.
niesz
thumbup.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.