Hi alhamd,
use ISNULL function.
Refer below query.
SQL
DECLARE @tblPurchaseTran AS TABLE(Product CHAR(10),P_Price INT,P_Head VARCHAR(50))
INSERT INTO @tblPurchaseTran VALUES('A',100,'Fixed Asset')
INSERT INTO @tblPurchaseTran VALUES('B',200,'Fixed Asset')
INSERT INTO @tblPurchaseTran VALUES('C',200,'Expenditure')
DECLARE @tblSaleTran AS TABLE(Product CHAR(10),P_Price INT,P_Head VARCHAR(50))
DECLARE @Asset INT
SET @Asset = (ISNULL((select Sum(ISNULL(P_Price,0)) as Amount from @tblPurchaseTran where P_Head='Fixed Asset'),0) - ISNULL((select Sum(ISNULL(P_Price,0)) as Amount from @tblSaleTran where P_Head='Fixed Asset'),0))
SELECT 'Fixed Asset' 'Asset', @Asset 'Price'
Output
Asset |
Price |
Fixed Asset |
300 |