SQL Server 常用存储过程集锦
2022-11-12 09:54:11
内容摘要
这篇文章主要为大家详细介绍了SQL Server 常用存储过程集锦,具有一定的参考价值,可以用来参考一下。
对此感兴趣的朋友,看看idc笔记做的技术笔记!=================分页=======
文章正文
这篇文章主要为大家详细介绍了SQL Server 常用存储过程集锦,具有一定的参考价值,可以用来参考一下。
对此感兴趣的朋友,看看idc笔记做的技术笔记!
=================分页==========================代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <code> /*分页查找数据*/ CREATE PROCEDURE [dbo].[GetRecordSet] @strSql varchar(8000),--查询sql,如select * from [user] @PageIndex int,--查询当页号 @PageSize int--每页显示记录 AS set nocount on declare @p1 int declare @currentPage int set @currentPage = 0 declare @RowCount int set @RowCount = 0 declare @PageCount int set @PageCount = 0 exec sp_cursoropen @p1 output,@strSql,@scrollopt=1,@ccopt=1,@rowcount=@rowCount output --得到总记录数 select @PageCount=ceiling(1.0*@rowCount/@pagesize) --得到总页数 ,@currentPage=(@PageIndex-1)*@PageSize+1 select @RowCount,@PageCount exec sp_cursorfetch @p1,16,@currentPage,@PageSize exec sp_cursorclose @p1 set nocount off GO </code> |
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | <code> SQL code create proc killspid (@dbname varchar(20)) as begin declare @sql nvarchar(500) declare @spid int set @sql=' declare getspid cursor for select spid from sysprocesses where dbid=db_id( '' '+@dbname+' '' )' exec (@sql) open getspid fetch next from getspid into @spid while @@fetch_status <>-1 begin exec ( 'kill ' +@spid) fetch next from getspid into @spid end close getspid deallocate getspid end GO </code> |
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | <code> SQL code CREATE FUNCTION fun_cgnum (@num INT) RETURNS VARCHAR(100) AS BEGIN DECLARE @temp INT,@res INT,@i TINYINT DECLARE @str VARCHAR(100),@no VARCHAR(20),@unit VARCHAR(16) SELECT @str= '' ,@no= '另壹贰叁肆伍陆柒捌玖' ,@unit= '拾佰仟万拾佰仟亿' SET @temp=@num SELECT @i=0,@res=@temp%10,@temp=@temp/10 WHILE @temp>0 BEGIN IF @i=0 SET @str=SUBSTRING(@no,@res+1,1) ELSE SET @str=SUBSTRING(@no,@res+1,1)+SUBSTRING(@unit,@i,1)+@str SELECT @res=@temp%10,@temp=@temp/10 SET @i=@i+1 END SET @str=SUBSTRING(@no,@res+1,1)+SUBSTRING(@unit,@i,1)+@str SET @str=REPLACE(@str, '另拾' , '另' ) SET @str=REPLACE(@str, '另佰' , '另' ) SET @str=REPLACE(@str, '另仟' , '另' ) SET @str=REPLACE(@str, '另拾' , '另' ) SET @str=REPLACE(@str, '另万' , '万' ) WHILE @i>0 BEGIN SET @str=REPLACE(@str, '另另' , '另' ) SET @i=CHARINDEX( '另另' ,@str) END SET @str=REPLACE(@str, '另万' , '万' ) SET @str=REPLACE(@str, '亿万' , '亿' ) IF RIGHT(@str,1)= '另' SET @str=LEFT(@str,LEN(@str)-1) RETURN @str END GO </code> |
注:关于SQL Server 常用存储过程集锦的内容就先介绍到这里,更多相关文章的可以留意
代码注释