Query below returns error
SELECT 'mailto:'|| fscp.parameter_value || '?subject=' || wfn.subject nid_subject || chr(38)
FROM apps.wf_notifications wfn, apps.fnd_svc_comp_param_vals_v fscp
WHERE fscp.component_id = :component_id
AND component_parameter_id = :param
AND wfn.item_key = :itemkey;
Error
ORA-00923: FROM keyword not found where expected
00923.00000 - "FROM keyword not found where expected"
When I remove the '|| chr(38)' at the end of the select statement, the query runs fine.
Something related to joining tables? Because the below query also works fine:
select 'Text: '||chr(39)||wfn.notification_id||chr(39) from wf_notifications wfn;
You have this in the select:
|| wfn.subject nid_subject ||
Perhaps you intend:
SELECT 'mailto:'|| fscp.parameter_value || '?subject=' || wfn.subject || nid_subject || chr(38)
----------------------------------------------------------------------^
Alex is right. The key in the question is that it works without chr(38). So, try this:
SELECT ('mailto:'|| fscp.parameter_value || '?subject=' || wfn.subject || chr(38) ) as nid_subject
Notice the use of parentheses and as to make it clear that a column alias is being defined.
Related
So i have a query like this:
select
p.identifier,
GROUP_CONCAT(
'[' ||
'{"thumbnail":' ||
'"' ||
ifnull(s.thumbnail,'null') ||
'"' ||
',"title:' ||
'"' ||
s.title ||
'","content": [' ||
GROUP_CONCAT(
'{"text":' ||
ifnull(c.text,'null') ||
'", "image":' ||
ifnull(c.image,'null') ||
'", "caption": "' ||
ifnull(c.caption,'null') ||
'"},'
) ||
']},'
)
from pois as p
join stories as s on p.identifier = s.poiid
join content c on s.storyid = c.storyid
group by s.storyid
And i got and error:
in prepare, misuse of aggregate function GROUP_CONCAT()
To see clearly i have a big object named POIS every POI have multiple STORIES and every STORY have multiple CONTENTS, and i want to display x rows(how many pois i have) and inside the column have every story that is connected to their poi(and every content inside stories) and i need this in json format so i can parse the database query and read back into my object.
I hope its clear what is my problem and you can help me.
So i changed the query to something like this:
SELECT p.identifier, (
SELECT json_group_array(json_object('id', s.storyid))
FROM stories AS s
WHERE s.poiid=p.identifier
) as stories,
(
SELECT json_group_array(json_object('id', c.contentid, 'storyId', s.storyid))
FROM content AS c
JOIN stories AS s ON c.storyid=s.storyid
WHERE s.poiid=p.identifier
) as contents
FROM pois AS p
GROUP BY p.identifier
this is my result:
enter image description here
but the 3 rd column i would like to put inside the second(every pois have multiple stories and every story have one or multiple contents, so the contents should be inside their stories.
Any ideas on how to use spatial functions in either a procedure or a calculation view? I cannot use a table function, as I need a cursor. Please see issues below:
I tried dynamic SQL in a stored procedure with select into (Doesn't allow into):
(About three months back it did work, but now cannot activate?)
This blog says it should work:
https://blogs.sap.com/2017/04/18/sap-hana-2.0-sps-01-new-developer-features-database-development/
Dynamic SQL:
EXECUTE IMMEDIATE 'SELECT NEW ST_Point(' || char(39) || 'POINT(' || decEndPointLong1 || ' ' || decEndPointLat1 || ')' || char(39) || ', 4326).ST_Distance( NEW ST_Point(' || char(39) || 'POINT(' || CURRLONG || ' ' || CURRLAT || ')' || char(39) || ', 4326)) FROM DUMMY' INTO dDistEP1;
Then, I thought that I would create a calculation view,
This blog says it should work:
https://blogs.sap.com/2018/02/23/compute-distance-using-a-calculation-view-xs-advanced-model/
But, does not allow the use of spatial functions in ether columnengine or SQL engine.
Calculated Column:
I went back and tried to re-activate the procedure that contains this code and has been working, and still works, but if I edit it and try to activate it has the same compile error. Cannot select into variable. So, something has changed since I first created this procedure.
Wow, I stumbled upon an alternate syntax that does not need single quotes:
https://blogs.sap.com/2017/02/17/transforming-spatial-data-in-sap-hana/
SELECT NEW ST_Point(-117.0400842, 32.92197086).ST_SRID(4326).ST_Distance( NEW ST_Point(-117.0394467, 32.92241185).ST_SRID(4326)) FROM DUMMY
Now, I think that I can eliminate the Dynamic SQL.
Looking at the two differ ways:
1) SELECT NEW ST_Point(-117.0400842, 32.92197086).ST_SRID(4326).ST_Distance( NEW ST_Point(-117.0394467, 32.92241185).ST_SRID(4326)) FROM DUMMY;
2) SELECT NEW ST_Point('POINT(-117.0400842 32.92197086)', 4326).ST_Distance( NEW ST_Point('POINT(-117.0394467 32.92241185)', 4326)) FROM DUMMY;
They yield slightly different results (meters):
77.06
77.12
Probably, because (1) converts a calculated point to 4326, and (2) calculates the point based on 4326.
So, this code:
EXECUTE IMMEDIATE 'SELECT NEW ST_Point(' || char(39) || 'POINT(' || decEndPointLong1 || ' ' || decEndPointLat1 || ')' || char(39) || ', 4326).ST_Distance( NEW ST_Point(' || char(39) || 'POINT(' || CURRLONG || ' ' || CURRLAT || ')' || char(39) || ', 4326)) FROM DUMMY' INTO dDistEP1;
Boiled down to:
SELECT r1.FROMLAT INTO decEndPointLat1 FROM DUMMY;
SELECT r1.FROMLONG INTO decEndPointLong1 FROM DUMMY;
SELECT NEW ST_Point(decEndPointLong1, decEndPointLat1).ST_SRID(4326) INTO stEndCoord1 FROM DUMMY;
SELECT NEW ST_Point(CURRLONG, CURRLAT).ST_SRID(4326) INTO stCurrCoord FROM DUMMY;
SELECT stEndCoord1.ST_Distance(stCurrCoord) INTO dDistEP1 FROM DUMMY;
I'm using query in HANA Studio , It's work
CASE WHEN T0."U_XXX_SalEmp2" is not null THEN CONCAT
(T7."SlpName",CONCAT ('+',T0."U_XXX_SalEmp2")) ELSE T7."SlpName" END
AS"Sales Emp",
But I want to CONCAT more fields
**For Example :** CASE WHEN T0."U_XXX_SalEmp2" is not null THEN CONCAT (T7."SlpName",CONCAT ('+',T0."U_XXX_SalEmp2"),**CONCAT
('+',T0."U_XXX_SalEmp3"**),**CONCAT ('+',T0."U_XXX_SalEmp4"**)) ELSE
T7."SlpName" END AS"Sales Emp",
You can use the two pipe symbols || for chained concatenation.
Your example would look like this:
CASE
WHEN T0."U_ISS_SalEmp2" is not null
THEN
T7."SlpName" || '+' ||
T0."U_ISS_SalEmp2" || '+' ||
T0."U_ISS_SalEmp3" || '+' ||
T0."U_ISS_SalEmp4"
ELSE
T7."SlpName"
END AS "Sales Emp"
I've used REGEXP to find text patterns, but I'm having a problem with one part of it. I'd like to classify a ticketing fare calculation line as having only 1 of the following labels:
blank (there are no Q surcharges)
QCPN (there are only instance(s) of the existing format Q20.00)
QPRO (there are only instance(s) of the new additional format Q LONSYD20.00)
QBOTH (there are examples of both QCPN and QBOTH)
Below SQL:
SELECT JOUR.JOUR_FSERNR
AS TICKET,
CASE
WHEN REGEXP_LIKE (
JOUR.JOUR_FCA1LN
|| JOUR.JOUR_FCA2LN
|| JOUR.JOUR_FCA3LN
|| JOUR.JOUR_FCA4LN,
'Q[[:space:]][[:alpha:]]{6}')
THEN
'QPRO'
WHEN REGEXP_LIKE (
JOUR.JOUR_FCA1LN
|| JOUR.JOUR_FCA2LN
|| JOUR.JOUR_FCA3LN
|| JOUR.JOUR_FCA4LN,
'Q[[:digit:]]+\.[[:digit:]]+.*END')
THEN
'QCPN'
WHEN REGEXP_LIKE (
JOUR.JOUR_FCA1LN
|| JOUR.JOUR_FCA2LN
|| JOUR.JOUR_FCA3LN
|| JOUR.JOUR_FCA4LN,
'Q[[:space:]][[:alpha:]]{6}')
AND REGEXP_LIKE (
JOUR.JOUR_FCA1LN
|| JOUR.JOUR_FCA2LN
|| JOUR.JOUR_FCA3LN
|| JOUR.JOUR_FCA4LN,
'[[ALPHA]]{3}Q[[:digit:]]+\.[[:digit:]]')
THEN
'QBOTH'
ELSE
NULL
END
AS QTYPE,
( (JOUR.JOUR_FCA1LN || JOUR.JOUR_FCA2LN) || JOUR.JOUR_FCA3LN)
|| JOUR.JOUR_FCA4LN
AS FARECALC
FROM "S00BJOUR" JOUR
WHERE JOUR.JOUR_FSERNR = '9999889652'
If you look at the above SQL and find the CASE WHEN line that outputs 'QCPN', you'll see there's an "END" text string 'Q[[:digit:]][[:graph:]]END'. I put ‘END’ in there because I only want the REGEXP to look to the left of 'END' in a fare calc line.
But it gives me some incorrect outputs as shown in the attached image Incorrect Outputs in RED:
Any help to have this corrected is much appreciated.
It feels strange, you don't put so much quantifier. Like QCPN, whathever it means shoudld be :
Q[[:digit:]]{2}\.[[:digit:]]{2}
To match your Q20.00 example at least.
EDIT :
In your "with end exemple", didnt work because you dont put any quantifier :
Q[[:digit:]][[:graph:]]END
#Match Q5.END, Q22END, Q8AEND
#Dont match Q20.00 END
But :
Q[[:digit:]]+\.[[:digit:]]+.*END
#Match "Q1.2 ZA VD END Q20.2"
#Dont match "Q5.END", "BF END Q10.25"
For the second problem, QPRO/QBOTH, the probleme is :
Q HAMAOQ20.00
Try
[[:space:]]Q[[:digit:]]+\.[[:digit:]]+.
For QCPN regex.
I would like to do something like
SELECT * FROM (
SELECT ('reword#' || reword) || reword_faq as reword FROM me_review_entries re
) as re
WHERE re.reword = 'reword#2#SOME_FAQ'
I tried to do
SELECT ('reword#' || reword) || reword_faq as foo FROM me_review_entries re
WHERE foo = 'reword#2#SOME_FAQ'
But I get:
ERROR: column "foo" does not exist
LINE 2: WHERE foo = 'reword#2#SOME_FAQ'
Is the first way of doing the only way ? Or could I improve that ?
I think it depends on your database, but the foo column does not exist except within the query, so you might have to do:
SELECT ('reword#' || reword) || reword_faq as foo FROM me_review_entries re
WHERE ('reword#' || reword) || reword_faq = 'reword#2#SOME_FAQ'