zoukankan      html  css  js  c++  java
  • 获取多表联合查询的存储过程。

    USE [NopV3.3Test]
    GO
    /****** Object:  StoredProcedure [dbo].[GetPostList]    Script Date: 06/18/2014 15:27:19 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:        于留洋
    -- Create date: 2014/06/10
    -- Description:    根据筛选条件获取帖子列表
    -- =============================================
    ALTER PROCEDURE [dbo].[GetPostList] 
        @IsAll bit ,--是否获取所有(0:false;1:true)
        @ForumId int ,--版块id(留言,建议,投诉)
        @CustomerId int ,--客户id
        @PostId int, --内容id
        @TopicId  int --话题id
        
        
    AS
    BEGIN
      declare @GetDataSql nvarchar(1024); --要执行的sql语句  
      set @GetDataSql='select post.Id, topic.ForumId, post.Text, post.CustomerId,post.IPAddress ,post.CreatedOnUtc from dbo.Forums_Post post';
       set @GetDataSql=@GetDataSql+' inner join dbo.Forums_Topic topic on topic.Id=post.TopicId  where 1=1';
      if(@IsAll=0)
       begin
            if(@ForumId!=0)
                begin
                  set @GetDataSql=@GetDataSql+'  and topic.ForumId='+CONVERT(nvarchar(10), @ForumId);
                end
            if(@CustomerId!=0)    
                begin
                   set @GetDataSql=@GetDataSql+'  and post.CustomerId='+CONVERT(nvarchar(10), @CustomerId);
                end 
            if(@PostId!=0)
                begin
                   set @GetDataSql=@GetDataSql+'  and post.Id='+CONVERT(nvarchar(10), @PostId);
                end
        end 
        --print  @GetDataSql;
    exec (@GetDataSql);
    
    END
    CONVERT(nvarchar(10), @ForumId),因为forumid是一个int类型,在sql 中不能直接跟字符串进行拼接。所以这个是转换string类型的。
  • 相关阅读:
    【AtCoder】Tenka1 Programmer Contest(C
    【AtCoder】AGC024
    【AtCoder】ARC098题解
    java反射机制详解 及 Method.invoke解释
    Spring切入点表达式常用写法
    border-radius 样式表CSS3圆角属性
    jquery判断自己是父节点的第几个子节点
    Spring事务配置的五种方式
    Spring中PropertyPlaceholderConfigurer的使用
    js中使用s(c)标签
  • 原文地址:https://www.cnblogs.com/visibleisfalse/p/3794978.html
Copyright © 2011-2022 走看看