Getting syntax error in #PROMPT Oracle SQL Developer? - sql

SAP Bo has generated a SQL query for a report which is not working in Oracle SQL Developer. I am getting 'missing expression' error.
Below is the code, please help me finding out the error here.
and also help me to understand the role of #PROMPT here.
SELECT
CASE
WHEN MATERIAL IN #PROMPT('Enter materials which may not be shipped to SIMS:','C',,Multi,Free,Persistent) OR material IN #PROMPT'Enter materials which may not be shipped to SIMS(2):','C',,Multi,Free,Persistent)
THEN 'Not SIMS'
WHEN
material IN #PROMPT('Enter materials which can be shipped to SIMS:','C',,Multi,Free,Persistent)
THEN 'SIMS'
END
FROM
Materials;
Expecting query should work as the same is working in SAP BO.

Try it like this:
SELECT
CASE
WHEN MATERIAL IN(&Enter_NON_ShippableMaterials_SIMS) OR MATERIAL IN(&Enter_NON_ShippableMaterials_SIMS_2) THEN 'Not SIMS'
WHEN MATERIAL IN(&Enter_SIMS_ShippableMaterials) THEN 'SIMS'
END "SIMS_OR_NOT"
FROM
You will be prompted to input data 3 times. If data are of type VarChar2 and you need to enter a list of data as input then do it within single quotes separated by comma - 'MAT_1', 'MAT_2', ....
Regards...

Related

Convert SQL to REGEX to Data Studio

I am new to working in Google Data Studio. I am trying to do a case when on some data but all I have is the SQL.
Here are the examples of what I am working with. I know this is not the best way to create this example. I normally use work with making queries so these examples are new to me.
CREATE TABLE #botdata(botstatus varchar(255))
insert into #botdata (botstatus)
values ('0|3900000:3900037:3900999:BOT-ANOMALY-HEADER|undefined|false')
insert into #botdata (botstatus)
values ('1|3900037|undefined|false')
insert into #botdata (botstatus)
values ('0|3900005:3900024|undefined|')
I am making the above into groups in SQL using a query but I need this same query to be formatted in Google Data Studio and I am not sure how
select case when botstatus like '1|%' OR (botstatus like '0|%' and botstatus like '%BOT-%') then 'BOT'
when botstatus like '0|%' then 'Regular Visit' else 'Regular Visit NO BOT STATUS' end as updatedbotstatus, botstatus
from #botdata
Having issues since the '|' and '-' are special charters in data studio.
Tried this but not getting the results I need.
CASE
WHEN REGEXP_MATCH( Bot Status(11) ,'0\\|*') and REGEXP_MATCH(Bot Status(11),'*BOT\\-*') then 'Bot'
ELSE 'Other'
END
Please test it out and lemme know if it needs any revision.
CASE WHEN REGEXP_CONTAINS(regex,'1\\|') OR (REGEXP_CONTAINS(regex,'0\\|') AND REGEXP_CONTAINS(regex,'BOT-')) THEN 'BOT' WHEN REGEXP_CONTAINS(regex,'0\\|') THEN 'REGULAR VISIT' END
-

SQL Sub-query parameters from Excel

I have SQL query with a sub-query where I want to assign sub query parameters from a cell in an Excel sheet, as this query cant be represented graphically Excel keep throwing error on this:
[Microsoft][ODBC SQL Server Driver] Invalid paramter number and
[Microsoft][ODBC SQL Server Driver] Invalid Descriptor Index
I have already tried solution as mentioned here to trick excel without success Using Parameters in SQL query with sub-query
;WITH dataset_bl as (
SELECT
--rank() over (partition by date_of_AC, ac_room order by into_theatre) as OrderNumber
--,datetime_of_AC as booking_datetime
date_of_AC
,AC_room
,specialty
,OAMRN
,substring(Subject_NAME,1,CHARINDEX(' ',Subject_NAME,1)) as 'surname'
,substring(Subject_NAME,CHARINDEX(' ',Subject_NAME,1)+2,500) as 'forename'
,convert(date,[dttm_of_birth],103) as DOB
,PRIN_SO as 'surg'
,'"'+ASST_SO_1+' '+ASST_SO_2+'"' as 'assistant_SO'
,substring(CONSULT_NAME,1,abs(CHARINDEX(',',CONSULT_NAME,1)-1)) as 'consult_surname'
,substring(CONSULT_NAME,CHARINDEX(' ',CONSULT_NAME,1)+1,500) as 'consult_first_name'
,'"'+actual_AC+'"' as AC_details
,'"'+PLANNED_PROD+'"' as booked_details
,'Carried Out' as 'TT_outcome'
, 'NULL' as 'unP_return_flag'
,OP_type
--,LOS
,case when CL_PRIORITY ='' then 'Not listed' else 'isted' end as islisted
,CLI_PRIORITY as listed_priority
,case when EM_PRIORITY like '<=%' then 'Submitted' else 'No Greensheet' end as isGreensheet
,em_priority as a, case when EM_PRIORITY like '<=%' and em_priority <> '<=72hrsCannot charge before prod'then LEFT(EM_PRIORITY, abs(charindex('-',EM_PRIORITY)-1))
when em_priority = '<=72hrsCannot diso before prod' then '<=72hrs' else 'NULL' end as em_priority
FROM sample.dbo.tb_Fnl_Sur_th4 WITH (NOLOCK)
**WHERE main_ident = 'A224' and convert(date,into_Start, 103) >= '2019-07-01' and convert(date,into_Start, 103) <= '2019-07-31'** --i am trying to get these parameters from excel cell value
)
SELECT * FROM dataset_bl
WHERE specialty like 'abc%'
or (consult_surname like '%abc%' and consult_first_name like '%def%' )
or surg in ('cde,fghi',
'jkl,'mnop,
'qrs,Tuv')
order by convert(date,date_of_procedure,103), operating_room--, into_theatre
Here's some suggestion.
First is to check the formatting of your date columns.
and build your parameter to be like
Cast(into_Start as smalldatetime) between ? and ?
I've been on that same issue and seem to find the solution for me. In fact the parameter [?] use in MSQUERY in Excel will normally work when you have a direct Query
Ex:
Select [YourTable].[Column]
From [YourTable]
Where [YourTable].[Column]= ?
The Excel parameter will prompt and trigger where the windows that ask you which cell or Data you want that parameter have to be filled with.
In the other hand if you use the a Subquery and you add a Where condition with the Parameter ? will be stuck with the parameter [Microsoft][ODBC SQL Server Driver] Invalid paramter number and [Microsoft][ODBC SQL Server Driver] Invalid Descriptor Index
If you download the ODBC Driver for SQL Server here -->
https://www.microsoft.com/fr-fr/download/details.aspx?id=56567
Install it and make sure that the ODBC use for your MSQUERY in Excel use that connection.
ODBC Data Source to use
After this I was able to use a MSQuery in Excel using Parameter like this one
Select [RenamedTable].*
From (Select [YourTable].[Column1],
[YourTable].[Column2],
[YourTable].[Column3]
From [YourTable]) as RenamedTable
Where [RenamedTable].[Column1] between ? and ?
Hope this will work for you as for me because I had similar problem with between date Parameter

Oracle query to XML using SSIS

I inherited a query that is used for extract information from Oracle Database and they want now to create a XML file using SSIS. So far I read several forum and blogs and I found a way to connect it but not sure how I should use this query. I found that Oracle use XMLElement to create the XML but I got
Unsupported Oracle data type USERDEFINED encountered. (System.Data.OracleClient)
when I tried to run the query. I will provide part of the original query, because it is quite large code
SELECT
--SCHED_STASK.SCHED_ID,
ACFT_INV.INV_NO_SDESC AS "Aircraft",
SCHED_STASK.BARCODE_SDESC AS "Barcode",
EVT_EVENT.ACTUAL_START_DT AS "Act_Start_Dt",
EVT_EVENT.EVENT_DT AS "Act_End_Dt",
TASK_TASK.TASK_ORIGINATOR_CD AS "Originator",
SCHED_STASK.TASK_CLASS_CD AS "Class",
SCHED_STASK.TASK_SUBCLASS_CD AS "SubClass",
EVT_EVENT.EVENT_STATUS_CD AS "Status",
CASE
WHEN TASK_TASK.TASK_CD is null THEN null
WHEN TASK_TASK.TASK_CD is not null THEN TASK_TASK.TASK_CD||' ('||TASK_TASK.TASK_NAME||')'
END AS "Task Defn",
ORG_HR.HR_CD AS "Employee number / ID",
SCHED_WORK_TYPE.WORK_TYPE_CD AS "Worktype",
EVT_STAGE.STAGE_DT AS "Signed Date"
......
and a huge bunch of left joins. then the where clause
So could someone guide me on how to solve this scenario I will more than happy, quite new using Oracle, I am more familiar with MS SQL + SSIS than Oracle + SSIS
If I understand you correctly you want xml output from oracle sql? try this!
with data as(SELECT
'Blériot' AS Aircraft,
1234 AS BARCODE,
DATE '2018-01-01' ACT_START_DT,
DATE '2018-02-01' ACT_END_DT,
'Louis' Originator,
'XI' Class,
'Civil tourer/trainer/military' SubClass,
'Obsolete but cool' Status,
CASE
WHEN 'Rebuild on mass' IS NULL THEN NULL
WHEN 'Rebuild on mass' IS NOT NULL THEN 'Rebuild on mass'||' ('||'Splinters in the sky'||')'
END "Task Defn",
666 AS "Employee number / ID",
'capentry and seamstressing' Worktype,
DATE '2018-02-01' "Signed Date"
from dual)
SELECT XMLELEMENT("Project",
(XMLELEMENT("Aircraft",AIRCRAFT)),
(XMLELEMENT("BARCODE",BARCODE)),
(XMLELEMENT("ACT_START_DT",ACT_START_DT)),
(XMLELEMENT("ACT_END_DT",ACT_END_DT)),
(XMLELEMENT("Originator",Originator)),
(XMLELEMENT("Class",Class)),
(XMLELEMENT("SubClass",SubClass)),
(XMLELEMENT("Status",Status)),
(XMLELEMENT("Task Defn","Task Defn")),
(XMLELEMENT("Employee number / ID","Employee number / ID")),
(XMLELEMENT("Worktype",Worktype)),
(XMLELEMENT("Signed Date","Signed Date"))
)
from data
the result beeing:
<Project>
<Aircraft>Blériot</Aircraft>
<BARCODE>1234</BARCODE>
<ACT_START_DT>2018-01-01</ACT_START_DT>
<ACT_END_DT>2018-02-01</ACT_END_DT>
<Originator>Louis</Originator>
<Class>XI</Class>
<SubClass>Civil tourer/trainer/military</SubClass>
<Status>Obsolete but cool</Status>
<Task Defn>Rebuild on mass (Splinters in the sky)</Task Defn>
<Employee number / ID>666</Employee number / ID>
<Worktype>capentry and seamstressing</Worktype>
<Signed Date>2018-02-01</Signed Date>
</Project>
For This particular case, I decided to use another ssis control that I downloaded, it seems that over here the settings used by the company didnt allow a good interaction between the oracle and the ms ssis.

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.

Error in list of function arguments: '=' not recognized. in VB.Net Query Wizard

SELECT
e.DESCRIPTION AS [EQUIPMENT TYPE],
Count(e.EQNAME) AS QUANTITY,
Sum(IIf(e.CONDITION = 'Functional', 1, 0)) AS WORKING,
Sum(IIf(e.CONDITION = 'Non-Functional', 1, 0)) AS [NON-WORKING]
FROM EQUIPMENTS AS e
GROUP BY e.DESCRIPTION;
I tried using this query in VB.net TableAdapter Query Configuration wizard and an error occurs.
Error in list of function arguments: '=' not recognized.
Unable to parse query text
Error in GROUP BY clause.
This Query works well in MS Access, what's the difference from it in VB.Net?
I already have a solution to this problem. I just used this query as a stored query in MS-Access then used in my VB.Net Code. Thank you guys.