资讯   |   开发   |   选机中心   |   产品大全 | IBM | 惠普 | 联想 | 戴尔 | 苹果 | 神舟
更多: | 华硕 | 明基 | 方正 | 紫光 | TCL | 夏新 | 联宝 | 宏碁 | 七喜 | 长城 | 清华同方 | 海尔 | 三星 | 东芝 | 索尼 | 富士通 | LG | 技术 | ddnoon
当前位置:笔记本 > 软件开发 >
Advertisement
文章正文

这条语句怎么改写啊?

类型:转载   责任编辑:asp.net   日期:2007/05/23


热门软件下载:


   

参考:  
  http://community.csdn.net/Expert/topic/3453/3453921.xml?temp=.7766992  
   
  我想将表名传递过去:但是发现这么写不行啊  
  CREATE   PROC   MoveSortId  
  @SortId   int, --要处理的id --功能:动态的调整表中的排序编号  
  @Arrow   nvarchar(10)   ,       --移动方向,上表示上移,下表示下移  
  @Table     nvarchar(15)     --相关表名  
  as  
  declare   @nid   int  
   
  exec   (select   +@nid+=case   when   up=up   then   min(SortId)   else   max(SortId)   end   from     +   @Table)  
   
  --如果不可移动,则退出  
  if   @SortId=@nid   return  
  --取得移动后的新   SortId   值  
  set   @nid=@SortId+case   when   @Arrow=up   then   -1   else   1   end  
  --更新   SortId  
   
  exec   (update     +   @Table   +     set   SortId=case   when   SortId=   +   @SortId   +     then     +   @nid   +     else     +   @SortId   +     end  
  where   SortId   in(   +   @SortId   +   ,   +   @nid   +   ))  
  GO  
   
   
  问题出在  
  exec   (select   +@nid+=case   when   up=up   then   min(SortId)   else   max(SortId)   end   from     +   @Table)  
   
  这句里面需要返回+@nid,但是这么执行总报错阿

网友回答:

发表者:zjcxc

 
  --存储过程  
  create   proc   p_move  
  @SortId   int, --要处理的id  
  @方向   char(1)=下, --移动方向,上表示上移,下表示下移  
  @Table   nvarchar(15)     --相关表名  
  as  
  declare   @s   nvarchar(4000)  
  set   @s=  
  declare   @nid   int  
  select   @nid=+case   when   @方向=上   then   min(SortId)   else   max(SortId)   end  
  +from   [+@Table+]  
   
  --如果不可移动,则退出  
  if   @SortId=@nid   return  
   
  --取得移动后的新   SortId   值  
  set   @nid=@SortId++case   when   @方向=上   then   -1   else   1   end  
  +  
  --更新   SortId  
  update   [+@Table+]   set   SortId=case   when   SortId=@SortId   then   @nid   else   @SortId   end  
  where   SortId   in(@SortId,@nid)  
  exec   sp_executesql   @s,N@SortId   int,@SortId  
  go  
 


 

 
热门推荐笔记本: 戴尔笔记本
相关文章:
笔记本相关:
IT技术文章:
webmaster:popbb@126.com   最佳浏览:1024X768 MSIE
©2007 popbb.net All Rights Reserved