in reply to Re^2: Avoiding SQL double jeopardy
in thread Avoiding SQL double jeopardy
I'm not sure what you're trying to do here, but whatever it is, this is overcomplicating it.
Aside from that, you're using dynamic SQL and a flag to determine if the person is a teacher or not. Use a Role id instead. That's what you want. The flag is a trick, and, it may bite you in the future.
Can more than one person be in the same session? Why does it matter if the person is a teacher or student?
It looks like you're inserting each person twice, once as a teacher and once as a student. If so, it can be done in one query:
INSERT INTO SessPeople (SessId, PersonId, IsTeacher) SELECT ?, ? 0 UNION ALL SELECT ?, ? 1;The second query is daunting. I have no idea what you're trying to do. If the original query (topic starting post) table was used, you can check via many ways. The easiest is to connect the two columns via UNION ALL:
WITH Session2 AS(SELECT AS (SELECT SessId, TeacherId, DoneDate, Topic FROM Sessions UNION ALL SELECT SessId, LearnerId, DoneDate, Topic FROM Sessions) SELECT SessId, TeacherId, DoneDate, Topic FROM Sessions2 WHERE TeacherId IN ();The rewritten query here might be more complicated, but it does't look right. Could you explain a little more clearly what you;re trying to achieve? I have a feeling the solution is considerably simpler.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Avoiding SQL double jeopardy
by GrandFather (Saint) on Jun 28, 2015 at 05:08 UTC | |
by Pope-O-Matik (Pilgrim) on Jun 28, 2015 at 09:25 UTC | |
by GrandFather (Saint) on Jun 28, 2015 at 10:21 UTC | |
by Pope-O-Matik (Pilgrim) on Jun 28, 2015 at 12:11 UTC | |
by GrandFather (Saint) on Jun 29, 2015 at 10:21 UTC | |
| |
by Pope-O-Matik (Pilgrim) on Jun 28, 2015 at 19:59 UTC |