Solved

Checking the SQL statement with CFIF

Posted on 2011-02-14
8
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 55

Expert Comment

by:Huseyin KAHRAMAN
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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
LVL 55

Expert Comment

by:Huseyin KAHRAMAN
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 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