on CTE

  • IS there any Possibility to use if on cte

    like

    with mycte(id,name,status)

    as

    (

    select id,e_name,status from emp

    )

    if id=10

    select * from mycte

    it's getting error pls help

  • Not that I know. I assume your real statement is much more complex, if not, add "where id=10" 🙂

    My wish is to use CTE as a cursor replacement, but this is not possible:

    with processlist(tablename, status) as

    (

    select tablename, status

    from batchlist

    where lastdate > getdate() -1

    )

    begin

    (your fancy code here)

    end

    Maybe something for SQL2010? 😉

    Wilfred
    The best things in life are the simple things

  • venki_1276 (10/3/2008)


    IS there any Possibility to use if on cte

    like

    with mycte(id,name,status)

    as

    (

    select id,e_name,status from emp

    )

    if id=10

    select * from mycte

    it's getting error pls help

    Only way is

    with mycte(id,name,status)

    as

    (

    select id,e_name,status from emp

    )

    select * from mycte where id=10


    Madhivanan

    Failing to plan is Planning to fail

  • venki_1276 (10/3/2008)


    IS there any Possibility to use if on cte

    Sure:

    IF id=10

    BEGIN

    with mycte(id,name,status)

    as

    (

    select id,e_name,status from emp

    )

    select * from mycte

    END

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

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

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