I have two tables. table1 and table2 as follows
| id | date | amnt |
|---|---|---|
| 1 | 01/01/2011 | 100 |
| 1 | 05/01/2011 | 100 |
| 1 | 10/01/2011 | 50 |
| 1 | 16/01/2011 | 500 |
| 1 | 17/01/2011 | 550 |
| 2 | 01/01/2011 | 10 |
| 2 | 15/01/2011 | 100 |
| 2 | 18/01/2011 | 800 |
| 2 | 20/01/2011 | 450 |
| 3 | 10/01/2011 | 15 |
| id | nan | hnm |
|---|---|---|
| 1 | Madhu | Namparayil |
| 2 | Anoop | Puthenveettil |
| 3 | Dhanya | Payyampallil |
I want id, nam,hnm, sum(amnt) of the above three customers as follows
1-Madhu - Namparayil - 1300
2-Anoop - Puthenveettil - 1360
3-Dhanya - Payyampallil - 15
Please give SQL command using c#
Satyapriya NayakPosted Sep 1, 2011, 10:07 AM
Your answer
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select t1.id, t2.name, t2.address, sum(t1.amount)from t2 inner join t1 on t2.id=t1.id group by t1.id, t2.name, t2.address";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();
con.Close();
}
Thanks
If this post helps you mark it as answer
Madhukumar ViswanathenPosted Sep 1, 2011, 2:10 PM
Satyapriya NayakPosted Sep 1, 2011, 1:13 PM
If this post helps you mark it as answer
Thanks