Solved

Checking the SQL statement with CFIF

Posted on 2011-02-14
8
242 Views
Last Modified: 2012-05-11
What would the syntax be to check the SQL statement that is provided?  I am trying to check if an employee is allowed to check out any videos or maybe restrict the list that displays to only employees that are eligible to checkout videos.  Any help is appreciated.

Thanks
SELECT     t .*
FROM         (SELECT     Employees.EmployeeID, Employees.Last_name, Employees.First_name, VideoList.video_name, Detail.out_date, Detail.in_date, Role, 
                                              COUNT(*) OVER (Partition BY Employees.EmployeeId) AS CountNotCheckedIn
                       FROM          Employees INNER JOIN
                                              Detail ON Employees.EmployeeID = Detail.EmployeeID INNER JOIN
                                              VideoList ON Detail.VideoID = VideoList.VideoID
                       WHERE      Detail.In_Date IS NULL AND Detail.Out_Date IS NOT NULL) t
WHERE     t .CountNotCheckedIn = 2 AND Role <> '2'

Open in new window

0
Comment
Question by:JohnMac328
  • 4
  • 2
  • 2
8 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 34889556
"employee is allowed to check out"

only you know the rule for an employee that determiines the eligibility...

post an excel file that shows a sample data for each table... and also the result set that you are looking for...

also, add the query that you have and the result that you get from this query...
0
 

Author Comment

by:JohnMac328
ID: 34889585
I forgot to submit this portion as a part of the question
<cfquery name="getCheckEligible" datasource="#datasource#">
SELECT     t .*
FROM         (SELECT     Employees.EmployeeID, Employees.Last_name, Employees.First_name, VideoList.video_name, Detail.out_date, Detail.in_date, Role, 
                                              COUNT(*) OVER (Partition BY Employees.EmployeeId) AS CountNotCheckedIn
                       FROM          Employees INNER JOIN
                                              Detail ON Employees.EmployeeID = Detail.EmployeeID INNER JOIN
                                              VideoList ON Detail.VideoID = VideoList.VideoID
                       WHERE      Detail.In_Date IS NULL AND Detail.Out_Date IS NOT NULL) t
WHERE     t .CountNotCheckedIn = 2 AND Role <> '2'
 </cfquery>

<cfif IsDefined('getCheckEligible')>
 <cfscript>
    WriteOutput('
        <script language="JavaScript">
      doyou = confirm("Do you like the ColdFusion? (OK = Yes   Cancel = No)"); 
              if (doyou == true)
                alert("Me Too!"); 
            else if (doyou == false)
                alert("*Sniff* *Sniff* Too Bad!"); 
        </script>
    ');

</cfscript>
</cfif>

Open in new window

0
 

Author Comment

by:JohnMac328
ID: 34889593
The message portion was just example code - forgot to delete it.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 51

Expert Comment

by:HainKurt
ID: 34889719
post sample data for tables and the result that you are looking for in a excel format or text...
0
 

Author Comment

by:JohnMac328
ID: 34889755
I just need the syntax to check a true/false against a query.  Is that possible like this?

<cfif IsDefined('getCheckEligible')>
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 34889860
restrict the list that displays to only employees that are eligible to checkout videos

That's the opposite of what your query's doing.  If you just want to display a list of employees that have less than 2 videos checked out, do something like this

SELECT  Employees.EmployeeID, Employees.Last_name 
FROM    Employees LEFT JOIN 
      (     SELECT EmployeeID, COUNT(*) AS TotalNotCheckedIn
            FROM   Detail
            WHERE  out_date IS NOT NULL 
            AND    In_Date IS NULL
            GROUP BY EmployeeID
            HAVING COUNT(*) > 1
        ) 
        mx ON Employees.EmployeeID = mx.EmployeeID
WHERE   mx.EmployeeID IS NULL

Open in new window

0
 

Author Comment

by:JohnMac328
ID: 34889916
Sorry I have been so confusing, I wanted to have both versions for different parts of the program.  That's perfect - thanks again.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34889927
Gotcha, that makes sense then!
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question