I have set up a drill process from a Sql table. i get an error message saying "1840 [6] ERROR 2013-10-14 09:03:47.750 TM1.SQLAPI 37000[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'FA'."
below is the coding i am using. if i change the division parameter in the Query to read ('?Division?')) instead of ('?vDivision?')), i can drill through to the lowest level, but not any consolidated levels of division. if i keep it as it is below, it says drill handle was succesfully built, but did not return a valid handle. check the message log.
any ideas?
Query
Code: Select all
Select
Source, Journal, EntryGroup, Customer, CustomerName, Supplier, SupplierName,
Invoice, SubJournal, StockCode, Description, substring(GlCode,1,4) as Account, substring(GlCode,6,2) as Division,
substring(GlCode,9,2) as BusinessUnit, substring(GlCode,12,2) as Location, GlCode, GlCodeDescription, EntryValue,
GlPeriod as vMonth , GlYear as Year, Reference, Comment, GRN, NetSalesValue, PurchaseOrder, PaymGrossValue,
WarehouseFrom, WarehouseTo, PurchaseOrderLin, Job, JobDescription,
SalesOrder, SalesOrderLine, RegisterNumber, Asset, Line, JnlDate, EntryType, Branch, AssetCostCenter, AssetGroupCode,
AssetStatus,ADescription, DateSold, PurchaseDate, DisposedFlag, 'Actual' as Version
from tmpTrnDetail
where GlYear ='?Year?'
and (GlPeriod ) = ('?vMonth?')
and (substring(GlCode,1,4) in ('?Accounts?'))
and (substring(GlCode,6,2) in ('?vDivision?'))
and (substring(GlCode,12,2) = '?Location?')
and (substring(GlCode,9,2) = '?BusinessUnit?')
Code: Select all
#****Begin: Generated Statements***
#****End: Generated Statements****
#vmonth = subst(vmonth,1,(scan(vmonth,'.'))-1);
#vMonth = UPPER(DimensionElementPrincipalName('Month',vmonth));
Accounts = UPPER(DimensionElementPrincipalName('Accounts',Accounts));
division = UPPER(DimensionElementPrincipalName('Division',division));
BusinessUnit = UPPER(DimensionElementPrincipalName('Business Unit',BusinessUnit));
Location = UPPER(DimensionElementPrincipalName('Location',Location));
Currency = UPPER(DimensionElementPrincipalName('Currency',Currency));
# variable for generated SQL
sSQL=' ';
# we need the children of this consolidated element in Division dimension
sDimName = 'Division';
sParentElemName=Division;
# build subset in Division dimension with all leaf children of the parent
sSubName='zTemp';
SubsetCreateByMdx(sSubName,'{TM1FILTERBYLEVEL( {TM1DRILLDOWNMEMBER( {['|sDimName|'].['|sParentElemName|']}, ALL, RECURSIVE )}, 0)}');
# iterate subset and add leaf elements to SQL statement
nCounter=1;
nMaxCount= SubsetGetSize(sDimName,sSubName);
WHILE(nCounter<=nMaxCount);
sElemName= SubsetGetElementName(sDimName,sSubName,nCounter);
# make sure it is principal name to match values in source system
# probably don't need this line - the MDX should return this
sPrincipalElemName= DimensionElementPrincipalName(sDimName,sElemName);
# update SQL
sSQL= sSQL|CHAR(39)|sPrincipalElemName|CHAR(39);
# need a comma unless last item in subset
IF(nCounter<nMaxCount);
sSQL=sSQL|',';
ENDIF;
nCounter=nCounter+1;
END;
# clean up temp subset
SubsetDestroy(sDimName,sSubName);
# debug output
AsciiOutput('debug.txt',sSQL);
# assign to drill-through query
vDivision=sSQL;