1

I have two tables Product and Purchase

Product
Item_Code   Item_Name          Packing   MRP
1           PANADOL TAB        1*200     200
2           PARACETAMOL TAB    1*50      200
3           CALPOL SYP         2*5       5
4           AUGMENTIN DROP     1*500     234
5           DISPRIN            10*60     14
6           NUBEROL FORT       5*20      245
7           PANADOL SYP        6*9       123
8           NORAN 20 CAP       1*5       765
9           CLARITEK DROP      2*9       45
10          NIVAQUIN P SYP     3*6       34

Purchase
Pur_Invoice_No  Item_Code   Pur_Item_PackQuantity
   1               1           3
   2               1           9
   2               2           3
   2               2           3
   3               1           9
   3               3           3
   3               9           3
   3               4           3
   6               4           14

Now I want to get all Item_Name from Product table and sum of Pur_Item_PackQuantity (colomn from Purchase Table) agianst Item_Name but have shown only that Item_Name which are exist in Purchase table not all item_Name from Product using given below Method.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Mateenwin
{
public partial class SumSaleQuantity : Form
{
    public SumSaleQuantity()
    {
        InitializeComponent();
        purchaseQuantity_Bind();
        PurchaseInvoice_Bind();
        PurchaseNameQuantity_Bind();
    }



    public void PurchaseNameQuantity_Bind()
    {
        string query = "SELECT Product.Item_Name,Packing,MRP,SUM(Purchase.Pur_Item_PackQuantity) FROM Product RIGHT JOIN Purchase ON Product.Item_Code = Purchase.Item_Code Group By Item_Name,MRP,Packing  ORDER BY Item_Name ";
        SqlConnection newcon = new SqlConnection("Data Source=.;Initial Catalog=mateenwin;User ID=sa;Password=123");
        SqlCommand newcommand = new SqlCommand(query, newcon);
        SqlDataAdapter dp = new SqlDataAdapter(newcommand);
        DataTable dttt = new DataTable();
        dp.Fill(dttt);
        dataGridView3.DataSource = dttt;
    }


    private void SumSaleQuantity_Load(object sender, EventArgs e)
    {

    }


}
}

Please help for this problem

sagi
  • 40,026
  • 6
  • 59
  • 84
  • LEFT JOIN ..... http://stackoverflow.com/questions/4715677/difference-between-left-join-and-right-join-in-sql-server – Steve Mar 15 '16 at 08:18

0 Answers0