Monday, March 26, 2012

Is this possible? please help (MS access query of sql database)

I work for an organisation that uses a bespoke document imaging system, the
database of which is an MS sql server.
We have MS Access and already use it for some querying of the database.
The database comprises a large number of distinct cases, which are
differentiated by case reference numbers, in one field (table?) of the
database. Each of these cases may have many documents associated with it,
denoted by the reference number, and these documents may be "new", "pending"
or "complete" shown in another data field.
We need to know how many cases have work outstanding on them.
Our problem is that our bespoke software will only count the number of
documents of each status, and not the cases.

Is it possible to design an MS Access query which will count the number of
different reference numbers which have any "new" documents associated, but
wont count each case more than once?

I am reasonably computer-savvy, I just don't know Access or SQL..
If I know it is possible, I don't mind putting in the effort to find out
how. I just don't want to waste time barking up the wrong tree ;-)

Of course any advice about how this would be achieved, such as pointers to
the right parts of the MS Access helpfiles, or to relevant websites would be
greatly appreciated. Some quick code would be even better...
Also, if there is any 3rd-party software which could easily do this, I need
help discovering it...I have looked long and hard, but don't know enough
about what I am looking for.
Yours in hope..
--
anthonyberet
Please reply in the groups, as my Usenet email address is not working at the
moment.anthonyberet wrote:
> I work for an organisation that uses a bespoke document imaging
> system, the database of which is an MS sql server.
> We have MS Access and already use it for some querying of the
> database.
> The database comprises a large number of distinct cases, which are
> differentiated by case reference numbers, in one field (table?) of the
> database. Each of these cases may have many documents associated with
> it, denoted by the reference number, and these documents may be
> "new", "pending" or "complete" shown in another data field.
> We need to know how many cases have work outstanding on them.
> Our problem is that our bespoke software will only count the number of
> documents of each status, and not the cases.
> Is it possible to design an MS Access query which will count the
> number of different reference numbers which have any "new" documents
> associated, but wont count each case more than once?
> I am reasonably computer-savvy, I just don't know Access or SQL..
> If I know it is possible, I don't mind putting in the effort to find
> out how. I just don't want to waste time barking up the wrong tree ;-)
> Of course any advice about how this would be achieved, such as
> pointers to the right parts of the MS Access helpfiles, or to
> relevant websites would be greatly appreciated. Some quick code would
> be even better...
> Also, if there is any 3rd-party software which could easily do this,
> I need help discovering it...I have looked long and hard, but don't
> know enough about what I am looking for.
> Yours in hope..

You'd probably be better off in an MS Access group - try
microsoft.public.access|||Gordon Burgess-Parker wrote:
> anthonyberet wrote:
>> I work for an organisation that uses a bespoke document imaging
>> system, the database of which is an MS sql server.
>> We have MS Access and already use it for some querying of the
>> database.
>> The database comprises a large number of distinct cases, which are
>> differentiated by case reference numbers, in one field (table?) of
>> the database. Each of these cases may have many documents associated
>> with it, denoted by the reference number, and these documents may be
>> "new", "pending" or "complete" shown in another data field.
>> We need to know how many cases have work outstanding on them.
>> Our problem is that our bespoke software will only count the number
>> of documents of each status, and not the cases.
>>
>> Is it possible to design an MS Access query which will count the
>> number of different reference numbers which have any "new" documents
>> associated, but wont count each case more than once?
>>
>> I am reasonably computer-savvy, I just don't know Access or SQL..
>> If I know it is possible, I don't mind putting in the effort to find
>> out how. I just don't want to waste time barking up the wrong tree
>> ;-)
>>
>> Of course any advice about how this would be achieved, such as
>> pointers to the right parts of the MS Access helpfiles, or to
>> relevant websites would be greatly appreciated. Some quick code would
>> be even better...
>> Also, if there is any 3rd-party software which could easily do this,
>> I need help discovering it...I have looked long and hard, but don't
>> know enough about what I am looking for.
>> Yours in hope..
> You'd probably be better off in an MS Access group - try
> microsoft.public.access

And I didn't see ALL those crossposts.... doh!|||On Sat, 18 Oct 2003 01:03:05 +0100, "anthonyberet"
<witfb001@.sneakemail.com> wrote:

>I work for an organisation that uses a bespoke document imaging system, the
>database of which is an MS sql server.
>We have MS Access and already use it for some querying of the database.
>The database comprises a large number of distinct cases, which are
>differentiated by case reference numbers, in one field (table?) of the
>database. Each of these cases may have many documents associated with it,
>denoted by the reference number, and these documents may be "new", "pending"
>or "complete" shown in another data field.
>We need to know how many cases have work outstanding on them.
>Our problem is that our bespoke software will only count the number of
>documents of each status, and not the cases.
>Is it possible to design an MS Access query which will count the number of
>different reference numbers which have any "new" documents associated, but
>wont count each case more than once?
>I am reasonably computer-savvy, I just don't know Access or SQL..
>If I know it is possible, I don't mind putting in the effort to find out
>how. I just don't want to waste time barking up the wrong tree ;-)
>Of course any advice about how this would be achieved, such as pointers to
>the right parts of the MS Access helpfiles, or to relevant websites would be
>greatly appreciated. Some quick code would be even better...
>Also, if there is any 3rd-party software which could easily do this, I need
>help discovering it...I have looked long and hard, but don't know enough
>about what I am looking for.
>Yours in hope..

this is very difficult without any idea of the tables involved, but
lets try;

Table: Cases
(caseNumber integer) *PK

Table: Documents
(docNumber integer,
caseNumber integer, *FK
status varchar(20))

SELECT COUNT(1) FROM Cases
WHERE caseNumber IN
(SELECT caseNumber
FROM Documents WHERE status='New')

Of course if your tables don't look like this then you need another
approach...|||Lyndon Hills wrote:
> On Sat, 18 Oct 2003 01:03:05 +0100, "anthonyberet"
> <witfb001@.sneakemail.com> wrote:
>> I work for an organisation that uses a bespoke document imaging
>> system, the database of which is an MS sql server.
>> We have MS Access and already use it for some querying of the
>> database. The database comprises a large number of distinct cases,
>> which are differentiated by case reference numbers, in one field
>> (table?) of the database. Each of these cases may have many
>> documents associated with it, denoted by the reference number, and
>> these documents may be "new", "pending" or "complete" shown in
>> another data field. We need to know how many cases have work
>> outstanding on them. Our problem is that our bespoke software will
>> only count the number of documents of each status, and not the cases.
>>
>> Is it possible to design an MS Access query which will count the
>> number of different reference numbers which have any "new" documents
>> associated, but wont count each case more than once?
>>
>> I am reasonably computer-savvy, I just don't know Access or SQL..
>> If I know it is possible, I don't mind putting in the effort to find
>> out how. I just don't want to waste time barking up the wrong tree
>> ;-)
>>
>> Of course any advice about how this would be achieved, such as
>> pointers to the right parts of the MS Access helpfiles, or to
>> relevant websites would be greatly appreciated. Some quick code
>> would be even better... Also, if there is any 3rd-party software
>> which could easily do this, I need help discovering it...I have
>> looked long and hard, but don't know enough about what I am looking
>> for. Yours in hope..
> this is very difficult without any idea of the tables involved, but
> lets try;
> Table: Cases
> (caseNumber integer) *PK
> Table: Documents
> (docNumber integer,
> caseNumber integer, *FK
> status varchar(20))
> SELECT COUNT(1) FROM Cases
> WHERE caseNumber IN
> (SELECT caseNumber
> FROM Documents WHERE status='New')
> Of course if your tables don't look like this then you need another
> approach...

I think only 2 tables are relevant in the first instance - "reference" and
"status".
Can you rcommend a site where I can read about the functions of the
intructions you have posted?
In particular, the "SELECT COUNT(1) FROM Cases" bit looks very powerful.
However, is this SQL or is it bespoke code used by MS Access?
Thank you for your help.
--
Put "usenet" in the subject-line if you want to mail me, otherwise it will
bounce.
Do you use filesharing networks? If so, please visit my online poll:
http://vote.sparklit.com/web_poll.spark/780772
anthonyberet|||On Mon, 20 Oct 2003 23:33:41 +0100, "anthonyberet"
<witfb001@.sneakemail.com> wrote:

<snip>
>> SELECT COUNT(1) FROM Cases
>> WHERE caseNumber IN
>> (SELECT caseNumber
>> FROM Documents WHERE status='New')
>>
>I think only 2 tables are relevant in the first instance - "reference" and
>"status".
>Can you rcommend a site where I can read about the functions of the
>intructions you have posted?
>In particular, the "SELECT COUNT(1) FROM Cases" bit looks very powerful.
>However, is this SQL or is it bespoke code used by MS Access?
>Thank you for your help.

I would google for sql tutorials. www.sqlcourse.com looks basic. Also
there should be some of this at least in the access help files. I
guess you do need to know what your looking for though. Above, all the
words in capitals are sql keywords, and they should be in the help
files. The IN is a subselect which could be replaced with EXISTS and a
slightly different syntax.

SELECT COUNT() FROM, just counts the number of rows that meet the
conditions. It just returns one number, not the actual rows of data.
There are similar options like MAX, MIN AVERAGE which apply to number
columns. A quick word of warning if you plan to use them, be careful
of the case where the number column is null. Average in particular may
give wrong results.

SQL has relatively few keywords, although each of the big
manufacturers have added their own.sql

No comments:

Post a Comment