编写存储过程常用技巧汇总

来源:互联网 发布:windows键被锁定 编辑:程序博客网 时间:2024/05/29 15:17

 

 --      根据存储过程名取存储过程内容 

 --   调试 GetContentByProcedureName '[dbo].[CPP_CountOfTrdeByUserID]' 
 
alter   procedure  GetContentByProcedureName
 (
 @ProcedureName   nvarchar ( 500 ))
 
as  
 
 
if   exists  ( select   *   from  dbo.syscomments  where  id = object_id (N'' + @ProcedureName+ '' )) 
 
select  c. text , c.encrypted, c. number , xtype = convert ( nchar ( 2 ), o.xtype),    
  
 datalength (c. text ),  convert ( varbinary ( 8000 ), c. text ),  0   from  dbo.syscomments c, dbo.sysobjects o   
   
 where  o.id  =  c.id  and  c.id  =   object_id (N'' + @ProcedureName + '' 
 
order   by  c. number , c.colid  option (robust  plan )
存储过程总top+变量参数
Alter   proc  getWorkPlan2
 (
 
@intCounter   int 
 ,
 @lngUserID   int 
 )
 
as 
 
set   rowcount   @intCounter 
 
select   lngWorkID,strWorkName,strExecHumanName,strBeginDate
 
from  worklist  where  lngExecHumanID =   @lngUserID 
 
order   by  lngWorkID  desc  

 

原创粉丝点击