我写了这样的语句
set @value=(select top @count-@index+1 bdamount from bomdetail where bmid=@product and mciid not in (select top @count-@index mciid from bomdetail where bmid=@product))
 --保留路径的分叉点的数据环境
那些变量我都声明过  且都赋了值 但是同不过语法检查   为什么呢?

解决方案 »

  1.   

    不能这样写,2000不支持这样的写法,top的数量要是常量
      

  2.   

    是,这样是不符合SQL的语法的,
    首先是不可以用表达式@count-@index+1 ,必须是一个数字如果top 后面是变量,必须用动态SQL语句
      

  3.   

    TOP只支持常量可以用动态SQL来拼接
      

  4.   

    恩  好了 
    现在我是这样写了
    declare  strsql varchar(2000)
    declare  @value varchar(100)
    set @strsql="select top " +str(@count-@index+1) +" bdamount from bomdetail where bmid=" + @product +" and mciid not in (select top " + str(@count-@index)+" mciid from bomdetail where bmid=" +@product +"))"
    下面我想把检索出的 那一条bdamount数据 赋值给另一个变量@value 怎么办呢?
    我市这样写的, 但是有语法错误 ?
     set @value=exec (@strsql)