What version of SQL is it?you can create two derived tables and select all 3 values from those (joined on RefNumber)Select Subtotal ,SeniorDiscount ,Total = Subtotal-SeniorDiscountFROM (SELECT REfNumber,InvoiceLineAmount as SubTotal FROM InvoiceLine WHERE RefNumber = <cfoutput>'#URL.thenumber#1'</cfoutput>' AND InvoiceLineRefFullName ='Subtotal' ) as SINNER JOIN ( SELECT RefNumber,InvoiceLineAmount AS SeniorDiscount FROM InvoiceLine WHERE RefNumber = <cfoutput>'#URL.thenumber#'</cfoutput> AND InvoiceLineRefFullName ='Senior Discount') as SDon S.RefNumber = SD.RefNumber
OR with SQL 2005 or later you can use CTE's;WITH S AS (SELECT REfNumber,InvoiceLineAmount as SubTotal FROM InvoiceLine WHERE RefNumber = <cfoutput>'#URL.thenumber#1'</cfoutput>' AND InvoiceLineRefFullName ='Subtotal' ) , SD AS ( SELECT RefNumber,InvoiceLineAmount as SeniorDiscount FROM InvoiceLine WHERE RefNumber = <cfoutput>'#URL.thenumber#'</cfoutput> AND InvoiceLineRefFullName ='Senior Discount') as SDSELECT Subtotal ,SeniorDiscount ,Total = Subtotal-SeniorDiscountFROM S INNER JOIN SD on S.RefNumber = SD.RefNumber
IF there is a chance there will be no records returned from the Senior Discount piece, you may have change to LEFT JOIN and use ISNULL(SeniorDiscount,0) in the final select...
Poor planning on your part does not constitute an emergency on my part.