syntax error on if block in sap hana studio - sap

i am writing a simple sql having an if block in it. the sql editor throws syntax error at the if block where as i checked the syntax and it seems to be correct to me. Below is code snippet of the query.
select
t4.OWNED,
if( isnull(
if(t4.OWNED='',
'01',
t4.OWNED)),
'01',
if(t4.OWNED='',
'01',
t4.OWNED) ) OWNERSHIP
from table t4
can anyone please suggest if there is issue with the syntax.... thanks for your help.

your sintax is wrong, i understand you want a result like this
select t4.OWNED, ifnull(t4.OWNED, '01'), ifnull(t4.OWNED, '01'), ifnull(t4.OWNED, '01') OWNERSHIP from table t4

Related

SQL ODBC Sybase TO_DATE Procedure not provided

I have a task to finish in SQL, and am not very familiar with the language. The normal resource I would use is sick currently, so I'm asking for help here instead. I'm running the following query on Sybase:
SELECT WgArt, SrtNr, Datum, WNetto
FROM M01.Wgs
WHERE (WgArt <> 'f') AND (SrtNr = '170904-01') AND
(Datum BETWEEN to_date('09.02.2017','dd.mm.yyyy') AND
to_date('09.02.2017','dd.mm.yyyy')
) OR
(SrtNr = '170904-02') OR
(SrtNr = '170904-05') OR
(SrtNr = '170904-07') OR
(SrtNr = '150106-03')
The error message I'm receiving is: "Procedure 'to_date' is not found".
Error msg 42S02
I googled and found some workaround articles with CAST/Convert, but also getting same error. Any idea would be welcome.
I would use IN clause rather that strange OR clause :
SELECT WgArt, SrtNr, Datum, WNetto
FROM M01.Wgs
WHERE (WgArt <> 'f') AND
(Datum BETWEEN to_date('09.02.2017','dd.mm.yyyy') AND
to_date('09.02.2017','dd.mm.yyyy')
) AND (SrtNr IN ('170904-01', '170904-02', '170904-05', '170904-07', '150106-03')
);
Assuming your product is Sybase (now SAP) SQLAnywhere, there is no to_date() function.
Here's a list of date-related functions supported by SQLAnywhere.
Of specific interest might be the date(), datetime() and/or dateformat() functions ... ?

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).

Microsoft SQL Server Error 102

I am executing below query and it gives me
SELECT
t1.s_reference "Section",
t2.m_reference "CourseRef",
t2.m_name "CourseName",
t3.mi_q02m02 "Aim",
t2.m_level "Level",
t2.m_start "Start",
t2.m_end "End",
t2.m_projstudents "Target",
COUNT(DISTINCT t4.e_id) "Enrolled"
FROM
isr t3,
person t5,
department t6,
section t1,
enrolment t4,
course t2
WHERE
t3.mi_id(+)=t2.m_id
AND t4.e_module=t2.m_id
AND t4.e_student=t5.p_id
AND(t2.m_status LIKE '%%'||SUBSTR((TO_CHAR(sysdate,'YYYY')+DECODE(least(to_number(TO_CHAR(sysdate,'mm')),8),8,0,-1)),-2,2) ||'%%')
AND t2.m_reference LIKE 'LL%%'
AND t4.e_status IN('C','S')
AND to_date(t2.m_start,'DD-Mon-RRRR')<=to_date(sysdate,'DD-Mon-RRRR')
AND to_date(t2.m_end,'DD-Mon-RRRR')>=to_date(sysdate,'DD-Mon-RRRR')
AND t2.m_modulesection=t1.s_id
AND t2.m_moduledept=t6.d_id
AND NVL(t2.m_close,0)=0
AND t3.mi_q02m02 IS NOT NULL
AND((
CASE
WHEN((t1.s_reference='LL2a')
AND(t2.m_reference LIKE '%W%'))
THEN 1
ELSE 0
END)=0)
AND(t2.m_reference!='LL3036E15')
GROUP BY
t1.s_reference,
t2.m_reference,
t2.m_name,
t3.mi_q02m02,
t2.m_level,
t2.m_start,
t2.m_end,
t2.m_projstudents,
t1.s_reference,
t2.m_reference
ORDER BY
t1.s_reference,
t2.m_reference
An error occurred while executing the query.
Incorrect syntax near ')'. MS SQL Server Error 102
I ran the same query in SQL Developer and it runs fine.
I tried to remove most of the parenthesis but still doesn't help.
Any idea why this happens?
Thanks
Aruna
You are trying to run a query written for Oracle in Microsoft's SQL Server. These products use a slightly different dialect of SQL, which are incompatible. For example, DECODE, NVL, TO_CHAR are not available in SQL Server. You'll have to re-write the query using SQL Server functions to replace the Oracle specific ones (CASE, COALESCE, CONVERT for the ones I mentioned).
1st step... replace all || to the word OR
2nd step
AND(t2.m_status LIKE
'%%'||SUBSTR((TO_CHAR(sysdate,'YYYY')+DECODE(least(to_number(TO_CHAR(sysdate,'mm')),8),8,0,-1)),-2,2)
||'%%')
where
||'%%')
is not a qualified condition and may be irrelevant since you already used it
3rd
t3.mi_id(+)=t2.m_id
you have to re-write this
4th
%%
should only be %

SQL Syntax Error

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
^

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.