2
Answers

How to Create Sql Query in Windows Form C#

Photo of Jyoti Jodha

Jyoti Jodha

7y
197
1
How to Create Sql Query For Product Master
 
Records Fetch Seles Table & Purchase Table
 
 

Answers (2)

0
Photo of Dharmraj Thakur
NA 4.1k 61.7k 7y
Do not execute this query directly first understand all statements and thing about your requirement... here is basic queries, let me know next queries later after understanding this...
  1. --get current stock of product  
  2. Select ProductID, ProductName, ClosingStockQTy, ClosingStockRs from ProductMaster where Product = 1  
  3.   
  4. --on purchase add stock  
  5. insert into Purchases (BillNo, BillDate, ProductID, Rate, Discount, Qty, TotalAmount)  
  6. values  
  7. (  
  8.     'CP1',  
  9.     getdate(),  
  10.     @ProductID,  
  11.     @Rate,  
  12.     @Discount,  
  13.     @Qty,  
  14.     @TotalAmount  
  15. )  
  16.   
  17. declare @StockQTy as int=0;  
  18. set @StockQTy = (select top 1 ClosingStockQty from ProductMaster where ProductID = 1);  
  19. set @StockQTy = @StockQTy + @Qty;  
  20.   
  21. Update ProductMaster  
  22. set  
  23.     ClosingStockQTy = @StockQTy  
  24. Where  
  25.     ProductID = 1  
  26.   
  27.   
  28. --on sale decrease stock  
  29. insert into Sales (BillNo, BillDate, ProductID, Rate, Discount, Qty, TotalAmount)  
  30. values  
  31. (  
  32.     'CS1',  
  33.     getdate(),  
  34.     @ProductID,  
  35.     @Rate,  
  36.     @Discount,  
  37.     @Qty,  
  38.     @TotalAmount  
  39. )  
  40.   
  41. declare @StockQTy as int=0;  
  42. set @StockQTy = (select top 1 ClosingStockQty from ProductMaster where ProductID = 1);  
  43. set @StockQTy = @StockQTy - @Qty;  
  44.   
  45. Update ProductMaster  
  46. set  
  47.     ClosingStockQTy = @StockQTy  
  48. Where  
  49.     ProductID = 1
0
Photo of Ramesh Barik
NA 639 90 7y
You can use inner join and left join to get the result.
  1. select PM.ProductID, PM.ProductName, PM.MRP,  
  2. Purchase.BillDate as PurchaseBillDate,Purchase.Rate as PurchaseRate,  
  3. Sales.BillDate as SalesBillDate,Sales.Rate as SalesRate  
  4. from Productmaster PM  
  5. inner join Purchase on PM.ProductID=Purchase.ProductID  
  6. left join Sales on PM.ProductID = Sales.ProductID  
  7. where PM.ProductID= 1000