SSRS Running Values with an IIF Statement Issues - reporting-services

I am developing an SSRS report and am having trouble with an expression. I want to apply 1 IIF statement with 2 conditions to a cell in a table. I am correctly do this, but the first expression only gives me the First value in the dataset. I took out the 'First' in the expression and tried to apply the RunningValue but i am getting stuck. I get an #Error in the cell. It just says #Error. How to apply the same IIF statement but loop through all the values in the dataset?
Can anyone shed some light on what I am doing wrong? All I am trying to do is apply a statement and if it meets the conditions then return only the value without summing. Any help is most appreciated.
First Script that works only for the first value.
=IIF(First(Fields!Title.Value, "getData")=1 And First(Fields!Day.Value, "getData")=DateAdd("d",-6,Parameters!WeekEnding.Value),Fields!Value.Value, "")
Second script trying to apply the RunningValue
=RunningValue(IIF(Fields!Title.Value=1 And Fields!Day.Value=DateAdd("d",-11,Parameters!WeekEnding.Value),Fields!Value.Value, ""),Sum,"getData")
Dataset query:
SELECT
a.PkId, a.EmpId, a.WkEnd, a.Day, a.Title, a.Description,
a.Value as Val
FROM
EmployeeTimeSheets a
INNER JOIN
Employees b ON a.EmpId = b.RowID
WHERE
Employee = #SelectEmployee
AND (WkEnd >= #WeekEnding OR WkEnd <= #WeekEnding)
DataSet
SQL table
SSRS table
Desired results

Related

SSRS Expression Count distinct column with IF statment

I am trying to distinct count all values in the Incident_ID column where a number of IIF statements are met. The SSTS expression is running but the result is far from correct. When using SQL on SSMS, I am getting totally different results which makes me feel my expression is incorrect. I am also looking at the data and the data backs-up my expression isn't right.
Kindly see below. Many thanks.
=CountDistinct(IIF(Fields!Last_month.Value = 1
AND Fields!Clinic_group.Value = "AAA"
AND Fields!Incident_approval_Flag.Value = 1
AND (Fields!Incident_severity_code.Value <> "BBB"
AND NOT ISNOTHING(Fields!Incident_severity_code.Value))
,Fields!Incident_ID.Value, Nothing)
)

How to convert IF or nested If statement like EXCEL to dynamic SQL Query in SQL server

I have came across one pretty problem in which I need to convert the nested if statement (like we used to write in excel) to dynamic SQL query.
I want to convert this
select 'IIF(A>B,A,IIF(B>C,B,C))'
to like this
select 'CASE WHEN A>B THEN A ELSE CASE WHEN B > C THEN B ELSE C END END'.
Why I am doing this I have formula column in the table user can insert formula in that and I need to convert this to SQL statement.
Do anyone has idea how can I do that?
The above is for only example I will be having 150 rows for different formula's entered by user.
Note : Here do not interpret IIF as SQL server IIF, it can be IF.
Assuming that A,B,C are numbers we can do something like this
SELECT
(
Select MAX(cols)
from
(VALUES (ColA), (ColB), (ColC))tbl(cols)
) as greatest
from yourtable

The Value expression for the textrun ‘Textbox15.Paragraphs[0].TextRuns[0]’ contains an error: [BC30201] Expression expected

I received this error when I am trying to run a select statement in a text box in SSRS. So, basically, I am trying to return a field which is not in the given dataset. So I have run a subquery which returns the value using the existing dataset as a container.
But I don't know how to represent that return value in the Expression field. Because the expression field returns a value which is within the dataset provided.
I have provided the SQL that I have written.
Any suggestions would be much appreciated.
My intention is to return the "CommentText" value. However, the dataset does not contain any commenttext field, but an EmpID field. So I have created the subquery below that brings up the CommentText from LaborDtlComment table and when it matches with the EmpID in the report dataset it returns the CommentText Value.
select [CommentReturnQuery].[LaborDtlComment_CommentText] as [LaborDtlComment_CommentText],
[EmpBasic].[EmpID] as [EmpBasic_EmpID]
from Erp.EmpBasic as EmpBasic
inner join (select [LaborDtlComment].[CommentText] as [LaborDtlComment_CommentText],
[LaborDtl].[EmployeeNum] as [LaborDtl_EmployeeNum]
from Erp.LaborDtlComment as LaborDtlComment
inner join Erp.LaborDtl as LaborDtl on LaborDtlComment.Company = LaborDtl.Company
and LaborDtlComment.LaborHedSeq = LaborDtl.LaborHedSeq
and LaborDtlComment.LaborDtlSeq = LaborDtl.LaborDtlSeq) as CommentReturnQuery
on EmpBasic.EmpID = CommentReturnQuery.LaborDtl_EmployeeNum
My aim is to show the CommentText value in a text field. So I will create the
text field and it will contain the SQL that I have written. Can anyone help
me in this case?
It maybe simpler to use the SSRS function lookup (single paired 1 to 1) or lookupset (multiple 1 to many).microsoft lookup reference
You will have to create the query/dataset to return CommentText from LaborDtlComment table with the EmpID

Show result from a query in a MS Access Report

I have a MS Access with a table containing some values that have to be summed up by categories and those sums I have to sum up again with different weighting. Therefore I created a query looking like this:
SELECT Sum(expr1) AS expr1
FROM
(SELECT 0.7 * Sum([performance]*[weighting])/100 AS expr1
FROM GOAL
WHERE GOAL.[ID]=[MYID] AND [YEAR]= [MYYEAR] and cat = "Cat1"
UNION
SELECT 0.3 *Sum([performance]*[weighting])/100 AS expr1
FROM GOAL
WHERE GOAL.[ID]=[MYID] AND [YEAR]=[MYYEAR] and cat = "cat2"
);
When I run the query it asks me to enter myid and myyear. Then it gives me the expected result.
I have a report and would like to have the result of the query at the end of the report. As I put in the query as the source for the textbox and open the report, then the report asks me for one parameter for the report and shows #Fehler (probably #Error with english settings). How can I give the query the parameter from values of the report?

Trouble in SQL Summing a Word

I am trying to Sum() the column Status where Status = 'operational'. I am having trouble figuring out how to sum the actual word "operational".
I have tried multiple different variations of the statement below (the one I posted is the most basic form) but I get the error: data type varchar is invalid for sum operator.
Can anybody help?
SELECT SUM(status) As 'TotalOperationalSTIDevices'
FROM netinfo_device_details
WHERE LoopBackAddress LIKE '10.12%' AND Status = 'Operational'
Try
Select COUNT(*) As 'TotalOperationalSTIDevices' from netinfo_device_details where LoopBackAddress Like '10.12%' and Status = 'Operational'
You need to use COUNT:
SELECT COUNT(*) As TotalOperationalSTIDevices
FROM netinfo_device_details
WHERE LoopBackAddress LIKE '10.12%' AND Status = 'Operational';
The SUM aggregation function really does a SUM of a set of numbers. COUNT just counts the number of rows.
Since the actual content of the row is not relevant, you can use COUNT(*) instead of COUNT(status) if you want.