[code=SQL][
declare @i int default 0;
/code]
这样为什么会报错?说是default附近有语法错误

解决方案 »

  1.   


    --sql2008
    declare @i int=0
      

  2.   

    不能用default 吗?  mysql 和 oracle 都是这样用的
      

  3.   

    mssql里变量不用default,直接赋值,字段可赋默认值
      

  4.   

    嗯、谢谢啊、顺便问下 游标里如果没有值、怎么控制下让它关闭?DECLARE  cur_plan_detail cursor for 
    select 
    c.question_no_b,c.point_per, c.difficult_y,c.difficult_z,c.difficult_n,c.type 
    from t_test_plan a,t_test_paper_question_b c 
    where  a.id = c.plan_id
    and a.id = p_plan_id
    order by question_no_b 
      

  5.   

    open cur_plan_detail
    if @@FETCH_STATUS <>0
    close cur_plan_detail
      

  6.   

    检查@@fetch_status = 0 完整示例
    declare cur_temp cursor local for
    select aa
    from bb
    where .....
    open cur_temp
    Fetch next from cur_temp  into @aa
    while @@fetch_status = 0 
    begin
    数据处理.....
    Fetch next from cur_temp into @aa
    end
    close cur_temp
    Deallocate cur_temp
      

  7.   


    DECLARE  cur_plan_detail cursor for 
    select 
    c.question_no_b,c.point_per, c.difficult_y,c.difficult_z,c.difficult_n,c.type 
    from t_test_plan a,t_test_paper_question_b c 
    where  a.id = c.plan_id
    and a.id = p_plan_id
    order by question_no_b 
    fetch next...
    while @@FETCH_STATUS=0
    begin
        ...
        fetch next...
    end
    --游标大致这个格式循环,不过能不用游标最好别用!貌似这是军令,PS你儿子好可爱