CTE definition 2008

  • Hello every body,

    I have been facing this problem since long. I have a table student and I am defining a CTE on that using SQl server 2008 with following code:

    with cte_student(cte_ID,cte_name,cte_fees)

    AS

    (select ID,name,fees from student where fees>5000 group by ID)

    and it gives me followig error. I dont see any apparant reason behind it . may be some body can help.

    Kunaal

  • What error? You didn't post the error.

  • Oh yah I am sorry the error is " Msg 102, Level 15, State 1, Line 4

    Incorrect syntax near ')'."

    Kunal 🙂

  • Well, you actually have several problems. One, no select, insert, update, or delete using the CTE. Second, you have a group by query in the CTE with no aggregates.

    As an example, without correcting the second problem, you need something like this:

    with cte_student(cte_ID,cte_name,cte_fees)

    AS

    (select

    ID,

    name,

    fees

    from

    student

    where

    fees > 5000

    group by

    ID)

    select

    *

    from

    cte_student;

  • Thank you very much that worked for me...

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply