zoukankan      html  css  js  c++  java
  • 表字段配置sql语句 使用存储过程执行

    1、配置表信息

    USE [cishu]
    GO
    
    /****** Object:  Table [dbo].[SearchConfig]    Script Date: 03/09/2018 17:39:57 ******/
    SET ANSI_NULLS ON
    GO
    
    SET QUOTED_IDENTIFIER ON
    GO
    
    CREATE TABLE [dbo].[SearchConfig](
        [DisplayIndex] [int] NULL,
        [TypeValue] [nvarchar](100) NULL,
        [TypeName] [nvarchar](100) NULL,
        [ClassName] [nvarchar](100) NULL,
        [sqlString1] [nvarchar](500) NULL,
        [sqlString2] [nvarchar](500) NULL,
        [sqlString3] [nvarchar](500) NULL
    ) ON [PRIMARY]
    
    GO
    View Code

    2、执行存储

    USE [cishu]
    GO
    
    /****** Object:  StoredProcedure [dbo].[MessageReault_SearchFullTextList]    Script Date: 03/09/2018 17:41:20 ******/
    SET ANSI_NULLS ON
    GO
    
    SET QUOTED_IDENTIFIER ON
    GO
    
    
    
    
    ALTER PROCEDURE [dbo].[MessageReault_SearchFullTextList]
    @searchContent NVARCHAR(100) = NULL,
    @TypeValue NVARCHAR(100) = NULL,
    @PageIndex INT=1,
    @PageSize INT=10
    AS
    BEGIN
    SET NOCOUNT ON;
    
    DECLARE @ExecSql NVARCHAR(200)
    
    SELECT TOP 1 @ExecSql=sqlString3 FROM [SearchConfig] WHERE TypeValue=@TypeValue
    
    IF    (@ExecSql IS NULL OR @ExecSql='') BEGIN  RAISERROR ('配置中未找到该查询类型!', 10, 1) END
    ELSE 
    BEGIN
    exec sp_executesql @ExecSql,N'@searchContent nvarchar(100),@TypeValue nvarchar(100),@PageIndex INT,@PageSize INT', 
                @searchContent=@searchContent,@TypeValue=@TypeValue,@PageIndex=@PageIndex,@PageSize=@PageSize
    end
    --exec(@ExecSql)
    SET NOCOUNT OFF;
    END
    
    
    GO
    View Code

    3、全部类型存储

    USE [cishu]
    GO
    
    /****** Object:  StoredProcedure [dbo].[MessageReault_SearchFullTextListByAll]    Script Date: 03/09/2018 17:43:54 ******/
    SET ANSI_NULLS ON
    GO
    
    SET QUOTED_IDENTIFIER ON
    GO
    
    
    
    
    
    
    
    
    
    
    
    ALTER PROCEDURE [dbo].[MessageReault_SearchFullTextListByAll]
    @searchContent NVARCHAR(100) = NULL,
    @TypeValue NVARCHAR(100) = NULL,
    @PageIndex INT=1,
    @PageSize INT=10
    --@AllCount INT=0 OUTPUT
    AS
    BEGIN
    SET NOCOUNT ON;
        DECLARE @minIndex INT
        DECLARE @maxIndex INT
        DECLARE @ExecSql NVARCHAR(200)
    
        SELECT @minIndex=MIN(a.DisplayIndex),@maxIndex=MAX(a.DisplayIndex) FROM dbo.SearchConfig a
        WHERE TypeValue!='All'
        
        WHILE @minIndex<=@maxIndex
        BEGIN 
            DECLARE @tempAllCount INT
            DECLARE @tempTypeValue NVARCHAR(100)
            SET @tempAllCount=0
            SELECT TOP 1 @ExecSql=sqlString1,@tempTypeValue=TypeValue FROM [SearchConfig] WHERE  TypeValue!='All' AND DisplayIndex=@minIndex
            IF    (@ExecSql IS NULL OR @ExecSql='') 
            BEGIN SET @minIndex=@minIndex+1 CONTINUE  END
            ELSE 
                BEGIN
                CREATE TABLE #tmp(
                AllCount NVARCHAR(100),
                TypeValue NVARCHAR(100)
                )
                INSERT INTO #tmp
                exec sp_executesql @ExecSql,N'@searchContent nvarchar(100),@TypeValue nvarchar(100),@AllCount INT OUTPUT', 
                            @searchContent=@searchContent,@TypeValue=@tempTypeValue,@AllCount=@tempAllCount OUTPUT
                DROP TABLE #tmp
                END
            IF    @tempAllCount>0 
            BEGIN
            SET @minIndex=@minIndex+1
                 EXEC MessageReault_SearchFullTextList @searchContent,@tempTypeValue,@PageIndex,@PageSize
                 BREAK 
             END
             ELSE
             BEGIN
             SET @minIndex=@minIndex+1
             CONTINUE
             END
          
        END
    
    --exec(@ExecSql)
    SET NOCOUNT OFF;
    END
    
    
    
    
    
    
    
    
    
    GO
    View Code
  • 相关阅读:
    Memoization-329. Longest Increasing Path in a Matrix
    Map-560. Subarray Sum Equals K
    Geometry-587. Erect the Fence
    Reservoir Sampling-382. Linked List Random Node
    Brainteaser-292. Nim Game
    Minimax-486. Predict the Winner
    Topological Sor-207. Course Schedule
    web前端开发规范手册
    css初始化
    asp.net LINQ实现数据分页
  • 原文地址:https://www.cnblogs.com/caolingyi/p/8535162.html
Copyright © 2011-2022 走看看