Last post Feb 23, 2009 05:29 PM by harunkaraman
Jan 29, 2009 12:44 AM|joeLA|LINK
In code behind (.cs), I have to perform two seperate sql queries.
For the simplicity, First I need to select the CustomerName from TableA. then another query to select CustomerPhone from TableB.
Note that there IS NO join between these two tables.
How can I combine these two resullts so that I can bind it to a single gridview datasource?
Any suggestion for a simple solution.. ?
Jan 29, 2009 02:13 AM|trdudei|LINK
Do your tables have only one column? Iterate through tableB and copy all rows to tableA...
It could also be done at the database level with: select CustomerName from TableA UNION ALL select CustomerPhone from TableB...
Jan 29, 2009 02:52 AM|joeLA|LINK
The tables have more multiple columns.
I forgot to mention that I also need to select CustomerID, CustomerName from TableA and use this CustomerID as a condition input to select CustomerPhone from TableB. (again no join between the two tables)
So the result should be a new list/array consisting of one record or row of CustomerName and CustomerPhone.
Jan 29, 2009 03:13 AM|santhosh11s|LINK
You said "I also need to select CustomerID, CustomerName from TableA and use this CustomerID as a condition input to select CustomerPhone from TableB"
Do you have a column CustomerID in TableB? What is the relation between two tables
Can you please give us the table structure of TableA and TableB
Jan 29, 2009 03:36 AM|joeLA|LINK
Here is the better scenario:
TableA: CustomerID, CustomerName, CustomerAddress.
TableB: CustomerID, CustomerPhone.
I know you will tell me why not use the join keyword but I can not use join here because the real queries are lot more complicated..and I want to perform these 2 queries seperately.
So what i'm trying to do is as follow:
- Query1: select CustomerID, CustomerName, CustomerAddress from TableA;
- Query2: select CustomerPhone from TableB where CustomerID = @varCustomerID;
- combine the results from the two queries into one row which should look like below:
row1: CustomerName, CustomerAddress, CustomerPhone
All these in asp.net using c#
Jan 29, 2009 04:49 AM|izharulislam|LINK
you need to iterate manually on two tables to achieve the required result.However i would suggest you using join on two tables because there would be no gain in performance by iterating tables manually.
Do take join on customer ID and create an index on customer id to get better performance.
For manually iterating rows you can do this .
for (int counter = 0;counter < dtA.Rows.Count ; counter++)
DataRows dr = dtB.Rows.Select('customer_id = ' + dtA.Rows.Columns);
Now get the required index from dr array and store the value in dtA.
Jan 29, 2009 03:24 PM|joeLA|LINK
I'm still not sure I understand your logic completely..
Can you explain what each line does? or better yet give me a complete example...?
Feb 23, 2009 05:29 PM|harunkaraman|LINK
I also have similar problem. Please help me if you find something. I have 2 separate querys. One of them finds the latest dated line of a table and I would like to join it with the original one.
'Costumers' is the original table
'Query1' latest entry related to the same costumers as a table extracted from 'Costumers'
'Query2' is another query combining Costumers with Query1 (Query2 = Costumers + Query1)
Now my problem is I would like to use a single SQL statement to create Query2 directly bypassing the Query1