DataSource Controls :: Concatenating Rows From Another Two Tables
Apr 13, 2010
I have a problem where I would like to get a comma-separated list of items from a couple of tables as part of a set of results. All the searching I've done so far has produced results for dealing with one or two tables. I have four, and can't get my head around how to adapt the sql to deal with it.
I have the following layout:
*Table_Castings*
+---- CastingID {PK}
| MouldID
| SerialNo
| CastRef
| MeltCode
| Signature
|
|
| *Table_CastCertificates* *Table_Certificates*
| CertificateID {PK} ----------- CertificateID {PK}
+---- CastingID {PK} Description
FileID -----------------+
|
|
*Table_CertificateFiles* |
FileID {PK} -------------+
FullLocation
The results I would like include the following columns:
CastingID, MouldID, SerialNo, CastRef, MeltCode, [Certificates],
Where Certificates is a comma separated list of Description + " " + FullLocation records. (What I'll actually do is add http:// and other html codes to make FullLocation a hyperlink, but I can do that.)
Some SQL I've already got is this:
DECLARE @str VARCHAR(500)
SELECT @str = COALESCE(@str + ', ','') + '<a href="http://' + Table_CertificateFiles.FullLocation + '">' + Table_Certificates.Description + '</a>'
FROM Table_CastCertificates INNER JOIN
Table_Certificates ON Table_CastCertificates.CertificateID = Table_Certificates.CertificateID INNER JOIN
Table_CertificateFiles ON Table_CastCertificates.FileID = Table_CertificateFiles.FileID
WHERE (CastingID = 45)
SELECT output = @str
This actually gives all records in the for the specific casting, but I keep getting an error at the "=" in @str = COALESCE when I try joining it to another query to get each casting.
View 3 Replies
Similar Messages:
Jun 17, 2010
[Code]....
View 2 Replies
Mar 12, 2011
I have 5 tables as follows
as it can be seen from diagram, I have one table ie.patientdetails with Pid as primary key and other 4 tables have pid which is foreign key related to Pid in patient details.
the problem is that when if a test data is filled for say patient with Pid as 1, the data is saved nicely in required tables
If i try doing that again for same patient then a duplicate is created in test tables with pid as 1.
View 7 Replies
Mar 7, 2010
Maybe this could be a simple questino, but for me it's difficult to do this action: I have a table in sql server 2005 with some records stored, for example 10 records. The primary key of this table, let's call it "Employee", it's a number field with an autoincrement constraint. I want to store more data into the table by using a OdbcDataTable object and OdbcDataAdapter and adding new rows to the datatable and afeter that use the "Update" method from the OdbcDataAdapter object.
The big deal is this: let's suppose that I want a add a new record to the datatable object, using any method or code sequence that you want. if I have 10 records stored on the data base table, when I retrieve this table schema by using the OdbcDataAdapter "Fill" method, I have a copy of the data base table schema in the DataTable object, right?. if I add a new row on the datatable object, it's suppose that the primary key column of that table must AUTO-INCREMENT the value of the key, I mean if the last value that I store on the table was the number 10 on the PK field, when I add a new row on the datatable object, the PK value on the datatable object must be the number 11 if the autoincrement constraint is present into the DataTable object, but in my case, it doesn't work
So, How can I define the conditions or set the c# data objects properties to wor in that way???. In this moment the PK column on the odbcDataTable doesn't auto-increment its value when I add a new row on it.
Please helpe with this.
PD: I have another question about the DataTable object, how many records can store this object?? I have some problems with this because sometimes when I use the Fill() method to get data into the DataTable or a DataSet object there's no problem if the Fill() method retrieves about 142000 records, but when I retrieve over the 145000 records, when I inspect the DataSet or DataTable object by using the debuging mode, they have null value. Any of you can tell me why this situation ocurrs??
View 1 Replies
Jan 19, 2011
I am writing an SQL query in which that I will need to perform a sub select on a table, which will usually return multiple rows. I need to be able to join together the results of a certain field from all the rows into one field to output. Is this possible, and how?
For example, if the SQL query returns
id | field
1 | test1
2 | test2
3 | test3
I need the outputted field to be "test1 test2 test3".
View 4 Replies
May 31, 2010
I have one big DataTable with X rows. I want to select Y rows from it and bind them to a new ViewList. While doing it, I want to delete these rows from the DataTable (Having X - Y rows).
What is the best and fast way to do it?
I don't know if it is better to create a new DataTable to have the Y and after that bind them to a ViewList or something else?
I'm also looking for example in code how to select/delete rows from DataTable.
View 1 Replies
Jun 17, 2010
[Code]....
In above query I want to have top 10 rows as well as count of all rows.
View 3 Replies
Dec 14, 2010
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?
View 1 Replies
Sep 29, 2010
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.
View 3 Replies
Nov 23, 2010
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();
View 4 Replies
Jul 24, 2010
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?
View 3 Replies
Jul 12, 2010
I have the following tables and fields in SQL:
[Code]....
I'd like to create an XML file(based on the above tables mentioned) which I'd like to bind to a treeview control, but I'm not sure how to do that.
View 2 Replies
Jan 8, 2011
im currently doing a web form that shows will show the contents of a table from a database... the problem is that the codes im using only shows the data from the 1st row of the table and i need the data from all the rows of the tables
using System;
using System.Data;
using System.Configuration; [code].....
View 6 Replies
Feb 22, 2011
I create an one webpage in asp.net all the time i am facing the following pbm how to rectify it..
if(ds.Tables[0].Rows.Count > 0)
View 2 Replies
Apr 28, 2010
How to get data from two tables through linq .1 ) productsDetails 2) productsImages to bind further listview.
View 1 Replies
May 13, 2010
From using the command: EXEC sp_spaceused on a SQL 2008 database,
the DB has a size of 642.56 MB, unallocated space 148.77 MB.
I can also see the size of the individual tables from the same command:
Reserved: 103656 KB
Data: 98264 KB
Index_size: 2656 KB
Unused: 2736 KB
What I don't quite get is why the total database size is 642.56 MB when the size of the individual tables is so much smaller. We pay for the total amount, in chunks of 500 MB. I was trying to see which tables where causing the DB to be so big, but to me, it looks like it is not the size of the tables but something else.
What should I look at to figure out why we are taking up so much space? Am I not understanding how this works?
View 6 Replies
Jun 15, 2010
I want to know that how many tables we can have in database and what is the maximum no. of columns.I also want to know the maximum size for each datatype.
View 3 Replies
Apr 27, 2010
I need to join some tables to get the matching records. I often have to ask around to see how certain tables could be joined. Is there any way to query the information schema or some thing else to see what columns/values match in certain tables in order to figure out how tables should be joined.
View 4 Replies
Jun 3, 2010
how i insert,update and delete data in multiple table .such tables in which primary and foreign key constraint are
View 1 Replies
May 13, 2010
I'm creating entity on a project to use them as data on my website. I got my base simple entity Users and my DataContext. The thing is i would like the database to create the table as i create Entities.
I mean, actually my database doesn't have a Users table and do not generate it as i build and launch the project. I used to be a Java dev and in Java the table can be created with JPA so i guess Microsoft made it possible with ASP.net but how to do? I've looked on the web but didn't find it.
View 2 Replies
Jun 29, 2010
Apologies if this is in the incorrect forum.. just a question about how to best structure some tables for a particular presentation of data. In the following table (2nd column) you'll see that each motorcycle product applies to a range of years. What is the best way to store this range of years in a relational db? At the moment I have a datefrom and a dateto field for the two ranges, but that may complicate things when I want to filter the table by a particular year. E.G. datefrom is 2006 & dateto is 2010 and I would like to filter by products for a 2008 model.
View 4 Replies
Feb 2, 2010
I don't know if I'm posting this in the right place - I have a feeling it can't be too difficult but I can't seem to figure it out. I've come across this problem many times and I've never solved it. I would imagine the scenario is commonplace - I have a table of Products with a PK of ProductID, and a table of related images with a FK of ProductID. Each product can have many images, but for my initial display I want to display one product record with one image record. I have a Sequence field in the Images table and I could pick the lowest one. Right and left Joins return too many records - if I have three images for Product 1 then Product 1 is listed three times.
I've gotten around this before using a flag in the Products table, or listing an image in both tables but I'm sure there must be a SQL statement that can get the information that I need.
View 5 Replies
Feb 17, 2010
I have a details view form inserting data into one table successfully with no problems and picking up the ID parameter from a session.
What i would like to do is one insert SOME of the fields NOT ALL get inserted into another table.
Table 1 = course
table 2 = matrixoneantwo
I tried creating a datasource which inserted data into Matrixoneanttwo and called it from the detailsview_inserting event (sqldatasource.insert() but then i realised that this data source is seperate to my current one and therefore cannot use its parameters.
View 11 Replies
Mar 27, 2010
I have 2 tables with UserId and FirstName, LastName Columns that I want to combine the data in a Select Statement or Stored Procedure
1. The 2 tables will never have the same data, each table will be distinct
2. I want to combine first and lastnames to a full name (t1.FirstName + ' ' + t1.LastName) AS FullName
3. The statement will be used to populate a dropdownlist with UserId as Value, and Name as text
I am unsure how to accomplish this since I do not need to connect the tables, but combine the Sum of their data.
View 6 Replies
Apr 21, 2010
I want to make some check before I add a list of data
so I create a temp table
[Code]....
and this is the qeury I retrive from DataBase
[Code]....
so now I get 2 data resultI just want to knowhow to compare these 2 data result?
[Code]....
then now allow to add new data...
View 2 Replies