Hi
I n below code i am getting error on - ROW_NUMBER() OVER (PARTITION BY T0."DocNum" ORDER BY (SELECT NULL)) AS RowNum
WITH RankedData AS (
SELECT
(T0."DocNum") As "Invoice No",T1."Quantity",T0."DocTotal",
ROW_NUMBER() OVER (PARTITION BY T0."DocNum" ORDER BY (SELECT NULL)) AS RowNum
FROM OINV T0
Inner Join INV1 T1 on T0."DocEntry" = T1."DocEntry"
)
Select * from RankedData
;
Thanks
Jignesh KumarPosted Mar 3, 2025, 3:26 AM
Hello Ramco,
Your orderBr clause is wrong, Please do correction as below in you query to ger desire out put,
In your Query : ORDER BY (SELECT NULL) throwing error.
Prasad RaveendranPosted Mar 3, 2025, 1:21 AM
The issue is with the
ORDER BY (SELECT NULL), which is not allowed in theROW_NUMBER()function. TheORDER BYclause must have a valid column for ordering the rows.Please try this
Muhammad Imran AnsariPosted Mar 1, 2025, 3:50 PM
Hello Ramco,
The error occurs because
ORDER BY (SELECT NULL)is not a valid syntax in ROW_NUMBER(). TheORDER BYclause inROW_NUMBER()requires a deterministic column to define the order in which rows are assigned row numbers.Modify the query to use a valid column for ordering. If there is no meaningful column to order by, you can use
T1."DocEntry"or any other unique column. Here is an updated query:There is an alternative approach, if you truly don't have a column for ordering and just need an arbitrary order, you can use:
OR
Good Luck!
Ramco RamcoPosted Mar 1, 2025, 9:43 AM
Hi
It is giving error - Constants are not allowed on order by clause of windows functions.
Thanks
Sophia CarterPosted Mar 1, 2025, 9:33 AM
The syntax error near ")" in your SQL query is due to the usage of (SELECT NULL) within the ORDER BY clause of the ROW_NUMBER() function. The ORDER BY clause in the ROW_NUMBER() function requires an actual column or expression based on which the ordering will be performed. Using (SELECT NULL) doesn't provide a valid ordering criterion.
To correct this error, you should replace (SELECT NULL) with a valid column or expression that determines the order in which ROW_NUMBER() should assign the row numbers. If you want an arbitrary row number without any specific order, you can use a constant value like 1.
Here's the corrected version of your SQL query:
In this corrected query, I replaced (SELECT NULL) with 1 in the ORDER BY clause after ROW_NUMBER(), which will assign row numbers in an arbitrary order.
Feel free to test this corrected query in your environment, and it should resolve the syntax error near ")". If you have any more questions or need further clarification, feel free to ask!