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?
Related
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)
)
Users want to have an option to control which columns are present in the final report.
One option is to get a list of fields requested. Is it possible in SQL Server to write a query like this? But I need to select a list of values, not just a single variable.
My plan is to get a parameter's list from a query like this:
SELECT
CONCAT ('Table2.', name) AS ColumnName
FROM
sys.columns
WHERE
object_id = OBJECT_ID('Table1')
The user would select columns they need this time, and then I want to use parameter list somehow like that:
SELECT #ColumnName FROM Table2
Of course it's not working this way...
Is there an option to get result that I want?
Check 'allow multiple values' for your parameter
In hide/show expression of the visibility of the column, put:
=IIF(instr(join(Parameters!ParamName.label,","),"NameColumn_to_filter")>0,false,true)
I have an SQL query to get results from my database table. When I run this query in Jasper Studio it should bring me following.
Nocte & Mane are boolean type colomns in the table. If the Nocte column is true then, it could show as a string ("Nocte") and this should same for the mane.
SQL Query
select * from medication where $X{IN,idmedication,list} order by `LastUpdated` desc
This is the query I am using in Jasper report and idmedication and list are parameters. LastUpdated is a timestamp. This list includes Integer values, which are the idMedications.
Have any ideas to do above task in Jasper Studio?
I can think of two approaches at the moment:
Use expressions when you design the report, it could be something like ($F{Nocte}?"Nocte":"something else")
Modify the query so that it returns varchar instead of boolean. For example:
select case when Nocte = 1 then "Nocte" else "something else" end Nocte
from your_table ...
the solution is something like bellow
(
${your_filed_name}==true?"Nocte"":"mane"
)
Hope this answer your question. And you can chain the condition or get into more complex expression.
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
I need my access db i'm trying to use the Max function on the results of a Count function of a field
i couldn't find any way of doing it - not through the user interface and not through SQL query.
This is my screen:
in the screen i have the count function working properly
how can i run the Max function on the Count function results?
To "run the Max function on the Count function results" requires that you "roll up" your count results to a higher level of aggregation. Save your existing query as HallCounts and then create a new query that does something like
SELECT Country_Id, Max(CountOfHall_Id) AS MaxHallCount
FROM HallCounts
GROUP BY Country_Id;
Or, to select just the row(s) with the highest count, try something like this
SELECT * FROM HallCounts
WHERE CountOfHall_ID = (SELECT MAX(CountOfHall_ID) FROM HallCounts);
I would use the TOP 1 SQL and DESC function. Or in the designer view it's "Return".
For example:
SELECT TOP 1 the_column_to_display
FROM the_table
ORDER BY Count(the_column_to_count) DESC;