Complicated query
From: Just D (no_at_spam.please)
Date: 07/21/04
- Next message: George Durzi: "Re: Help with SQL Query"
- Previous message: Mike Perry: "Re: Help with SQL Query"
- Next in thread: martin: "Re: Complicated query"
- Reply: martin: "Re: Complicated query"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 20 Jul 2004 19:52:56 -0700
Hi,
The task is so hard that I even don't know how to start explaining it...(
Let try to write a schema step by step.
We have two basic tables (and a few related subtables) - with questions and
answers. The tblQuestions database table is having the following fields
(simplified):
QID [int, PK]
QTopic [varchar 50]
QText [varchar 50]
Enabled [bit, NOT NULL]
Description [varchar 250]
Term [int] - Validity in months from the current date.
...
The table tblAnswers has the following structure (simplified):
AnswerID [int, PK, NOT NULL]
PtID [int, NOT NULL] - PatientID
RespDate [smalldatetime, NOT NULL, GetDate()] - the Response date
TextAnswer [varchar, not so important now]
BitAnswer [bigint, bitmask, not so important now]
...
The answer supposed to be saved correctly if at least one of these last
fields has a value.
The problems are to write a query to get the question list for a patient
with a some defined PtID. The query should evaluate the patient's answers so
that if the question is already having the answer saved inside the Validity
period:
(GETDATE() - Answer.RespDate < Question.Validity)
should be ignored. Another one problem - we're having many generations of
answers and we need to evaluate the answers inside some defined time period:
(WHERE RespDate<SomeDate)
keeping in mind the Validity interval.
The main rule - if the answer is already saved inside the Validity interval
the question should be ignored, if not - we need to ask this question and
save a new answer with the current DateTime. The previous answer should not
be updated or replaced, we just need to save a new one.
Second problem - we need to show the answers for defined DateTime receiving
all valid answers for current date.
The tasks are even more complicated because we don't need always to ask all
questions and the question list should be customized for a current patient
condition. It's like a bitmask and this WHERE can be gotten using a simple
bit-related query. It's easy.
Maybe anybody knows how to create such types of queries, if so, we'd
probably can discuss more details of this terrible task if anything's not
clear.
Thanks,
Dmitri
- Next message: George Durzi: "Re: Help with SQL Query"
- Previous message: Mike Perry: "Re: Help with SQL Query"
- Next in thread: martin: "Re: Complicated query"
- Reply: martin: "Re: Complicated query"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|