常用存儲(chǔ)過程集錦,都是一些mssql常用的一些,大家可以根據(jù)需要選擇使用。
=================分頁==========================
/*分頁查找數(shù)據(jù)*/
CREATE PROCEDURE [dbo].[GetRecordSet]
@strSql varchar(8000),--查詢sql,如select * from [user]
@PageIndex int,--查詢當(dāng)頁號(hào)
@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 --得到總記錄數(shù)
select @PageCount=ceiling(1.0*@rowCount/@pagesize) --得到總頁數(shù)
,@currentPage=(@PageIndex-1)*@PageSize+1
select @RowCount,@PageCount
exec sp_cursorfetch @p1,16,@currentPage,@PageSize
exec sp_cursorclose @p1
set nocount off
GO
=========================用戶注冊(cè)============================
/*
用戶注冊(cè),也算是添加吧
*/
Create proc [dbo].[UserAdd]
(
@loginID nvarchar(50), --登錄賬號(hào)
@password nvarchar(50), --密碼
@email nvarchar(200) --電子信箱
)
as
declare @userID int --用戶編號(hào)
--登錄賬號(hào)已經(jīng)被注冊(cè)
if exists(select loginID from tableName where loginID = @loginID)
begin
return -1;
end
--郵箱已經(jīng)被注冊(cè)
else if exists(select email from tableName where email = @email)
begin
return -2;
end
--注冊(cè)成功
else
begin
select @userID = isnull(max(userID),100000)+1 from tableName
insert into tableName
(userID,loginID,[password],userName,linkNum,address,email,createTime,status)
values
(@userID,@loginID,@password,'','','',@email,getdate(),1)
return @userID
end
=================sql server系統(tǒng)存儲(chǔ)過程================
聯(lián)系客服