with as 前面加if 怎么写啊?
例如
 if (select count(*) from t_eng_partno where ver=@ver and pno=@pno)>0 
with cte
as
总报错。

解决方案 »

  1.   

    不可以啊。加了分号提示 Incorrect syntax near ';'.
    不加; 提示Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.
      

  2.   


    if (select count(*) from t_eng_partno where ver=@ver and pno=@pno)>0  
    begin
    with cte
    as
    end
      

  3.   

    没得写,除非
    if (select count(*) from t_eng_partno where ver=@ver and pno=@pno)>0  
    exec('with cte as
    ...')
      

  4.   

     if (select count(*) from t_eng_partno where ver=@ver and pno=@pno)>0 
    begin
    ;with cte
    as
    ()
    SELEC * FROM CTE
    END
      

  5.   

    哦,理解错误,以为是
    if
    with cte
    ..
    else
    with cte
    ..
    select * from cte
      

  6.   

    if(select count(*) from a)>0
    begin
    ;with cte 
    as
    (
    select * from a
    )
    select * from cte
    enduserid     USERname
    ---------- ----------
    1          aa
    2          bb
    3          cc(3 row(s) affected)