I have this result on my query.
This result is from my sales table, each sale has an ID, and I have a table of products sold, each product sold has the sale ID as a foreign key, which represents the ID_NF in the result below:
How do I create a table or matrix in which each product that has the ID_NF equal to the sales ID is within its group.
You can join result which is from sales table with table of products. Condition for join will be ID = ID_NF. Sort it by sales, and then by products, for the sake of the result on report.
SELECT * FROM dbo.Sales s
INNER JOIN dbo.Products p ON s.ID = p.ID_NF
ORDER BY
s.ID,
p.ID_Produto
This select is just representing what you should do, write it so it suits your needs.
In your report (.rdl, or .rdlc file), create a table which will provide data about sales.
Set value of any column, for instance for the first column.
Group rows by sales id. You can do it by these steps:
right click on the row
from the menu select Row Group
select Group Properties
in newly opened window choose tab/card General
go to section Group expressions
click the Add button
in the newly added dropdown list choose id of the sale
One of the columns will be about products. Insert new table in the cell that is intersection of row that represents sale and column that represents products. In the newly added table add needed columns.
In this example new table of three columns is added in column Products.
Add values for the rest of the columns.
For these results
Report should look like this
Related
How to show or retrieve multiple columns with distinct value from one table in sql query ?eg: in my database i have account id 13 and id 13 have balance of 8000 and remaining fields are different but id and balance is same in 9 records, so i want id and balance to display only once and for remaining fields it should display 9 records
Try like this;
SELECT DISTINCT c1,c2,c3 FROM table
Or you can use group by
SELECT c1,c2,c3 FROM table group by c1,c2,c3
i have Two Table Like This
Request Example UniTerm Example
St_Code 1 Id 1 2
St_Name FirstStudent Term 96-97 95-94
St_Family FirstFamily
and i have a Grid View contain St_Code,Name,Family and Term
now the problem is i want to display all records of the student with the Just Last Record Term field in Term table
i need gridview data like below
1 FirstStudent FirstFamily 96-97
show last record of the Term table and all of the Student table Records
i tried this SQL Code to select them
SELECT Request.St_Code, Request.St_Name, Request.St_Family, UniTerm.Term FROM Student CROSS JOIN UniTerm ORDER BY UniTerm.Term DESC
its ok but shows all of the records in UniTerm table i need just last one!
thanks in advance
Just update your query
SELECT Request.St_Code, Request.St_Name, Request.St_Family, UniTerm.Term FROM Student CROSS JOIN UniTerm ORDER BY UniTerm.Id DESC
I want to create report that show data group by each column and total them
My select Data in SQL Server is:
Select sa,sb,sc,id from tbl
How do I can crate my report in rdlc?
If you use 'Group BY' With rollup Or 'Cube' Data Grouped by each column
in cube data grouped by all column with permutation of all column for your example grouped by
1-sa
2-sb
3-sc
4-sa,sb
5-sa,sc
6-sb,sc
7-sa,sb,sc
Select sa,sb,sc,id from tbl group by cube (sa,sb,sc)
if you use rollup data group by sort of column
for your example
1-sa
2-sa,sb
3-sa,sb,sc
Select sa,sb,sc,id from tbl group by rollup (sa,sb,sc)
I have a table like this:
Table name is List.
I have to get sum of each column. I cannot give this query:
SELECT SUM(jayesh,murali,jins) from List;
because the columns are added dynamically. Column names are given as user input. Is there any other code to do this..?
If you want the sum in each column:
SELECT SUM(jayesh), SUM(murali), SUM(jns) from List;
Not saying that any of this is or is not a good idea because no context was provided, but...
Sum of all columns combined for all records (one sum for entire table):
SELECT SUM(jayesh+murali+jns)
FROM List
Sum of all columns for each record (one sum for each row):
(This option requires having an id column to group by so that you can determine how to group the rows)
SELECT
ID,
SUM(jayesh+murali+jns)
FROM List
GROUP BY ID
Sum of each column separately for all records (one sum for each column):
SELECT
SUM(jayesh),
SUM(murali),
SUM(jns)
FROM List
I would also recommend reconsidering your design in adding dynamic columns based on user input. This is generally not a good idea, certainly not for this case. Read more here: http://www.sommarskog.se/dynamic_sql.html
I have a local report that I created in my application. It displays the contents of a table in my access database called "History". One of the columns is "ID" and it refers to the primary key in another table "Employees".
My report shows the employee's ID when it is refreshed but of course I want it to display the employee's name instead.
In short, I need to be able to perform a lookup on another table in my rldc file. How can I go about that?
I assume you fetch data from the database through a dataadapter and a typed dataset. something like this?
TestDataSetTableAdapters.CategoryTableAdapter ca = new TestDataSetTableAdapters.CategoryTableAdapter();
this.ds1 = new TestDataSet();
ca.Fill(this.ds1.Category);
Then you go to the dataset and modify the query in your tableadapter to something like this
select h.*,e.EmployeeName from history h
inner join Employees e on e.ID = h.UserID
Then the datset will be modified to include the column EmployeeName on all rows in the History table. Then the column "employeename" is directly available in yyour report
Here is an example of how to join your employee and history tables with SQL. My Access is rusty, so the syntax might not be perfect, but this should demonstrate the concept. Obviously, I made up the column names, so you will have to change the columns to whatever you need.
SELECT EmployeeID,
EmployeeName,
TimeIn,
TimeOut
FROM Employee Emp
INNER JOIN History History
ON Emp.EmployeeID = History.EmployeeID