When I appy the following query using T-SQL on MS Server I don't have any problems:
SELECT DISTINCT
*
FROM dbo.account
LEFT OUTER JOIN dbo.crm2cburl_lookup
ON account.Id = CRM2CBURL_Lookup.[Key]
LEFT OUTER JOIN dbo.organizations
ON CRM2CBURL_Lookup.CB_URL_KEY = organizations.cb_url
cross apply (values (charindex('://', homepage_url))) a(a)
cross apply (values (iif(a = 0, 1, a + 3))) b(b)
cross apply (values (charindex('/', homepage_url, b))) c(c)
cross apply (values (iif(c = 0, len(homepage_url) + 1, c))) d(d)
cross apply (values (substring(homepage_url, b, d - b))) e(e)
However, when I apply the similar (identical except for the database used) I get the error message missing 'JOIN' at 'apply'(line 14, pos 6) line 14 refers to
cross apply (values (charindex('://', homepage_url))) a(a)
The query on Databricks is as follows:
SELECT DISTINCT
*
FROM basecrmcbreport.account
LEFT OUTER JOIN basecrmcbreport.crm2cburl_lookup
ON account.Id = crm2cburl_lookup.Key
LEFT OUTER JOIN basecrmcbreport.organizations
ON crm2cburl_lookup.CB_URL_KEY = organizations.cb_url
cross apply (values (charindex('://', homepage_url))) a(a)
cross apply (values (iif(a = 0, 1, a + 3))) b(b)
cross apply (values (charindex('/', homepage_url, b))) c(c)
cross apply (values (iif(c = 0, len(homepage_url) + 1, c))) d(d)
cross apply (values (substring(homepage_url, b, d - b))) e(e)
My feeling the problem is a syntax error with 'charindex', but I'm not sure.
Any thoughts?