Solved

SSRS IIF & Switch Not behaving

Posted on 2015-01-22
3
256 Views
Last Modified: 2015-01-22
I am working on a SSRS Report that looks at attendance. I am calculating how many minutes an employee is from clocking in verses the time he/she is supposed to be clocking in.  Our rule is, if you are more than 5 minutes from when you are supposed to clock in, you are late.  If you are more than 5 minutes before, you are early.  Anything and everything in between is considered on time.  Example:  Employee has a start time of 9AM. they punch in at 9:06, that would be considered late.  they clock in at 8:57, that is considered on time.  They clock in at 8:54, that is considered early.

So, I am looking at this Time difference and attempting to make SSRS return the "early, late, on time" flag.

This:

=iif(Fields!Time_Diff.Value > 5, "LATE","EARLY")   This statement will give me all of the lates, and defaults everything else to early.

 So, I then decided I need a SWITCH statement to look for the on time ones:

=Switch(Fields!Time_Diff.Value > 5, "Late",
Fields!Time_Diff.Value <  -5, "Early",
"On Time")

When I do that, I get "#ERROR" returned for all values.  Am I doing something wrong with the switch?  That syntax looks correct to me.
0
Comment
Question by:sbalawajder
  • 2
3 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40565168
Yes, the syntax is wrong. You can't use SWITCH like that.

Have a look at the function syntax https://msdn.microsoft.com/en-us/library/gg492166.aspx

It means you need your field as the first argument, then the first possible value as the second, then the first possible answer as the third.
0
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40565171
Why not use

iif(Fields!Time_Diff.Value > 5, "LATE", iif(Fields!Time_Diff.Value <-5, "EARLY", "On time"))
0
 

Author Comment

by:sbalawajder
ID: 40565196
That IIF worked!  Thanks...I didn't realize you could do an IIF like that.

Also- thanks for the clarification on the SWITCH
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now