The management program that I maintain for the OP has had a comments table 'from time immorial'; depending on a field in the table, a comment can be connected to a docket, a therapist or to a project. From these screens, the appropriate comments can be seen (otherwise known as vertical access); i.e. for a given docket, one can easily see the comments for that docket.
A few months ago, I added the concept of a 'comment type' as we had introduced certain automatic comments; whilst these comments can still be in the vertical manner, there was no way of seeing all comments of a given type (aka horizontal access). So I developed a report that showed all the comments, depending on the various parameters chosen. As a comment regarding a therapist is somewhat different from a comment regarding a docket, the query that I had to write required a case statement in order to selectively display data. As this query was written in the 'modern age', it included all the bells and whistles developed in the past (i.e. adding parameters in a dynamic fashion).
select comments.curdate, comments.subject, comtypes.name, case when comments.sug = 'D' then comments.docket when comments.sug = 'T' then therapists.name else comments.docket end as avalue, customers.name, comments.comment from comments left join comtypes on comtypes.id = comments.comtype left join therapists on therapists.id = comments.docket left join xtracust on xtracust.docket = comments.docket left join customers on customers.id = xtracust.customer where 1 = 0
select comments.curdate, comments.subject, comtypes.name, cast (comments.docket as varchar (32)) as avalue, customers.name, comments.comment from comments left join comtypes on comtypes.id = comments.comtype inner join xtracust on xtracust.docket = comments.docket inner join customers on customers.id = xtracust.customer where 1 = 0 and comments.sug = 'P'
const q1 = 'select comments.taarich, comments.subject, comtypes.name, '; q2 = 'cast (comments.docket as varchar (32)) as avalue, customers.name, '; q3 = 'therapists.name as avalue, cast (''-'' as varchar (32)) as name, '; q4 = 'comments.comment from comments '; q5 = 'left join comtypes on comtypes.id = comments.comtype '; q6 = 'inner join xtracust on xtracust.docket = comments.docket '; q7 = 'inner join customers on customers.id = xtracust.customer '; q8 = 'inner join therapists on therapists.id = comments.docket '; q9 = 'inner join projects on projects.id = comments.docket '; q10 = 'inner join customers on customers.id = projects.customer '; q11 = 'where 1 = 1'; [following is the code that builds the query] s:= q1; // this is the query string sug:= GetSug; // 'sug' is Hebrew for 'type', a reserved word if sug = 'T' then s:= s + q3 else s:= s + q2; s:= s + q4 + q5; case sug[1] of 'D': s:= s + q6 + q7; 'T': s:= s + q8; 'P': s:= s + q9 + q10 end; s:= s + q11;
Blog # | Date | Title | Tags |
---|---|---|---|
118 | Brains and mirrors | Psychology, Social intelligence, Martin Seligman, The brain | |
1374 | 28/01/2021 | Cormoran Strike | TV series, DCI Banks, Cormoran Strike |
No comments:
Post a Comment