Query not running properly - database

I ran a query using google big query but I get an error as a result. I don't know what could be wrong.
SELECT
usertype,
CONCAT(start_station_name, " to ", end_station_name) AS route,
COUNT(*) as num_trips,
ROUND(AVG(CAST(tripduration AS INT64)/60),2) AS duration
FROM
`bigquery-public-data.new_york_citibike.citibike_stations`
GROUP BY
start_station_name, end_station_name, usertype
ORDER BY
num_trips DESC
LIMIT 10

You must be getting this error: Unrecognized name: usertype . As the error suggests bigquery-public-data.new_york_citibike.citibike_stations dataset doesn't have any column usertype.
As #samuel mentioned, usertype column is present in new_york_citibike.citibike_trips. Do cross check your dataset before querying.

Related

Why do I get the Error Message: "No modifications to the 'SYSTEM' or 'INTEGRATION' user are permitted.", when I add an Optional default Value?

I'm migrating some Database from SSMS to CRM Online. And the problem is, that there are systemuser in SSMS Database, which were deleted in CRM Online, or worse the systemuser has a new GUID. In this case I tried to look for similarities. I found out, that the systemusers from both System have the same value in the field "internalemailaddress". So I used it in my Dynamics CRM Destination. And added an value for the "optional default value".
And this Error code came out:
CRM service call returned an error: No modifications to the 'SYSTEM' or 'INTEGRATION' user are permitted.
On the other site, I could use the fullname, which I did with an "optional default value".
And this gave me this Error code:
CRM service call returned an error: systemuser With Id = 11111-111-AAAA-BBBB-123456789 Does Not Exist
and
CRM service call returned an error: An unexpected error occurred.
And when I don't write anything in the "Optional default value" I get this Error message: KingswaySoft.IntegrationToolkit.DynamicsCrm.LookupFailureException: Text lookup failed for 'managerid' field, entity 'systemuser' does not contain a record that has a value of '' for 'fullname' field (SSIS Integration Toolkit for Microsoft Dynamics 365, v11.1.0.7311 - DtsDebugHost, v15.0.2000.93)
Does someone know the problem and the solution?
I would be really grateful.
My first mistake was, that I tried to give the GUID in the "internalEmailAddress". To solve it, I did an LEFT JOIN where I get all Territory's and their SystemUsers.
My SQL Query:
SELECT Territory.*, ModifiedBy.InternalEMailAddress as M_EMail,
CreatedBy.InternalEMailAddress as C_EMail, ManagerId.InternalEMailAddress as Manager_Email
FROM TerritoryBase as Territory
LEFT JOIN SystemUser as ModifiedBy
ON Territory.ManagerId = ModifiedBy.SystemUserId
LEFT JOIN SystemUser as CreatedBy
ON Territory.CreatedBy = CreatedBy.SystemUserId
LEFT JOIN SystemUser as ManagerId
ON Territory.ManagerId = ManagerId.SystemUserId
Then in the Destination I assigned the columns like:
Source Destination
C_Email CreatedBy
M_Email ModifiedBy
Manager_Email ManagerId
And the Text Lookup Editor is like:
InternalEmailAddress(E-Mail from SystemUser)
This solved the problem, but I still got this error:
CRM service call returned an error: No modifications to the 'SYSTEM' or 'INTEGRATION' user are permitted.
The problem for this Errorcode was, that I had multiple SystemUser in Territory in the field "ManagerId", that didn't exist in the Online CRM. And since I put a "default option value", all the missing SystemUsers were assigned to 1 SystemUser. And in CRM you cannot assign 1 SystemUser to more Territory's ManagerId's field. So the end result was to not fill the field, if the user didn't exist.
But if you need to assign SystemUser's to the ManagerId field, then you should assign the SystemUsers manually with a "Derived Column".

Error: an expression of non-boolean type specified in a context where a condition is expected, near ',' ; Using Cascading Parameters

I am trying to use cascading parameters to filter this Pivot table in SSRS Report Builder.
This is the main dataset query:
SELECT * FROM(
SELECT *,
CASE WHEN PLN=PLN THEN '01. GROSS PREMIUM'
ELSE NULL
END AS PREMIUM
FROM MYI
PIVOT (SUM(GROSS_PREMIUM_1) FOR PERIOD_TYPE IN([MTD],[YTD],[ITD])) pvt
UNION ALL
SELECT *,
CASE WHEN PLN=PLN THEN '02. REFUND'
ELSE NULL
END AS PREMIUM
FROM MYI
PIVOT (SUM(REFUND_2) FOR PERIOD_TYPE IN([MTD],[YTD],[ITD])) pvt
)A
WHERE ACC_PERIOD = #ACC_PERIOD
AND REINSURER IN (#REINSURER)
AND INSURER IN (#INSURER)
AND PLN IN (#PLN)
AND SVC_AGY IN (#SVC_AGY)
These parameters in the WHERE clause each have their own dataset and are cascaded from top to bottom.
Here is the query for the final parameter as an example:
SELECT DISTINCT [fasren_servicingagency]
FROM [FAS_ReinsuranceNumber]
WHERE ACC_PERIOD = #ACC_PERIOD
AND REINSURER IN (#REINSURER)
AND INSURER IN (#INSURER)
AND PLN IN (#PLN)
ORDER BY SVC_AGY
The query runs fine in SSMS, but I keep getting this error when I run it in the SSRS report builder:
An expression of non-boolean type specified in a context where a condition is expected, near ','
It must have something to do with the WHERE clause in either the main query or the parameter dataset queries. I have seen many posts about this error but I could not find a solution that helped with my problem. Any ideas?
NOTE: all parameters are character fields, no integers, no date columns.
EDIT: There is another query that I was successful with;
SELECT [acctyymm],
[retrosummary],
[retroagent],
[coveragedivision],
[policyinsurer],
SUM([NetDue]) AS NET_DUE,
SUM([ActualPayable]) AS PAYABLE
FROM [dbo].[RetroNumberGAAP]
WHERE [acctyymm] IN (#ACC_PERIOD)
AND [retrosummary] IN (#RETSUM)
AND [retroagent] IN (#RETAGT)
AND [coveragedivision] IN (#PLN)
AND [policyinsurer] IN (#INSURER)
AND POWER([fasrtng_NetDue],2)+POWER([ActualPayable],2)<>0
GROUP BY [acctyymm],
[retrosummary],
[retroagent],
[coveragedivision],
[policyinsurer]
How am I successful running the report with cascaded parameters in this second query and not the first query?
I figured out what I did wrong. My Dataset properties were not configured correctly in the Report Builder.
WRONG CONFIGURATION
Dataset properties; Parameters; parameter name: SVC_AGY Parameter Value: [#SVC_AGY]
CORRECTED CONFIGURATION
Dataset properties; Parameters; parameter name: #SVC_AGY Parameter Value: [#SVC_AGY]
Make sure your parameter names match your parameter values, including the # symbol.

Apex SOQL query removing object type designation from id in query

I am attempting to query a custom object that has a master detail lookup relation with opportunities. When I build the query dynamically I am getting an SOQL error:
System.QueryException: unexpected token: 'A000000VmhPyIAJ'
The first three characters of the ID have been dropped in that exception, the full ID is:
006A000000VmhPyIAJ
If I dump the query string with System.debug I get this (with the full ID):
SELECT id, isdeleted, name, createddate, createdbyid, lastmodifieddate, lastmodifiedbyid, systemmodstamp, lastactivitydate, opportunity__c, issue__c, description__c, ... FROM Exceptions__c WHERE Opportunity__c = 006A000000VmhPyIAJ
If I pass this exact same string into the database.query() I get results as expected.
Anyone have any idea what is causing this? The code that is generating that query is a library that I use for hundreds of other queries through out our custom Apex, and none of those queries are failing.
The actual query block:
try {
String query = 'SELECT id, isdeleted, name, createddate, createdbyid, lastmodifieddate, lastmodifiedbyid, systemmodstamp, lastactivitydate, opportunity__c, issue__c, description__c, ... FROM Exceptions__c WHERE Opportunity__c = 006A000000VmhPyIAJ';
exceptions = database.query( query );
} catch(DmlException e) {
System.debug('DmlException: ' + e);
}
Forgot to escape single quotes on the where clause value.
WHERE Opportunity__c = '006A000000VmhPyIAJ'

How to use inner query to fetch data from salesforce to mule?

I wrote below query to fetch data from salesforce but getting error like "Unknown error parsing query"
select Email,Id from contact where Email in (select b.Email from contact as b group by b.Email having count(b.id) < 2 limit 1000)
inner query alone retrieving the set of mail Ids, please suggest.
Are you sure the issue is not related with the query / organisation ?
Using SOQL workbench --> https://workbench.developerforce.com
and getting this error:
MALFORMED_QUERY:
(select b.Email from contact as b group by b.Email having count(b.id)
^
ERROR at Row:1:Column:78
expecting a right parentheses, found 'group'
You can first check your query on Salesforce using developer console if its working or not.
If its returning required result in Salesforce then it will work in Mulesoft as well.

Insert bigquery job table not found

I am trying to run an asynchronous query. When I submit it to Bigquery it answers me that the table does not exist (status is "DONE"). What is wrong?
jobData = {'configuration': {'query': {'query': query, 'createDisposition': 'CREATE_NEVER'}}}
logger.info('jobdata: %s', jobData)
insertResponse = self.service.jobs().insert(projectId = PROJECT_ID, body = jobData).execute()
if 'errorResult' in str(insertResponse):
logger.error('query insert failed: %s', insertResponse)
This worked a few weeks back but no more. The error I get seems to indicate that the table cannot be found (or is it some kind of temporary table and all is well?)
jobdata: {'configuration': {'query': {'createDisposition': 'CREATE_NEVER', 'query': 'SELECT TIMESTAMP_TO_MSEC(timestamp) AS timestamp, location, branch, platform, description, original, metrics.group, metrics.id, metrics.name, metrics.value, DATE(timestamp) AS date FROM [mm.autotest] WHERE DATEDIFF(CURRENT_TIMESTAMP(), timestamp) < 14'}}}
query insert failed: {u'status': {u'state': u'DONE', u'errors': [{u'reason': u'notFound', u'message': u'Not found: Table ava-backend:_24bc4b39cef74439ece7e6f9a41399c21fccacd8.anonev_c7HQskNXMdaxCBDXdnAtOzlSJ6M'}], u'errorResult': {u'reason': u'notFound', u'message': u'Not found: Table ava-backend:_24bc4b39cef74439ece7e6f9a41399c21fccacd8.anonev_c7HQskNXMdaxCBDXdnAtOzlSJ6M'}}, u'kind': u'bigquery#job', u'statistics': {u'endTime': u'1390899670652', u'creationTime': u'1390899670344', u'startTime': u'1390899670652'}, u'jobReference': {u'projectId': u'ava-backend', u'jobId': u'job_EowCD-kiOirnlyRAQjFJNFoRFUY'}, u'etag': u'"11dTZYgUnUwbk8emYQU9mVRTTLs/0mRkexpB4dgaqONWphRujyRJhqM"', u'configuration': {u'query': {u'createDisposition': u'CREATE_NEVER', u'query': u'SELECT TIMESTAMP_TO_MSEC(timestamp) AS timestamp, location, branch, platform, description, original, metrics.group, metrics.id, metrics.name, metrics.value, DATE(timestamp) AS date FROM [mm.autotest] WHERE DATEDIFF(CURRENT_TIMESTAMP(), timestamp) < 14'}}, u'id': u'ava-backend:job_EowCD-kiOirnlyRAQjFJNFoRFUY', u'selfLink': u'https://www.googleapis.com/bigquery/v2/projects/ava-backend/jobs/job_EowCD-kiOirnlyRAQjFJNFoRFUY'}
The query works fine in Bigquery web interface and if run synchronously with 'query' instead of 'insert'
Could it possibly be an authentication issue? When I run the query with "query" it works but I get a warning message:
Checking for id_token.
id_token verification failed: Can't parse header: '\xc9\xad\xbd'
Checking for oauth token.
Client ID is not allowed: 173893847593-pdkumgr5bhobh3tv6qhqqfvel2tvnns0.apps.googleusercontent.com
URL being requested: https://www.googleapis.com/bigquery/v2/projects/ava-backend/queries?alt=json
The issue is with 'createDisposition': 'CREATE_NEVER'. This tells BigQuery that you never want to create a table for the query results. So it fails when the query result table doesn't exist. If you remove that create disposition, it should work.

Resources