TrySELECT case when country='SWISS' and currency_code in('EUR','CHF','USD')then 'CHF'else currency_code end as currency,com.country,com.fb_id,(sum(CASE WHEN drcr_flag='DR' THEN isnull(base_amount,0) ELSE 0 END))+ (sum(CASE WHEN drcr_flag='CR' THEN isnull(base_amount,0)* (-1) ELSE 0 END)) as ous_amount,'outstanding'FROM fin_ods..Fbp_posted_trn_dtl dtl(nolock) inner join fin_ods..Company_Fb_mst com(nolock)ON dtl.fb_id=com.fb_idWHERE account_code in(SELECT DISTINCT account_code FROM fin_ods..as_opaccount_dtl(nolock)WHERE ctrl_acctype ='CUSTRECACC')and dtl.fb_id ='RSLSOLFB'-- @FB_Id_Inand posting_date <= '20071231'--dbo.date_format(@To_Posting_date_in,'YYYYMMDD')AND com.country = 'Swiss'--@Country_Name_InGroup by country,case when country='SWISS' and currency_code in('EUR','CHF','USD')then 'CHF'else currency_code end ,com.fb_id