GK in the UK
Registered User.
- Local time
- Today, 21:24
- Joined
- Dec 20, 2017
- Messages
- 281
I have a query which returns the values I need, but I would like them returned into one column.  By that, I mean, I can get three columns in the dataset, called Balance_Grp, Balance_PL, and Balance_BS.  
I want to consolidate them into one value, OR, format a string according to whether the value is >0 or <0.
I made a string function fDebitCredit which returns a 32 character string, either like '_______________£123,456,789.02' OR ' £123,456,789.02_______________' (with spaces not underscores but you get the idea)
Now when I put this in my query:
nodeText: nominalName & Switch( [nominalType]="H",fDebitCredit(Balance_Grp), [nominalType]="P",fDebitCredit(Balance_PL), [nominalType]="B",fDebitCredit(Balance_BS))
Access says sub queries cannot be used.
Here is the query. For a single row returned by the query, I want one only of Balance_BS, Balance_PL, Balance_Grp, but returned into the same named column. fGroupTotal is an external function.
	
	
	
		
 I want to consolidate them into one value, OR, format a string according to whether the value is >0 or <0.
I made a string function fDebitCredit which returns a 32 character string, either like '_______________£123,456,789.02' OR ' £123,456,789.02_______________' (with spaces not underscores but you get the idea)
Now when I put this in my query:
nodeText: nominalName & Switch( [nominalType]="H",fDebitCredit(Balance_Grp), [nominalType]="P",fDebitCredit(Balance_PL), [nominalType]="B",fDebitCredit(Balance_BS))
Access says sub queries cannot be used.
Here is the query. For a single row returned by the query, I want one only of Balance_BS, Balance_PL, Balance_Grp, but returned into the same named column. fGroupTotal is an external function.
		Code:
	
	
	SELECT "recid" & [nominalid] AS ID,
       "recid" & [nominalparent] AS parentID,
       tblnominalaccounts.nominalname AS nodeText,
       "recid" AS identifier,
       tblnominalaccounts.nominaltype, Sum(tbltranslines.tlnetvalue) AS NetSum,
       Sum(Iif([thacyrprd] <= [endacyrprd] AND [nominaltype] = "b", Nz([tbltranslines].[tlnetvalue], 0), NULL)) AS Balance_BS,
       Sum(Iif(( [thacyrprd] >= [startacyrprd] )AND ( [thacyrprd] <= [endacyrprd] )AND ( [nominaltype] = "p" ), ( Nz([tlnetvalue], 0) ), NULL))AS Balance_PL,
       Sum(Iif([nominaltype] = "h", Fgrouptotal([nominalid], [startacyrprd],[endacyrprd],[thpbno]), NULL)) AS Balance_Grp
FROM   tbltransheaders
       RIGHT JOIN (tbltranslines
                   RIGHT JOIN tblnominalaccounts
                           ON tbltranslines.tlnominalfk =
                              tblnominalaccounts.nominalid)
               ON tbltransheaders.transheaderid = tbltranslines.tltransheaderfk
GROUP  BY "recid" & [nominalid],
          "recid" & [nominalparent],
          tblnominalaccounts.nominalname,
          "recid",
          tblnominalaccounts.nominaltype
HAVING (( ( tblnominalaccounts.nominaltype ) = "h" ))
        OR ( ( ( Sum(tbltranslines.tlnetvalue) ) <> [thvalue] )
             AND ( ( Max(tbltransheaders.thpostingbatchno) ) >= [thpbno] ) ); 
	