function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Roberto LuengoRoberto Luengo 

Data loader error : Unmatched closing ')', but there are no extra )!

Hello community,

I have an error that is driving me crazy here.

I am doing a data upload from SQL Server to Salesforce, it has been working great with other SQLs but it is returning an error with the latest one I am implementing... Please advise?

SQL (reduced to the minimum expression, keep in mind the last select is to return the fields I have mapped to avoid an error)

DECLARE    @StartDate datetime = DATEDIFF(dd, 0,DATEADD(month, -5, GETDATE())) + convert(datetime, '00:00:00');
DECLARE    @EndDate datetime = DATEDIFF(dd, 0,DATEADD(day, -1, GETDATE())) + convert(datetime, '23:59:59');
DECLARE    @CountryCodes varchar(max)=null;
DECLARE    @AccountTypes varchar(max)='property';

if object_id('tempdb..#CountryCodes') is not null drop table #CountryCodes
select    CountryCode = convert(varchar(5), data)
into    #CountryCodes
from    dbo.Split(@CountryCodes, ',') a
where    nullif(data, '') is not null 

if object_id('tempdb..#AccountTypes') is not null drop table #AccountTypes
select    AccountType = convert(varchar(50), data)
into    #AccountTypes
from    dbo.Split(@AccountTypes, ',') a
where    nullif(data, '') is not null 

select '201705INT66942' as PerfDataID, 'test' as test
from dbo.Split('abc', ',')

Error returned

2017-06-21 01:45:37,892 ERROR [propertyMonthlyPerformanceData] action.AbstractAction handleException (AbstractAction.java:222) - Exception occured during loading
com.salesforce.dataloader.exception.DataAccessObjectInitializationException: Unmatched closing ')' near index 17
@CountryCodes, ',')
where    nullif(data, '') is not null 

if object_id('tempdb..#AccountTypes') is not null drop table #AccountTypes
select    AccountType = convert(varchar(50), data)
into    #AccountTypes
from    dbo.Split(@
                 ^
    at com.salesforce.dataloader.dao.database.DatabaseReader.open(DatabaseReader.java:115)
    at com.salesforce.dataloader.dao.database.DatabaseReader.open(DatabaseReader.java:99)
    at com.salesforce.dataloader.action.AbstractAction.execute(AbstractAction.java:123)
    at com.salesforce.dataloader.controller.Controller.executeAction(Controller.java:121)
    at com.salesforce.dataloader.process.ProcessRunner.run(ProcessRunner.java:149)
    at com.salesforce.dataloader.process.ProcessRunner.run(ProcessRunner.java:100)
    at com.salesforce.dataloader.process.ProcessRunner.main(ProcessRunner.java:253)
Caused by: java.util.regex.PatternSyntaxException: Unmatched closing ')' near index 17
@CountryCodes, ',')
where    nullif(data, '') is not null 

if object_id('tempdb..#AccountTypes') is not null drop table #AccountTypes
select    AccountType = convert(varchar(50), data)
into    #AccountTypes
from    dbo.Split(@
                 ^
    at java.util.regex.Pattern.error(Unknown Source)
    at java.util.regex.Pattern.compile(Unknown Source)
    at java.util.regex.Pattern.<init>(Unknown Source)
    at java.util.regex.Pattern.compile(Unknown Source)
    at java.lang.String.replaceFirst(Unknown Source)
    at com.salesforce.dataloader.dao.database.DatabaseContext.replaceSqlParams(DatabaseContext.java:134)
    at com.salesforce.dataloader.dao.database.DatabaseReader.setupQuery(DatabaseReader.java:123)
    at com.salesforce.dataloader.dao.database.DatabaseReader.open(DatabaseReader.java:111)
    ... 6 more
2017-06-21 01:45:37,892 ERROR [propertyMonthlyPerformanceData] progress.NihilistProgressAdapter doneError (NihilistProgressAdapter.java:58) - Unmatched closing ')' near index 17
@CountryCodes, ',')
where    nullif(data, '') is not null 

if object_id('tempdb..#AccountTypes') is not null drop table #AccountTypes
select    AccountType = convert(varchar(50), data)
into    #AccountTypes
from    dbo.Split(@
                 ^

 
NagendraNagendra (Salesforce Developers) 
Hi Roberto,

I use Sublime Text editor, you can get it here
https://www.sublimetext.com/3

It is useful when building formulae, validation rules etc with lots of nesting as it highlights the open and closing brackets as you move your insertion point through the text.

E.g. I'm on line 6 in this screenshot and you can see the brackets on lines 5 and 9 underlined: (the /*1*/ numbering was manually added by me):
User-added image

Hope this helps.

Mark this as solved if it's resolved.

Thanks,
Nagedra
Roberto LuengoRoberto Luengo
​Hey Mike, I was using Notepad++, but tried Sublime with the same result. As far as I can see there are no redundant brackets, not sure why it returns that error! Any advise? ​
Roberto LuengoRoberto Luengo
​Another question... It seems I am unable to do multiple selects or mix with inserts, etc. I want to do so to create temporary tables in my SQL! Is this a restriction?
Roberto LuengoRoberto Luengo
​After much tinkering... The problem is that I have @ in the SQL. It seems Data Loader is interpreting some of them as a parameter. Any advise? How do I use an @ in the SQL?​
Roberto LuengoRoberto Luengo
​Anyone? This is a bit of a nightmare :) I have genuine @ symbols in my SQL and the Data Loader keeps messing up with them. How do I escape them? Make DL ignore them?