SQL Syntax Error - sql

I'm getting an incorrect syntax error when I try to execute this query in t-sql. I'd appreciate any help - I believe the issue is on, or around the ROUND statement.
SELECT
EMPL.employeeid as KEmplID,
EMPL.PERSONNUM as EmployeeNumber,
EMPL.PERSONFULLNAME as FullName,
....
FROM
VP_EMPLOYEE as EMPL,
VP_PERSON as PRSN,
(
SELECT
TLS.employeeid as EMPLID,
TLS.applydate as APPLYDATE,
ROUND((SUM(CONVERT(FLOAT,TLS.timeinseconds)) /60/60,1)) AS ElapsedHrs
FROM
VP_TOTALS as TLS,
VP_PAYCODE as PAYCODE
....
I am just not quite sure where my issue stems - again, I think it is the round statement but I could be wrong. I will appreciate any and all help - or suggestions - to make this more efficient or help with the rounding, conversion and sum of the data.

Incorrect:
ROUND((SUM(CONVERT(FLOAT,TLS.timeinseconds)) /60/60,1)) AS ElapsedHrs
Corrected (parenthesis placement):
ROUND((SUM(CONVERT(FLOAT,TLS.timeinseconds)) /60/60),1) AS ElapsedHrs
^

Related

PostgreSQL 10 Rowtype Bug in Function?

I declare inside a function the following:
SEL_USER APP.USER % ROWTYPE;
Then i made the select
Working perfectly:
SELECT *
INTO SEL_USER
FROM APP.USER
WHERE ...
But this isn't working and i don't know the reason.
Maybe a postgresql bug?
SELECT USER_ID, OFFICE_FK, LOCKER, EMAIL, FULL_NAME, SURNAME1
SURNAME2, SOCIAL_CARD, BIRTHDATE, PREFERENCES
INTO SEL_USER
FROM APP.USER
WHERE ...
To clarify:
Where statement are the same and it works.
There is no error of fields because if I do the select without the into it works.
what happened?
It's changing the fields, example:
locker_id is assigned the value of social_card (I verify that the values ​​are where they should go)
some fields are null (which is not possible because they are declared as not null)
Is it a postgresql 10 bug or am I doing something wrong?
In case I'm doing something bad I would appreciate it if you would help me.
(forgive my english)
Sincerely I do not know why it only gave me problems in that function,
maybe it was some context problem, because in others it did not matter the order or if any column was missing.
Fix it by putting in order and using 'as'
SELECT U.USER_ID, U.OFFICE_FK, U.LOCKER, U.SOCIAL_CARD, U.EMAIL,
U.FULL_NAME, U.SURNAME1, U.SURNAME2, U.BIRTHDATE, U.PREFERENCES
INTO SEL_USER
FROM APP.USER AS U
WHERE ...;
Thanks for your time :)

U-sql error: Expected one of: AS EXCEPT FROM GROUP HAVING INTERSECT OPTION ORDER OUTER UNION UNION WHERE ';' ')' ','

I have a following table:
EstimatedCurrentRevenue -- Revenue column value of yesterday
EstimatedPreviousRevenue --- Revenue column value of current day
crmId
OwnerId
PercentageChange.
I am querying two snapshots of the similarly structured data in Azure data lake and trying to query the percentage change in Revenue.
Following is my query i am trying to join on OpportunityId to get the difference between the revenue values:
#opportunityRevenueData = SELECT (((opty.EstimatedCurrentRevenue - optyPrevious.EstimatedPreviousRevenue)*100)/opty.EstimatedCurrentRevenue) AS PercentageRevenueChange, optyPrevious.EstimatedPreviousRevenue,
opty.EstimatedCurrentRevenue, opty.crmId, opty.OwnerId From #opportunityCurrentData AS opty JOIN #opportunityPreviousData AS optyPrevious on opty.OpportunityId == optyPrevious.OpportunityId;
But i get the following error:
E_CSC_USER_SYNTAXERROR: syntax error. Expected one of: AS EXCEPT FROM
GROUP HAVING INTERSECT OPTION ORDER OUTER UNION UNION WHERE ';' ')'
','
at token 'From', line 40
near the ###:
This expression is having the problem i know but not sure how to fix it.
(((opty.EstimatedCurrentRevenue - optyPrevious.EstimatedPreviousRevenue)*100)/opty.EstimatedCurrentRevenue)
Please help, i am completely new to U-sql
U-SQL is case-sensitive (as per here) with all SQL reserved words in UPPER CASE. So you should capitalise the FROM and ON keywords in your statement, like this:
#opportunityRevenueData =
SELECT (((opty.EstimatedCurrentRevenue - optyPrevious.EstimatedPreviousRevenue) * 100) / opty.EstimatedCurrentRevenue) AS PercentageRevenueChange,
optyPrevious.EstimatedPreviousRevenue,
opty.EstimatedCurrentRevenue,
opty.crmId,
opty.OwnerId
FROM #opportunityCurrentData AS opty
JOIN
#opportunityPreviousData AS optyPrevious
ON opty.OpportunityId == optyPrevious.OpportunityId;
Also, if you are completely new to U-SQL, you should consider working through some tutorials to establish the basics of the language, including case-sensitivity. Start at http://usql.io/.
This same crazy sounding error message can occur for (almost?) any USQL syntax error. The answer above was clearly correct for the provided code.
However since many folks will probably get to this page from a search for 'AS EXCEPT FROM GROUP HAVING INTERSECT OPTION ORDER OUTER UNION UNION WHERE', I'd say the best advice to handle these is look closely at the snippet of your code that the error message has marked with '###'.
For example I got to this page upon getting a syntax error for a long query and it turned out I didn't have a casing issue, but just a malformed query with parens around the wrong thing. Once I looked more closely at where in the snippet the ### symbol was, the error became clear.

TOAD 10.6 Sql Error ORA - 01858: What is wrong with query?

Please help me identify the below issue. I have a canned query below and can't get it to run without getting this error:
SELECT * FROM TABLE(fdr_dal_txns.get_txn_trans_adjst_consol
(short_string_col('1BFV')
,'POST_DT'
,short_string_col('MCH','GP3', 'OTC')
,'01-may-2017'
,'30-june-2017'
))
WHERE trd_id_num IN ('17FHKBBSSML',
'17FHVBBRJD8')
What is obvious, is that you seem to be passing strings ('01-may-2017' is a string) where you should have passed dates. I'd suggest you to use date literals, such as
SELECT *
FROM TABLE (fdr_dal_txns.get_txn_trans_adjst_consol (
short_string_col ('1BFV'),
'POST_DT',
short_string_col ('MCH', 'GP3', 'OTC'),
DATE '2017-05-01', --'01-may-2017',
DATE '2017-06-30' --'30-june-2017'
))
WHERE trd_id_num IN ('17FHKBBSSML', '17FHVBBRJD8')
and see what happens. If it still doesn't help, you should provide much more details of what you're doing (because you told us close to nothing so far).

SQL Hive subquery error

I have the query below
set hive.cli.print.header=true;
set hive.query.max.partition=1000;
set hive.mapred.mode=unstrict;
SELECT
dim_lookup("accounts",name,"account_id") = '28016' as company,
dim_lookup("campaigns",name,"campaign_id") in (117649,112311,112319,112313,107799,110743,112559,112557,105191,105231,107377,108675,106587,107325,110671,107329,107181,106565,105123,106569,106579,110835,105127,105243,107185,105211,105215) as campaign_name,
case when is_click_through=0 then "PV" else "PC" end as conv_type,
(SELECT COUNT(1) FROM impressions WHERE ad_info[2] in (117649,112311,112319,112313,107799,110743,112559,112557,105191,105231,107377,108675,106587,107325,110671,107329,107181,106565,105123,106569,106579,110835,105127,105243,107185,105211,105215)) AS impressions
FROM actions
WHERE
data_date>='20170101'
AND data_date<='20171231'
AND conversion_action_id in (20769223,20769214,20769219,20764929,20764932,20764935,20769215,20769216,20764919,20769218,20769217,20769220,20769222)
GROUP BY conv_type
When I execute it I get an error
ERROR ql.Driver: FAILED: ParseException line 8:1 cannot recognize input near 'SELECT' 'COUNT' '(' in expression specification
I am trying to fetch each count of impression for a specified conversion_action_id. What could be the error in my query? Thanks for the help.
FYI: ad_info[2] and campaign_id are the same.
The problem is quite clear, you have a subquery inside your SELECT.
That is not how this works.
Unfortunately the exact solution is not that clear, as it I am not completely sure what you want, but here is some general advice:
Write your subquery, test it and make sure it is ok
Rather than putting it in your SELECT part, put it in your FROM part, and (as always) SELECt from the FROM
Just think of your subquery output as an other table that can be used in the from statement, and which needs to be combined (JOIN, UNION?) with other tables in the from statement.

Getting this error - ORA-00936: missing expression

I am new to SQL and trying to use an if statement equivalent in order to get the value in SQL.
After running this report I am getting the error "ORA-00936: missing expression"
CASE WHEN (select Sum(MONTANT) from fraisExterne where matching=fm.id and statut=3) IS NULL
THEN select sum(MONTANT) from fraisExterne where matching=fm.id
ELSE Select sum (MONTANTHTBROKER) from fraismatching where matching=fm.id
End End as "BROKER AMOUNT"
Please let us know if you can help me with it
You have a extra END key word at the end of your case statement. You also need to put your select query into ().
Try this:
SELECT
CASE
WHEN (select Sum(MONTANT) from fraisExterne where matching=fm.id and statut=3) IS NULL THEN (select sum(MONTANT) from fraisExterne where matching=fm.id)
ELSE (Select sum (MONTANTHTBROKER) from fraismatching where matching=fm.id)
End AS BROKER_AMOUNT
I hope this helps and welcome to StackOverflow. If you find this answer or any other answer solves your problem please mark it as the solution. This will help the community and fellow programmers who run into the same problem in the future. Thanks.