cfdeveloper
Programmer
Hello everybody,
I need your help with some sql select statement.
Let me expalin..
I'm working on a logging system for a support desk which allows customers to call the support desk and log a call if something needs to be done or say for example some equipment needs to be brought.
So, coming to my query. A log can be linked to another log. For example, I can link Log B to Log A and at the same time link Log B to Log C (needless to say I can link Log C to Log A and vice versa)
On the page where the support desk can view a log, there is a hyper link which opens up a pop-up that displays the logs linked to this log. I'm trying to write a sql stmt that returns the logs linked to a log.
Db table design:
The log table stores all the the log information
The 'logNumber' column is a primary key and 'LinkedLog' is the column that stores the logNumber.
The way it currently works is as under:
If I was to link Log B to Log A, the LinkedLog column for Log B would have Log A's logNumber. If I was now to link Log B to Log C, the LinkedLog column for Log C would have Log A's logNumber, so if I view the calls linked to log C, it should display Log A and Log B. However if I wish to view the logs linked to Log A, I want it to only display Log B (because the user has not linnked Log C to Log A)
I've tried to write a select stmt but just can't get the logic right.
here is my sql stmt:
<cfquery name="linked" datasource="db">
SELECT logNumber, LinkedLog
FROM Log
WHERE (LogNumber = '#url.ref#' AND LinkedLog <> '#url.ref#')
OR (LinkedLog = '#url.ref#' AND LogNumber <> '#url.ref#')
</cfquery>
url.ref contains the logNumber for the call the user is viewing.
if you have sussed my problem then please can you help me. If you don't understand something then please let me know. I look forward to hearing from you
Best Regards
cfcoder
I need your help with some sql select statement.
Let me expalin..
I'm working on a logging system for a support desk which allows customers to call the support desk and log a call if something needs to be done or say for example some equipment needs to be brought.
So, coming to my query. A log can be linked to another log. For example, I can link Log B to Log A and at the same time link Log B to Log C (needless to say I can link Log C to Log A and vice versa)
On the page where the support desk can view a log, there is a hyper link which opens up a pop-up that displays the logs linked to this log. I'm trying to write a sql stmt that returns the logs linked to a log.
Db table design:
The log table stores all the the log information
The 'logNumber' column is a primary key and 'LinkedLog' is the column that stores the logNumber.
The way it currently works is as under:
If I was to link Log B to Log A, the LinkedLog column for Log B would have Log A's logNumber. If I was now to link Log B to Log C, the LinkedLog column for Log C would have Log A's logNumber, so if I view the calls linked to log C, it should display Log A and Log B. However if I wish to view the logs linked to Log A, I want it to only display Log B (because the user has not linnked Log C to Log A)
I've tried to write a select stmt but just can't get the logic right.
here is my sql stmt:
<cfquery name="linked" datasource="db">
SELECT logNumber, LinkedLog
FROM Log
WHERE (LogNumber = '#url.ref#' AND LinkedLog <> '#url.ref#')
OR (LinkedLog = '#url.ref#' AND LogNumber <> '#url.ref#')
</cfquery>
url.ref contains the logNumber for the call the user is viewing.
if you have sussed my problem then please can you help me. If you don't understand something then please let me know. I look forward to hearing from you
Best Regards
cfcoder