SQLSERVER 일반 페이지 나누기 스토리지 프로세스

29818 단어 sqlserver

 
공통 페이지 저장 프로세스 호출
.src_container{background-color:#e7e5dc; width:99%; overflow:hidden; margin:12px 0 12px 0 !important; padding:0px 3px 3px 0px}
.src_container .titlebar{ background-color:#d4dfff; border:1px solid #4f81bd; border-bottom:0; padding:3px 24px; margin:0; width:auto; line-height:120%; overflow:hidden; text-align:left; font-size:12px}
.src_container .toolbar{ display:inline; font-weight:normal; font-size:100%; float:right; cursor:hand; color:#00f; text-align:left; overflow:hidden}
.toolbar span.button{ display:inline; font-weight:normal; font-size:100%; cursor:hand; color:#00f; text-align:left; overflow:hidden; cursor:pointer;}
.src_container div.clientarea{ background-color:white; border:1px solid #4f81bd; margin:0; width:auto !important; width:100%; height:auto; overflow:auto; text-align:left; font-size:12px; font-family: "Courier New","Consolas","Fixedsys",courier,monospace,serif}
.src_container ol.mainarea{ padding:0 0 0 52px; margin:0; background-color:#f7f7ff !important}
.number_show{ padding-left:52px !important; list-style:decimal outside !important}
.number_show li{ list-style:decimal outside !important; border-left:1px dotted #4f81bd}
.number_hide{ padding-left:0px !important; list-style-type:none !important}
.number_hide li{ list-style-type:none !important; border-left:0px}
ol.mainarea li{ display:list-item !important; font-size:12px !important; margin:0 !important; line-height:18px !important; padding:0 0 0 0px !important; background-color:#f7f7ff !important; color:#4f81bd}
ol.mainarea li pre{color:black; line-height:18px; padding:0 0 0 12px !important; margin:0em; background-color:#fff !important}
.linewrap ol.mainarea li pre{white-space:pre-wrap; white-space:-moz-pre-wrapwhite-space:-pre-wrap; white-space:-o-pre-wrap; word-wrap:break-word}
ol.mainarea li pre.alt{ background-color:#f7f7ff !important}
function CopyCode(key){var codeElement=null;var trElements=document.all.tags("ol");var i;for(i=0;i<trelements.length;++i){if(key.parentelement.parentelement.parentelement==trelements[i].parentelement.parentelement){codeelement=trelements[i];break}}if(codeelement!=null){var content="codeElement.innerText;if(window.clipboardData==null){window.alert("브라우저에서 스크립트 복사를 지원하지 않습니다. 수동으로 복사해 보십시오.')} else {window.clipboard Data.set Data('Text', content), window.alert('소스 코드는 클립보드에 복사됐다.')}}}function'LineNumberVisible(key) {var codelement ='null; var'trlements ='document'val.all.tags('ol'), var'var'i'), for(i=') for(i======'0; i< i&trtrtrtrements.lenglents.lents;;;;;, lengnglents++++++ belement. Element. E=trElements[i].parentElement.parentElement) {codeElement=trElements[i];break}}if(codeElement!=null){if(코드 Element.class Name ='mainarea'number hide') {code Element. classname ='mainarea numbe show'; 키. innertext ='숨겨진 줄 번호'}else {code Element. classname ='mainarea number hide'; 키. innertext = '는 줄 번호';;;'key. innertext =' 는'key = '는'key. innertext = =' 는 줄 번호'key. innertext = = '는 줄 번호'}}} function function ChangeIcon(color='blue'}function CopyCode CheckKey(key) {if(window.event. keycode='= 13) CopyCode(key)}function"AboutMe () {window.alert ("이 코드 상자는 CodePaste for Windows Live Writer에서 생성됩니다.\r
\r
Author: 범전근\r
Email:[email protected]\r
Website: http://chuangen.name\r
Blog: http://blog.csdn.net/chuangen");}
.codearea{ color:black; background-color:white; line-height:18px; border:1px solid #4f81bd; margin:0; width:auto !important; width:100%; overflow:auto; text-align:left; font-size:12px; font-family: "Courier New","Consolas","Fixedsys","BitStream Vera Sans Mono", courier,monospace,serif}
.codearea pre{ color:black; line-height:18px; padding:0 0 0 12px !important; margin:0em; background-color:#fff !important}
.linewrap pre{white-space:pre-wrap; white-space:-moz-pre-wrap; white-space:-pre-wrap; white-space:-o-pre-wrap; word-wrap:break-word; word-break:normal}
.codearea pre.alt{ background-color:#f7f7ff !important}
.codearea .lnum{color:#4f81bd;line-height:18px}
ALTER PROCEDURE [dbo].[EnterpriseInfo_By_OrganNo_Page] 
    -- Add the parameters for the stored procedure here
     @OrganNo       NVARCHAR(20) = NULL,  --  ? ? ? ? ? ?                  
     @RoleID        int,      --id
     @beginDateTime datetime,
     @PageSize       int ,    -- ? ? ? ? ? ? ? ? ?
     @pageIndex    int     , ---- ? ? ? ? ? ? ? ? ?
     @RecordCount int=0 OUTPUT,      ---- ? ? ? ? ? ? ? ?
     @pageCount INT OUTPUT,  ---- ? ? ? ? ? ? ? ? ? ? ?
     @strSQL nvarchar(max)='' output
AS
BEGIN
    DECLARE @_OrganNo NVARCHAR(20)
    Declare @_strWher   nvarchar(max)
    declare @_UserTime int
-- ? ?SQL ? ?
IF @OrganNo IS NOT NULL AND @OrganNo <> ''
    SET @_OrganNo = @OrganNo
 
-- ? ? ? ?
Select o.Name,o.OrganComCode,o.ComRegNo,o.Corporation
From TDOrgan o
Where o. OrganNo=@_OrganNo
 
-- ? ? ? ? ? ? ?
--Select l.Name,l.Phone,l.Mobile,l.Email,l.Address,l.ZipCode
--From TDGrpLinkMan l
--Where l.OrganNo=@_OrganNo
set @_strWher='OrganNo='''+@_OrganNo+''''
if @RoleID is not null
begin
  @_strWher=@_strWher+' and RoleID='+CONVERT(nvarchar(50), @RoleID)
end
if @beginDateTime is not null
begin
  @_strWher=@_strWher+' and beginDateTime='''+CONVERT(nvarchar(50), @beginDateTime,23)+''''
end
exec commPageList
   @tblName='TDGrpLinkMan',
   @fldName='Name,Phone,Mobile,Email,Address,ZipCode,Fax',
   @pageSize=@PageSize,
   @pageIndex=@pageIndex,
   @fldSort='Name',
   
   @strCondition=@_strWher,   @strGroupBy=null,
   @pageCount=@pageCount OUTPUT,
   @RecordCount=@RecordCount  OUTPUT,
   @UsedTime=@_UserTime OUTPUT,
   @strSql=@strSQL output
END

.codearea{ color:black; background-color:white; line-height:18px; border:1px solid #4f81bd; margin:0; width:auto !important; width:100%; overflow:auto; text-align:left; font-size:12px; font-family: "Courier New","Consolas","Fixedsys","BitStream Vera Sans Mono", courier,monospace,serif}
.codearea pre{ color:black; line-height:18px; padding:0 0 0 12px !important; margin:0em; background-color:#fff !important}
.linewrap pre{white-space:pre-wrap; white-space:-moz-pre-wrap; white-space:-pre-wrap; white-space:-o-pre-wrap; word-wrap:break-word; word-break:normal}
.codearea pre.alt{ background-color:#f7f7ff !important}
.codearea .lnum{color:#4f81bd;line-height:18px}
 
 
공통 페이지 나누기 저장 프로세스
--    

-------------------------------------------------------------

/*

* @tblName   ----            

* @fldName   ----         ,*      

* @pageSize   ----         

* @pageIndex  ----         

* @fldSort   ----         , :id desc (  id desc,dt asc)

* @strCondition  ----    ,  where

* @strGroupBy   ----    

* @pageCount  ----           

* @RecordCount  ----        

* @UsedTime   ----       

* @strSql   ----     SQL  

*/

ALTER PROCEDURE [dbo].[commPageList]

(

 @tblName NVARCHAR(MAX),

 @fldName NVARCHAR(MAX),

 @pageSize INT,

 @pageIndex INT,

 @fldSort NVARCHAR(MAX),

 @strCondition NVARCHAR(MAX),

 @strGroupBy nvarchar(max),

 @pageCount INT=0 OUTPUT,

 @RecordCount INT OUTPUT,

 @UsedTime INT=0 OUTPUT,

 @strSql nvarchar(max)='' OUTPUT

)

AS

 SET NOCOUNT ON

 DECLARE @startRow int, @endRow INT     ----           

 DECLARE @timediff DATETIME       ----        

 DECLARE @SqlCounts NVARCHAR(MAX)     ----            

 DECLARE @strTmp NVARCHAR(MAX)      ----        

 DECLARE @strWhere NVARCHAR(MAX)      ----        

 SELECT @timediff = getdate()      ----      

 SET @startRow = (@pageIndex - 1) * @pageSize + 1 ----     

 SET @endRow = @startRow + @pageSize - 1    ----     

 ----          ----

 IF @strCondition is null or @strCondition='' ----        

  BEGIN

   SET @SqlCounts = 'SELECT @RecordCount = COUNT(*) FROM ' + @tblName

  END

 ELSE ----       

  BEGIN

   SET @strWhere = ' WHERE ' + @strCondition

   SET @SqlCounts = 'SELECT @RecordCount = COUNT(*) FROM ' + @tblName + @strWhere

  END  

 ----         -----

 exec sp_executesql @SqlCounts,N'@RecordCount int out ',@RecordCount out 

 declare @tmpCounts int 

 if @RecordCount = 0 

  set @tmpCounts = 1 

 else 

  set @tmpCounts = @RecordCount 

    ----      ----

    set @pageCount=(@tmpCounts+@pageSize-1)/@pageSize

 ----             ----

 ----SELECT * FROM (SELECT *,ROW_NUMBER() OVER (ORDER BY contnet_keyword_addDate DESC) AS RowNumber FROM Public_content_keyword ) T WHERE T.RowNumber BETWEEN @startRow AND @endRow

  if @strGroupBy is not null and @strGroupBy <>'' ----   gruop by  

       begin

        set @tblName=@tblName + ' group by '+@strGroupBy

       end

    

  

 IF @pageIndex = 1    

  BEGIN

   IF @strCondition is null or @strCondition='' ----        

    BEGIN

     SET @strTmp = 'SELECT TOP ' + CAST(@pageSize as VARCHAR(max)) + ' ' + @fldName + ' FROM ' + @tblName + ' order by '+ @fldSort

    END

   ELSE ----       

    BEGIN

     SET @strTmp = 'SELECT TOP ' + CAST(@pageSize as VARCHAR(max)) + ' ' + @fldName + ' FROM ' + @tblName + @strWhere +' order by '+ @fldSort

    END

  END

 ELSE

  BEGIN

   IF @strCondition is null or @strCondition='' ----        

    BEGIN

     --SET @strTmp = 'SELECT ' + @fldName + ' FROM (SELECT ' + @fldName + ',ROW_NUMBER() OVER (ORDER BY ' + @fldSort + ') AS RowNumber FROM '+ @tblName +') T WHERE T.RowNumber BETWEEN ' + CAST(@startRow as VARCHAR(max)) + ' AND ' + CAST(@endRow as VARCHAR(max))

     SET @strTmp = 'SELECT * FROM (SELECT ' + @fldName + ',ROW_NUMBER() OVER (ORDER BY ' + @fldSort + ') AS RowNumber FROM '+ @tblName +') T WHERE T.RowNumber BETWEEN ' + CAST(@startRow as VARCHAR(max)) + ' AND ' + CAST(@endRow as VARCHAR(max))

    END

   ELSE ----       

    BEGIN

     --SET @strTmp = 'SELECT ' + @fldName + ' FROM (SELECT ' + @fldName + ',ROW_NUMBER() OVER (ORDER BY ' + @fldSort + ') AS RowNumber FROM '+ @tblName + @strWhere +') T WHERE T.RowNumber BETWEEN ' + CAST(@startRow as VARCHAR(max)) + ' AND ' + CAST(@endRow as VARCHAR(max))

       SET @strTmp = 'SELECT * FROM (SELECT ' + @fldName + ',ROW_NUMBER() OVER (ORDER BY ' + @fldSort + ') AS RowNumber FROM '+ @tblName + @strWhere +') T WHERE T.RowNumber BETWEEN ' + CAST(@startRow as VARCHAR(max)) + ' AND ' + CAST(@endRow as VARCHAR(max))



    END

  END 

------      -----

SET @strSql = @strTmp

EXEC(@strTmp)

SET @UsedTime = DATEDIFF(ms,@timediff,GETDATE())

SET NOCOUNT OFF

좋은 웹페이지 즐겨찾기