Solved

Checking the SQL statement with CFIF

Posted on 2011-02-14
8
241 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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