SQL Reporting :: Joined Tables - Concatenate Rows Into Single Row?
Feb 13, 2010
Im having a go at doing a report for my asp.net application. I have 2 tables, one which lists a loan we have given to a customer, and another table which lists repayments against the loans.
I want to display each loan and how much is outstanding against it. My problem is that each loan is repeated in the table for each repayment against it. So when i try to sum up the loans awarded to a customer, if they only have one loan and have made 3 repayments against it, it sums up the amount awarded against each record.
eg, if i award a customer a loan of £200, and they make 3 repayments of £50, 3 records appear in the table. The amount awarded is repeated against each repayment, and when i total a customers loan amounts, it totals 3 x £200.
I have put the details into the grouping row, where it is grouped by loan_id, displaying the toal of repayments instead of each repayment. This stops it repeating in the table, but when i total the amount awarded field it still calculates 3 x £200.
I tried calculating the total on the report item after grouping but you cannot calculate on a report item.
Is there a way to stop the table from repeating the amount awarded against each repayment? Or even a way in the SQL statement of the dataset to make it display a total of repayments rather than each repayment. Cant see how to calculate a total repaid as i would need to pass a Loan_id in as a parameter.
I've a table where one person teaches multiple classes. It looks like this.
Table1
Id Name Class Subject ---------------------------------------- 2 Sam 12 English 2 Sam 10 Maths 2 Sam 10 English 2 Sam 8 History 2 Sam 12 Economics
Here Sam teaches Class 12 - English & Economics, Class 10 - Maths & English, Class 8 - History
I want to display the result like this -
Id Name Class Subject --------------------------------------------------------------- 2 Sam 12 English, Economics 2 Sam 10 Maths, English 2 Sam 8 History
i need to concatenate the gridview rows to a single string if the gridview count is more than 100 then i need to perform the concatenation as 100 comma seperated and the next has to be carried over to the next string say if the count of gridview is 1000 then i need to concatenate the string as string1= 1to 100(Ex: a,b,c....) then string2=101-200 string3= 201-300... and so on. in case if i had to use String builder for this.. tel me how to proceed with this.
I'm trying to display data which comes from a join on two tables (or more) in a gridview I want to be able to filter the result set via user given input (text boxes on page)I have tried the standard tutorials but cannot find something which goes beyond displaying one table result sets in the gridview. If I go through the configure gridview and configure datasource wizard for any datasource (sqlDatasource, object, entitydatasource), when I use multiple tables I cannot use the 'where' parameters in the wizard, and therefore need to have the selecting code in the code-behind, but i'm unsure where exactly to put this.
I have a stored procedure that returns 3 tables within the single recordset it returns. If I set a SqlDataSource to get data from this procedure, it works, but it only returns the first table. I want to have a GridView display the data from the 2nd or 3rd table using a SqlDataSource, but I can't figure out how to specify a particular table.
While there are some posts discussing this out there, I can't get a definitive answer about whether or not this is even possible (?). In a worst-case scenario, I can create another SP that only returns the 3rd table - but that creates a little maintenance headache that I would prefer to avoid.
convert the code below to LINQ, converting my project to a wseb version usimg LINQ To SQL. The project contains 10 textboxes to possibly select from, but I'm only providing the first two textboxes to simplify my question.
mySQL_Statement = "SELECT IDENTIFICATION_DATA.NSC,ITEMISCD.RNC,ITEMISCD.NSC1 FROM IDENTIFICATION_DATA LEFT OUTER JOIN ITEMISCD on IDENTIFICATION_DATA.NIIN = ITEMISCD.NIIN" If Not ((TextBox1.Text = String.Empty) And (TextBox2.Text = String.Empty) Then mySQL_Statement = mySQL_Statement + " where " If Not (TextBox1.Text = String.Empty) Then mySQL_Statement = mySQL_Statement + "IDENTIFICATION_DATA.NSC IN (" + TextBox1.Text & ")" End If If (TextBox1.Text = String.Empty) Then mySQL_Statement = mySQL_Statement + "isnull(IDENTIFICATION_DATA.NIIN) = FALSE" End If If Not (TextBox2.Text = String.Empty) Then If astrixState = 0 Then If Not (TextBox1.Text = String.Empty) Then mySQL_Statement = mySQL_Statement + " AND IDENTIFICATION_DATA.NIIN IN (" + TextBox2.Text & ")" ElseIf (TextBox1.Text = String.Empty) Then mySQL_Statement = mySQL_Statement + " AND IDENTIFICATION_DATA.NIIN IN (" + TextBox2.Text & ")" MsgBox(mySQL_Statement) End If End If If astrixState = 1 Then If Not (TextBox1.Text = String.Empty) Then mySQL_Statement = mySQL_Statement + " OR IDENTIFICATION_DATA.NIIN IN (" + TextBox2.Text & ")" Else mySQL_Statement = mySQL_Statement + " AND IDENTIFICATION_DATA.NIIN IN (" + TextBox2.Text & ")" End If End If If astrixState = 2 Then If Not (TextBox1.Text = String.Empty) Then mySQL_Statement = mySQL_Statement + "AND IDENTIFICATION_DATA.NIIN NOT IN (" + TextBox2.Text & ")" Else mySQL_Statement = mySQL_Statement + " AND IDENTIFICATION_DATA.NIIN NOT IN (" + TextBox2.Text & ")" End If End If End If
how can I display on a single page(View) data from two tables in my db? In my project the model is *.edmx file. i have two table one with categories, and the second one with products. All I want to do is to display on home page(view) in left column all categories, and all products in right column. After clicking on category in left column, in right column there should be products form category which was clicked....
How can I insert value in two tables by single sql query because if I'm using two sql query it gives problem me on binding data and connection. Like I have 2 table table 1, table 2 ... In table I'm only save id and name and in other table I'm saving id, time1, time2
i am developing a web site in Asp.Net using Visual Studio 2008.i want to know that how can i search a keyword that will be entered by the user, i want the key word should be searched in complete database(all the tables)using a single query.I am using sql database. how can the keyword be searched using like parameter...
I am having a hard time solving the following with an MVC view. My goal is to display data from multiple tables in a single MVC view. The bulk of the data comes from a table called Retailers. I also have another table called RetailerCategories which stores the retailerid from the Retailers table and also a categoryid linking to a Category table. Note that there are multiple records for each retailerid in the RetailerCategories table.
In the view I want to show a list of retailers and with each retailer I want to show the list of categories applicable to them. What would be the best way to accomplish this?
I want to update two tables using stored procedures but my data not updating to data base
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace INV_DN { public partial class Form1 : Form { SqlConnection con; SqlDataAdapter da1; SqlCommand cmd; // SqlCommandBuilder cb; DataSet ds; public Form1()
Here I'm using three tables given below. As u can see in the below three tables, 3 columns(P_Id,PdtName,PdtImgUrl) are same. Now can any body tell me how can I retreive values of 3 columns(P_Id,PdtName,PdtImgUrl) without repeatition.
I need to copy rows for 2 tables from one db to another.I want to be able to do identity insert, one way is to change the column to not be PK.if I mark the pk not a pk but just a column, can I still map it as an ID?
Here's the scenario: Buyers and Sellers (where all of the sellers have a unique D&B number).
I'm catering to the buyers, and I want them to be able to import a list of sellers based on the D&B number.
Here are the tables:
BuyersSellers - unique list of sellers - one record, no matter how many buyers work with them.BuyerSellers - lookup table - buyer_id, seller_id sets which buyers work with which sellers ImportedSellers - temp table that holds sellers the buyer wants to add.AllSellers - master table that has all known sellers with D&B numbers (remote database).
Here's the process:
Buyer uploads list of new sellers, they get added to ImportSellers tableMatch ImportedSellers against AllSellers (valid), ignore unmatched (invalid).Add valid ImportedSellers to the Sellers table if they don't exist.Create BuyerSeller records for all valid ImportedSellers - using data from AllSellers.Delete all valid ImportedSellers, leave the unmatched behind so they know what they need to fix.
I've got the upload and import working, but now I'm a little stuck on how to do all of the matching and inserting, and do it as quickly as possible.
I am having a strange problem with and RDLC report with two tables in it. The tables are not related, nut I need them both on the same report. In my project, I created a typed dataset with two datatables in it (no tableadapters). IN my rdlc, added two datasets, one for each of the datatables. I then built the two tables in the report to use the appropriate dataset. When the application runs, I manually add data to the typed datasets and then add them as reportdatasources, etc. Now, all of this works fine if I have only one dataset in the rdlc. But, when I have two, I get an exception when I call lc.render(...). Digging through the inner exceptions, I end up with "DataSet1" as the inner most exception message.
I am having trouble deleting three table rows using SQL. The middle table is a junctional table allowing a one to many relationship between table 1 and table 3.
Table 1 Order_Id int Primkey FK1 Name Varchar Date Datetime
Table 2 Order_Id int PrmKey FK1 Item_Id int PrimKey FK2
Table 3 Item_Id int PrimKey FK2 Description Varchar Price money
Acually, I want to delete all rows associated with any particular order.
I am very new to Linq , i want to check if the PrintingAdminSetting table has rows in it and then if it has then i want to get the value and assign it to txtMaxJobs textbox
below is teh code
, please let me know teh syntax to check .
var DC = new ServiceDataContext(); var rec = DC.PrintingAdminSetting.Where("").First(); txtMaxJobs.Text = rec.ParaName.ToString();
I am accessing rows in an SQL database table based upon the contents of the Primary key and another column. But, I cannot insert new rows in the table when the content of the new Primary key column already exists in another row. Can I define the table with a multiple column Primary key so that a unique value can be based upon the content of both columns?
After creating a dataset, which has CRUD statements generated two or more tables, which Data Control should I use that will allow me to insert data into fields into 2 or more tables from a single web form. I'm trying to create a web form that will allow the user to input student information, such as general information, medical information, etc.
I have a rectange that has some printable elements. I want everying in the rectangle to print on one page. I don't want a new page ALWAYS before the rectange prints, I only want a new page if the entire rectange wont print on the current page