exec sp_executesql N' DECLARE @ID_IndentBillOnNet uniqueidentifier 
															 DECLARE @IndentBillOnNetNo nvarchar(64) 
															 SELECT TOP 1 @IndentBillOnNetNo = IndentBillOnNet.No_IndentBillOnNet FROM IndentBillOnNet 
															 Join Customer On Customer.ID_Customer=IndentBillOnNet.ID_Customer 
															 WHERE IndentBillOnNet.No_IndentBillOnNet > @No_IndentBillOnNet 
															 And Customer.ID_Creator=case IsNull(DataLength(@Right),0) When 0 Then Customer.ID_Creator Else @Right End	--added for validating right  
															 ORDER BY IndentBillOnNet.No_IndentBillOnNet  
															 SELECT IndentBillOnNet.*, Customer.No_Customer, Customer.Name_Customer, Customer.ShortName_Customer, Customer.Type_Customer, 
																	  Customer.LastDiscount_Customer, Customer.PostalCode_Customer, ISNULL(b.Name_User, '''') AS Name_Assessor, Customer.ID_Creator As CustomerCreator, 
                                     c.Name_User AS LastModUserName,d.Name_User AS DeleteUserName
																	  FROM IndentBillOnNet 
																	  LEFT JOIN Customer ON Customer.ID_Customer = IndentBillOnNet.ID_Customer 
																	  LEFT JOIN AppUser b ON b.ID_User = IndentBillOnNet.ID_Assessor 
                                     LEFT JOIN AppUser c ON c.ID_User = IndentBillOnNet.LastModUser_IndentBillOnNet
                                    LEFT JOIN AppUser d ON d.ID_User = IndentBillOnNet.DeleteUser_IndentBillOnNet
																	  WHERE IndentBillOnNet.No_IndentBillOnNet = @IndentBillOnNetNo 
															   SELECT @ID_IndentBillOnNet = IndentBillOnNet.ID_IndentBillOnNet FROM IndentBillOnNet WHERE IndentBillOnNet.No_IndentBillOnNet = @IndentBillOnNetNo 
								
								SELECT [ID_IndentBillOnNetProduct]
      ,[No_IndentBillOnNetProduct]
      ,IndentBillOnNetProduct.[ID_IndentBillOnNet]
      ,IndentBillOnNetProduct.[ID_Product]
      ,[Quantity_IndentBillOnNetProduct]
      ,[UnitPrice_IndentBillOnNetProduct]
      ,IndentBillOnNet.No_IndentBillOnNet as [Comment_IndentBillOnNetProduct]
      ,[Amount_SaleBill], 
								Product.No_Product, Product.Name_Product, Product.Unit_Product, A.AvailableQty_ProductStocks,
                                (IndentBillOnNetProduct.Quantity_IndentBillOnNetProduct * IndentBillOnNetProduct.UnitPrice_IndentBillOnNetProduct) AS Amount_IndentBillOnNetProduct ,Price_Product 
                                FROM IndentBillOnNetProduct
								LEFT JOIN IndentBillOnNet on IndentBillOnNet.ID_IndentBillOnNet = IndentBillOnNetProduct.ID_IndentBillOnNet 
                                LEFT JOIN Product ON Product.ID_Product = IndentBillOnNetProduct.ID_Product
                                Left join (Select ID_Product,Sum(AvailableQty_ProductStocks) As AvailableQty_ProductStocks From ProductStocks
                                Group By ID_Product) A On A.ID_Product = Product.ID_Product
                                WHERE IndentBillOnNetProduct.ID_IndentBillOnNet = @ID_IndentBillOnNet ORDER BY CAST(IndentBillOnNetProduct.No_IndentBillOnNetProduct AS INT)',N'@No_IndentBillOnNet nvarchar(64),@Right uniqueidentifier',@No_IndentBillOnNet=N'IBN201904010001',@Right=NULL