I want to query the row values as Column in SQL - mysql

I have a query to result in the below data from DB
But actually, I want to get the data as
Is there any way we can do this the SSRS?
How can I do this? really stuck

You can do this easily in SSRS without changing your dataset.
Add a Matrix control to your report
Drag the Assignee field to the Rows placeholder
Drag the Priority_n field to the Columns placeholder
Drag the Count_C field to the Data placeholder
that's it. If this does not help, let me know and I will update with sample images.

Please recheck the column names;
SELECT * FROM (
SELECT
[Assignee],
[Priority_n],
[Count_C]
FROM dataset
) Results
PIVOT (
SUM([Count_C])
FOR [Priority_n]
IN (
[High],
[Medium],
[Low]
)
) AS PivotTable

Related

SQL Server : select query with dynamic column selection in SSRS report

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)

SSRS: How can i use a Parameter in MDX Query?

I have been trying for some time to get a Parameter to work within an MDX Query which is automatically generated by SSRS Query Designer.
I have tries the following:
FROM ( SELECT ( {[Dim Date].[Fiscal Year].&[+"#Current_FYear"+]}) ON COLUMNS
FROM ( SELECT ( { [Dim Date].[Fiscal Year].[+"#Current_FYear"+} ) ON COLUMNS
FROM ( SELECT ( {StrToMember(#Current_FYear,CONSTRAINED).lag(23):StrToMember(#Current_FYear, CONSTRAINED)}) ON COLUMNS
FROM ( SELECT ( {[Dim Date].[Fiscal Year].[+"Parameters!Current_FYear.Value"+]}) ON COLUMNS
And none of the above give me the result i am looking for: To have the Dataset filter by the value in the Parameter.
Any help on this would b emuch appreciated!
Thanks,
First of all, I would suggest using the Parameter checkbox in the Query Designer and let SSRS build the MDX for you. Here's a screenshot in case you missed it.
Another reason to let the report create the parameter for you is that it will automatically create another hidden Dataset to populate the available values of the parameter.
If you do want to edit the MDX manually, the syntax could look like this:
SELECT NON EMPTY { [Measures].[Measure] } ON COLUMNS FROM (
SELECT ( STRTOSET(#Parameter, CONSTRAINED) ) ON COLUMNS FROM [Model])
The STRTOSET function converts the parameter value into MDX syntax. It can also handle multi-value parameters.
The parameter you reference here would also need to be defined in the Parameters tab of the Dataset Properties. This is where you link the parameter value from the report to the query.

How to display empty chart instead of "no data available" in ssrs 2008

I inserted a pie chart in my SSRS 2008 report. When there is no data coming from sql, it basically shows "no data available", but what I would like it to display is an empty chart instead. I could not find a way to provide this. Any help would be appreciated
This is how I solved the problem for myself, though I was not using a pie chart. For my dataset query, I'd add a column called ShowRow. For any valid data, the ShowRow value would be 1. I would union that data with a row that matched the original data and if we had valid data, then showRow would be zero, else 1.
WITH ChartData as
(
SELECT Sales, Month, Year, 1 as ShowRow
)
SELECT * FROM ChartData
UNION
SELECT NULL,NULL,NULL,
CASE WHEN (SELECT COUNT(*) FROM ChartData) > 0
THEN 0
ELSE 1
END as ShowRow
Then in the dataset properties, I added a filter to only show rows where ShowRow = 1. This nicely showed my legend values and chart frame without showing any data.

How to rotate single row to key-value table in SSRS 2012?

Using SSRS 2012 with SQL Server 2012. I have a result set in SQL Server 2012 which has the following fields as headers:
sumDeposits,
sumWithdrawals,
sumFees,
etc
This has been mapped to a Dataset in SSRS.
I would like a SSRS table or matrix where I can have the column header as column one and the data row (there is only one row in the result set) as column two in a table. Is this possible? Been struggling with it.
I should add that the way I am doing it now is to drag a Field from the Dataset onto the SSRS page, and then put a text box next to it. The number of fields is growing so I'd rather have a table.
It sounds like you want to unpivot the data from columns into rows. If that is the case, then you should be able to use the UNPIVOT function in SQL.
The basic structure of the query will be:
select col, value
from yourtable
unpivot
(
value
for col in (sumDeposits, sumWithdrawals, sumFees) -- your columns here
)unpiv;
If you have data that is not the same datatype, then you will have to convert the data for all columns to be the same type:
select col, value
from
(
select sumDeposits,
cast(sumWithdrawals as numeric(10, 2)) sumWithdrawals,
sumFees
from yourtable
) d
unpivot
(
value
for col in (sumDeposits, sumWithdrawals, sumFees)
) unpiv;
This type of query is exactly the same as using a UNION ALL with multiple calls to the same table:
select 'sumDeposits' col, sumDeposits as value
from yourtable
union all
select 'sumWithdrawals' col, sumWithdrawals as value
from yourtable
union all
select 'sumFees' col, sumFees as value
from yourtable

How do i reference the value of a control in a rowsource query?

Im trying to write a query that will pull the value of the selected item in a combobox to use in a WHERE clause.
For example, the user selects "Jeff" out the combobox that is named cboNames. The bound value is 1 (the primary key). I'm trying to create the query:
select * from tbleEmployees where empID = cboNames.Value
obviously this doesn't work. Get what I'm trying to do?
How do i place the control value into the query??
select * from tbleEmployees where empID = [Forms]![YourForm]![cboNames]