Click here to Skip to main content
15,889,838 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using following query for select statement

SELECT	GODOWNNAME,  ITEMCODE,      ITEMNAME,
        STOCKQUANTITY as OPEN_QTY,  CLOSINGQTY,
       'PUR_QTY'  =  ISNULL(PURCHASEQUANTITY,0) + ISNULL(SALESRTNQTY,0) ,
       'SAL_QTY' =   ISNULL(PURCHASERTNQTY,0) + ISNULL(SOLDQUANTITY,0),  
FROM	@GODOWN_STOCK WHERE ITEMSRLNO=@ITEMSNO AND ('PUR_QTY'+'SAL_QTY'+STOCKQUANTITY+CLOSINGQTY)<>0
		ORDER	BY	GODOWNSRLNO,	ITEMCODE


But the error is displayed we cannot convert varchar to numeric. How to calculate the values for dynamic columns PUR_QTY , SAL_QTY

Please help me thank you
Posted

1 solution

Try:
SQL
SELECT	
     GODOWNNAME,  
     ITEMCODE,      
     ITEMNAME,
     STOCKQUANTITY as OPEN_QTY,  
     CLOSINGQTY,
     (ISNULL(PURCHASEQUANTITY,0) + ISNULL(SALESRTNQTY,0)) AS PUR_QTY,
     (ISNULL(PURCHASERTNQTY,0) + ISNULL(SOLDQUANTITY,0)) AS SAL_QTY,  
FROM	
     @GODOWN_STOCK 
WHERE 
     ITEMSRLNO=@ITEMSNO 
     AND 
     (PUR_QTY+SAL_QTY+STOCKQUANTITY+CLOSINGQTY)<>0
ORDER BY	
     GODOWNSRLNO,	
     ITEMCODE
 
Share this answer
 
Comments
devausha 23-Jun-12 7:18am    
There is too many columns should be added. So Is there any other method to solve this problem?
Arul R Ece 23-Jun-12 7:41am    
Can U pls confirm the data type for PUR_QTY , SAL_QTY
devausha 25-Jun-12 1:12am    
Pur_qty and Sal_qty is numeric(13,2)
devausha 25-Jun-12 2:26am    
I already tried above solutions, But the error is displayed UNKNOWN COLUMN NAME PUR_QTY,SAL_QTY

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900