Sql using With Clause

Raj0125 511 Reputation points
2022-07-12T08:24:29.107+00:00

Hi

I am writing below using With clause but i am getting error "Incorrect syntax near RNum"

WITH CTE AS
(SELECT *,DENSE_RANK()OVER(ORDER BY L_key DESC)) as RNum
FROM DBO.Rep_Def_TMP

Please suggest.

Thanks

Azure SQL Database
0 comments No comments
{count} votes

Accepted answer
  1. Olaf Helper 47,436 Reputation points
    2022-07-12T08:37:28.78+00:00

    Your SQL statement is wrong. A WITH clause must start with a semicolon. And a WITH is a kind on inline view, which you use/query later in the SQL statement like here SELECT * FROM CTE:

    ;WITH CTE AS  
       (SELECT *, DENSE_RANK() OVER(ORDER BY L_key DESC) as RNum  
        FROM DBO.Rep_Def_TMP)  
    SELECT *  
    FROM CTE  
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.