Nathan

Nathan

  • NA
  • 24
  • 15.4k

Confusion in SQL Server Stored Procedure Inner Join

Mar 3 2014 4:26 AM
Sir,
I am getting an zero value return result in a  SQL Server Query. Please go through the query and make correction.
My table to inner join is:-
1) TAXSLAB

2) PRODUCTS
 
Here the query.

I want to display inputrate from TAXSLAB table as per the taxId in the PRODUCTS table


Please find the highlighted text in this query where i want to to get result :-


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[Get_PurchaseDetails]
(
@as_ID bigint
)
AS

BEGIN
SELECT
INVPURCHASE.ID,
INVPURCHASE.CompCode,
INVPURCHASE.DivCode,
INVPURCHASE.YearCode,
INVPURCHASE.BillNo,
INVPURCHASE.OrderNo,
INVPURCHASE.pdate,
INVPURCHASE.pfrom,
INVPURCHASE.custcode,
INVPURCHASE.amount,
INVPURCHASE.disc,
INVPURCHASE.tax,
INVPURCHASE.frieght,
INVPURCHASE.netamt,
INVPURCHASE.paidamt,
INVPURCHASE.cashmode,
INVPURCHASE.[type],
INVPURCHASE.ltype,
INVPURCHASE.remarks,
INVPURCHASE.contactid,
INVPURCHASE.salespersonid,
INVPURCHASE.creditcardid,
INVPURCHASE.rowguid,
INVPURCHASE.insuserid,
INVPURCHASE.upduserid,
INVPURCHASE.modidate,
INVPURCHASE.isdelivered,
INVPURCHASE.isdeleted,
INVPURCHASE.isblocked,
INVPURCHASE.ischecked,
INVPURCHASE.isaudited,
INVPURCHASE.custregno,
INVPURCHASE.gid,
INVPURCHASE.roundoff,
INVPURCHASE.cashac,
INVPURCHASE.transac,
FN_LedgerMembers.LNAME AS CustName
FROM INVPURCHASE INNER JOIN FN_LedgerMembers ON INVPURCHASE.CustCode = FN_LedgerMembers.LedgerID
WHERE INVPURCHASE.ID = @as_ID AND INVPURCHASE.isdeleted = 'False'

SELECT
INVPURCHASEITEMS.ID,
INVPURCHASEITEMS.PurchaseID,
INVPURCHASEITEMS.PCode,
INVPURCHASEITEMS.PID,
INVPURCHASEITEMS.batchno,
INVPURCHASEITEMS.rate,
INVPURCHASEITEMS.qty,
INVPURCHASEITEMS.freeqty,
INVPURCHASEITEMS.disc,
INVPURCHASEITEMS.taxid,
INVPURCHASEITEMS.taxrate,
INVPURCHASEITEMS.tax,
INVPURCHASEITEMS.amount,
INVPURCHASEITEMS.isdeleted,
INVPURCHASEITEMS.discper,
INVPURCHASEITEMS.remarks,
INVPURCHASEITEMS.mandate,
INVPURCHASEITEMS.expdate,
INVPURCHASEITEMS.conrate,
INVPURCHASEITEMS.mrp,
INVPURCHASEITEMS.uomid,
INVPURCHASEITEMS.stockaffect,
INVPURCHASEITEMS.accountid,
INVPRODUCTS.PNAME,
INVCOMPANY.[NAME],
INVSTOCK.QTY AS STOCK,
INVSTOCK.GID,
INVSTSLAB.inputrate
FROM INVPURCHASEITEMS
INNER JOIN INVPRODUCTS ON INVPURCHASEITEMS.PID = INVPRODUCTS.PID
LEFT JOIN INVCOMPANY ON INVPRODUCTS.COMPANYCODE = INVCOMPANY.COMPANYCODE
INNER JOIN INVSTOCK ON INVPRODUCTS.PID = INVSTOCK.PID
INNER JOIN INVPURCHASE ON INVPURCHASE.ID = INVPURCHASEITEMS.PURCHASEID
INNER JOIN INVSTSLAB ON INVSTSLAB .SlabID = INVPRODUCTS.PID
WHERE INVPURCHASEITEMS.PURCHASEID = @as_ID AND INVPURCHASEITEMS.isdeleted = 'False'
AND INVPURCHASE.LTYPE = INVSTOCK.LTYPE AND INVPURCHASE.YEARCODE = INVSTOCK.YEARCODE
AND INVPURCHASE.GID = INVSTOCK.GID AND INVPURCHASEITEMS.batchno = INVSTOCK.batchno


END

 

Answers (1)