Pivot the result of pivot query, Is this possible in sql / C#? - c#

Below is my table with column as below
And I want to get report as below
In this i want to get report from particular date and product within that date and its cumulative according to employee.
Is this possible in sql or C# so this can be generated in desired format.
Through pivot I have achieved for product , but further I am unable to get result.
Thank you in advance.

THank you everyone for your help , as told by #Ross Bush we are able to get report through SSRS. It is not same but similar to it . THe date column is been made vertical, grouped by date and been designed.

Related

How to get the average of the difference between start date and end date in SSRS

While trying to use reporting services I have tried to include a calculation. The calculation I'm trying to find is the average of the difference between the start date and the end date of every record.
I'm trying this piece of code in SSRS:
=CInt(DateDiff(DateInterval.Day, CDate(First(Fields!StartDate.Value, "DataSet1")), CDate(First(Fields!EndDate.Value, "DataSet1")))) / COUNTDISTINCT(DataSet1.Fields!Forename.Value)
But this comes out with the error
The Value expression for the text box ‘Textbox31’ uses an aggregate expression without a scope. A scope is required for all aggregates used outside of a data region unless the report contains exactly one dataset.
In your sql select statement input:
DATEDIFF(d, StartDate, EndDate) AS daysdiff
then in your report designer (either add total within a table or as a column in a matrix) use this expression
=Avg(Fields!daysdiff.Value)
It seems that your doing this in a text box and not a table.
Since the text box does not have it's own dataset property, you need to specify the dataset in your expression. You have it all of the except the COUNT.
=DateDiff(DateInterval.Day, CDate(First(Fields!StartDate.Value, "DataSet1")), CDate(First(Fields!EndDate.Value, "DataSet1"))) / COUNTDISTINCT(DataSet1.Fields!Forename.Value, "DataSet1")

Simple SUM Query needed for C#

I am a beginner programmer wanna ask about simple SUM query for C#. here is the case:
I have a table called "revenue", and that table consist of 5 columns. they are Bulan, Target, Realisasi, Target_YtD, and Realisasi_YtD. for column Bulan, I manually inserted 12 data. they are January, Februari, March, and so on...
For column Target and Realisasi also I inserted data manually with INT data type.
Now, I wanna add up the January's Target + February's Target + March's Target, and then the value of that calculation is gonna fill March's Target_YtD.
Can somebody tell me the query of that? I hope anyone can help me this time, I really appreciate that. Thanks
Do you mean something like this?
UPDATE
SET Target_YtD =
(SELECT SUM(Target) AS Total FROM revenue
WHERE Bulan IN ('JAnuary', 'February', 'March')
)
WHERE Bulan = 'March'
It depends on if you plan to calculate the colum at the time of input and save it to the database. Usually calculated columns are not in and of themselves columns in databases, but if that is what you are doing you can just use the c# concatenation function to populate that variable before doing your insert statement. If you're only populating the sum upon output to a c# app, same thing applies, or you could do a sum in your sql code. A few ways to get there, just depends what you're trying to do.

C# Fill Data Grid View after using input list

I really need your expert help :). Expanding on what I have learnt from querying data sets using adapters and filling a Grid View. I need some help on the following task.
I have a SQL Server Database which I am querying using C#. I already have solid working solutions of by a date range, a specific value. However, the business user would like to search by a list of values they provide as input into a form.
Similar to the below:
adapter.SelectCommand.Parameters.AddWithValue("#mindate", textBox1.Text);
The input will be taken from a text box or similar form based element. There should be no defined limit to the number of values e.g. I don't want to prevent the user from inputting 100 values for example.
By way of example.
User input: doc1.num1.value;doc2.num1.value;doc3.num1.value etc
Note: The document number field may contain a full stop. However, each value will be terminated by a ';'
In the above example, we would run the following query: select employee_id, docNumbers from tableName where docNumbers in (inputlist)
And the output would be:
Record 1: 1, doc1.num1.value
Record 2: 2, doc2.num1.value
Record 3: 3, doc3.num1.value
Thanks in advance guys and gals.
I guess what you are looking for is using an IN clause when doing your query.

Crystal Reports Multiple Tables Issue

I have a C# 2010 application that uses Crystal Reports for VS 2010. My report's purpose is to show where a person should be each day of one or more weeks. The format is this:
Please note that it is displayed in pairs, rather than a table with a general header.
It uses a DataSet that contains two DataTables, one for the header dates and one for the location.
The problem is that if I have n items in each DataTable, the report displays n^2 pairs of header / location instead of just n. The pattern is similar to a Cartesian product of the two tables.
I think it might have something to do with the linking part in the report's Database Expert but I couldn't manage to fix it. It contains no links right now.
The DataSet I use looks like this:
Why do you need a table for the headers? What are you trying to accomplish?
Why not add a date (StartOfWeek) to the WeekTable that represents the starting date of the week? If you have that date, each column header would be a formula field that calculates the day based on the StartOfWeek field. So much easier and it eliminates the Cartesian product that you are experiencing.
** edit **
There would be 7 header formulae (one for each day):
//{#Sunday}
DateAdd("d", 0, {WeekTable.StartOfWeek})
...
//{#Saturday}
DateAdd("d", 7, {WeekTable.StartOfWeek})
Add each field to the Page Header section and format as desired (they are Date values).
You need to link the tables to only get n rows.
Ideally:
Add a unique ID column to the Headers table. Make it the one primary key, and an auto-incrementing identity.
Add a HeaderID column to the WeekTable table, and make it a foreign key to the Headers table on the ID column.
The Headers table should now only include one row for each week, so if you have four employees they will all have the same HeaderID for a given week.
You may need to explain a little further what your "header dates" are. But from what you're saying they are not linked to the main data, in which case i would probably use a subreport in the header.

How can I add a unique count of a specific field to my report?

I have a C# program with output that looks like this (unexpanded rows):
and this (expanded rows):
Here's my SQL for the Fill method:
SELECT MBRSEP, LOCATION, BILLMOYR, RATE
FROM CAR1.CAV_MBRHISTDETL
WHERE (BILLMOYR IN ('1104', '1105', '1106', '1107', '1108', '1109')) AND (RATE = '0096')
ORDER BY BILLMOYR ASC, MBRSEP ASC
What this report is showing is a breakdown of customers with a rate type of 0096 for the months of April, May, June, July, August, and September.
What I'd like to see is a unique count for each distinct customer (MBRSEP) (a grand total of unique customers for those months), but I can't get my head around how to do this. Can anyone help or point me in the right direction? This little program was written with Visual Studio 2010 using a blank form, a databound dataset, and a reportviewer control.
EDIT: Also, here is the report source on the report design screen:
On the designer screen, I'm assuming there's some way to add a field that will show total number of unique values in a certain field in the report, but I'm not sure how to do that. (NOTE: I just added the SQL statements in a text field on the report for clarity)
Have you tried the SSRS CountDistinct function?
If I read this correctly, you want to find how many customers you had:
SELECT count(distinct MBRSEP) TotalCustomers
FROM CAR1.CAV_MBRHISTDETL
WHERE (BILLMOYR IN ('1104', '1105', '1106', '1107', '1108', '1109')) AND (RATE = '0096')
ORDER BY BILLMOYR ASC, MBRSEP ASC

Categories

Resources