Good afternoon,I have the following two queries :SELECT a.[date] as iDate, SUM(a.struck_stake) as struck_stakes, sum(a.struck_stake)-sum(settled_returns) as GPFROM AGG1.dbo.AGG_DAY_009 as ainner join WHouse1.dbo.Date_Dim as b on b.date_key = a.DATEinner join WHouse1.dbo.COST_CENTRE_DIM as c on c.COST_CENTRE_NUMBER = a.COST_CENTRE_NUMBERWHERE c.CURRENT_FLAG = 'C'AND a.Date = 20051019 AND c.COST_CENTRE_NUMBER = 2309group by a.[date](select b.df1date as iDate, b.take as struck_stakes, b.adjustedGP as GPfrom whouse1.dbo.date_dim as ainner join whouse1.dbo.daily_figures_fact as b on a.date_key = b.df1dateinner join whouse1.dbo.cost_centre_dim as c on c.cost_centre_code = b.shopwhere (c.current_flag = 'c' or c.current_flag = 'x')and b.df_username <> 'system'and c.cost_centre_code = 2309and a.date_key = 20051019)
I want to subtract the struck_stakes in the first query from the struck_stakes in the second one. I thought about joining the two tables (they both return one record each) on the date then subtract the values but I have a feeling that there is a better way to do it by assiginig the values to variables within the select statment.How can this be done?Many thanks in advance.