多表查询存储过程

多表查询存储过程  ;看懂了应该会有所收获

  1 -- Description:    根据条件查询金融产品信息。
  2 -- =============================================
  3 ALTER PROCEDURE [dbo].[SearchProduct]
  4     (
  5       @ben1 AS DECIMAL(38, 2) ,
  6       @yue1 AS INT ,
  7       @strWhere AS NVARCHAR(MAX),
  8       @PageSize as int,
  9       @PageIndex as int
 10     )
 11 AS
 12     BEGIN
 13
 14         SET NOCOUNT ON ;
 15         DECLARE @str NVARCHAR(MAX)
 16
 17         SELECT  DISTINCT
 18                 p.ProductID ,
 19                 p.ProductName ,
 20                 i.InstitutionName ,
 21                 i.IconUrl ,
 22                 i.InstitutionName + ‘ - ‘ + p.ProductName AS PNames ,
 23                 --pt.PledgeName ,
 24                 CASE WHEN CHARINDEX(‘企业主‘, ISNULL(c.ConditionContent, ‘‘)) > 0
 25                           AND CHARINDEX(‘个体户‘, ISNULL(c.ConditionContent, ‘‘)) > 0
 26                           AND CHARINDEX(‘上班族‘, ISNULL(c.ConditionContent, ‘‘)) > 0
 27                      THEN ‘企业主,个体户,上班族‘
 28                      WHEN CHARINDEX(‘企业主‘, ISNULL(c.ConditionContent, ‘‘)) > 0
 29                           AND CHARINDEX(‘个体户‘, ISNULL(c.ConditionContent, ‘‘)) > 0
 30                      THEN ‘企业主,个体户‘
 31                      WHEN CHARINDEX(‘企业主‘, ISNULL(c.ConditionContent, ‘‘)) > 0
 32                           AND CHARINDEX(‘上班族‘, ISNULL(c.ConditionContent, ‘‘)) > 0
 33                      THEN ‘企业主,上班族‘
 34                      WHEN CHARINDEX(‘个体户‘, ISNULL(c.ConditionContent, ‘‘)) > 0
 35                           AND CHARINDEX(‘上班族‘, ISNULL(c.ConditionContent, ‘‘)) > 0
 36                      THEN ‘个体户,上班族‘
 37                      WHEN CHARINDEX(‘企业主‘, ISNULL(c.ConditionContent, ‘‘)) > 0
 38                           AND CHARINDEX(‘个体户‘, ISNULL(c.ConditionContent, ‘‘)) = -1
 39                           AND CHARINDEX(‘上班族‘, ISNULL(c.ConditionContent, ‘‘)) = -1
 40                      THEN ‘企业主‘
 41                      WHEN CHARINDEX(‘企业主‘, ISNULL(c.ConditionContent, ‘‘)) = -1
 42                           AND CHARINDEX(‘个体户‘, ISNULL(c.ConditionContent, ‘‘)) > 0
 43                           AND CHARINDEX(‘上班族‘, ISNULL(c.ConditionContent, ‘‘)) = -1
 44                      THEN ‘个体户‘
 45                      WHEN CHARINDEX(‘企业主‘, ISNULL(c.ConditionContent, ‘‘)) = -1
 46                           AND CHARINDEX(‘个体户‘, ISNULL(c.ConditionContent, ‘‘)) = -1
 47                           AND CHARINDEX(‘上班族‘, ISNULL(c.ConditionContent, ‘‘)) > 0
 48                      THEN ‘上班族‘
 49                      ELSE ‘无身份要求‘
 50                 END AS Identitys ,
 51                 c.ConditionContent ,
 52                 LoanTime ,
 53                 CASE WHEN ( POWER(( 1 + MothRateMin ), @yue1) - 1 ) <> 0
 54                      THEN ( @ben1 * MothRateMin * POWER(( 1 + MothRateMin ),
 55                                                         @yue1) ) / ( POWER(( 1
 56                                                               + MothRateMin ),
 57                                                               @yue1) - 1 )
 58                      ELSE 0
 59                 END AS yuegong ,
 60                 CASE WHEN ( POWER(( 1 + MothRateMin ), @yue1) - 1 ) <> 0
 61                      THEN ( ( @ben1 * MothRateMin * POWER(( 1 + MothRateMin ),
 62                                                           @yue1) )
 63                             / ( POWER(( 1 + MothRateMin ), @yue1) - 1 ) )
 64                           * @yue1 - @ben1
 65                      ELSE 0
 66                 END AS SumRateMin ,
 67                   case when
 68                 charindex(‘</li>‘,isnull(c.ConditionContent,‘‘))   <=0
 69                  or charindex(‘</li>‘,isnull(c.ConditionContent,‘‘),charindex(‘</li>‘,isnull(c.ConditionContent,‘‘))+1)<=0
 70               or charindex(‘</li>‘,isnull(c.ConditionContent,‘‘), charindex(‘</li>‘,isnull(c.ConditionContent,‘‘),charindex(‘</li>‘,isnull(c.ConditionContent,‘‘))+1)+1)<=0 or
 71                   ( charindex(‘</li>‘,isnull(c.ConditionContent,‘‘), charindex(‘</li>‘,isnull(c.ConditionContent,‘‘), charindex(‘</li>‘,isnull(c.ConditionContent,‘‘))+1)+1)+4 )   <=0
 72                then c.ConditionContent
 73          else
 74                 SUBSTRING(isnull(c.ConditionContent,‘‘),1,charindex(‘</li>‘,isnull(c.ConditionContent,‘‘), charindex(‘</li>‘,isnull(c.ConditionContent,‘‘), charindex(‘</li>‘,isnull(c.ConditionContent,‘‘))+1)+1)+4) end as   ConditionContents,
 75                 e.TypeName ,
 76                 pt.PledgeName ,
 77                 CAST(LimitMin AS VARCHAR) + ‘ ~ ‘ + CAST(LimitMax AS VARCHAR) AS LimitMin ,
 78                 CAST(DeadLineMin AS VARCHAR) + ‘ ~ ‘
 79                 + CAST(DeadLineMax AS VARCHAR) AS DeadLineMin ,
 80                 m.RepaymentName ,
 81                 MothRateMin AS RateMin ,
 82                 CAST(MothRateMin AS VARCHAR) + ‘ %~ ‘
 83                 + CAST(MothRateMax AS VARCHAR) + ‘%‘ AS MothRateMins ,
 84                 CASE p.SynthesizeRate
 85                   WHEN ‘确切‘
 86                   THEN CAST(RateMin AS VARCHAR) + ‘% ~ ‘
 87                        + CAST(RateMax AS VARCHAR) + ‘%‘
 88                   ELSE p.SynthesizeRate
 89                 END AS SynthesizeRate ,
 90                 CASE p.SecurityCost
 91                   WHEN ‘确切‘
 92                   THEN CAST(CostMin AS VARCHAR) + ‘% ~ ‘
 93                        + CAST(CostMax AS VARCHAR) + ‘%‘
 94                   ELSE p.SecurityCost
 95                 END AS SecurityCost ,
 96                 CASE OneTimeFee
 97                   WHEN ‘确切‘
 98                   THEN CAST(FeeMin AS VARCHAR) + ‘% ~ ‘
 99                        + CAST(FeeMax AS VARCHAR) + ‘%‘
100                   ELSE OneTimeFee
101                 END AS OneTimeFee
102         FROM    dbo.P_LoanProduct p
103                 LEFT JOIN dbo.I_Institution i ON p.InstitutionID = i.InstitutionID
104                 LEFT JOIN dbo.I_InstitutionType t ON i.InstitutioniTypeID = t.InstitutioniTypeID
105                 LEFT JOIN dbo.P_PledgeType pt ON p.PledgeID = pt.PledgeID
106                 LEFT JOIN dbo.P_ProductType e ON p.ProductTypeID = e.ProductTypeID
107                 LEFT JOIN dbo.P_RepaymentMode m ON p.ModeID = m.ModeID
108                 LEFT JOIN dbo.P_Product_Condition pc ON p.ProductID = pc.ProductID
109                 LEFT JOIN dbo.P_Condition c ON pc.ConditionID = c.ConditionID
110                 LEFT JOIN dbo.P_ConditionCredit ct ON c.ConditionID = ct.ConditionID
111                 LEFT JOIN dbo.P_ConditionProperty py ON c.ConditionID = py.ConditionID
112                 LEFT JOIN dbo.P_ResidenceAge re ON c.ConditionID = re.ConditionID
113                 LEFT JOIN dbo.P_WorkAge w ON c.ConditionID = w.ConditionID
114                 LEFT JOIN dbo.P_ShopAge s ON c.ConditionID = s.ConditionID
115                 LEFT JOIN dbo.P_Condition_Certificate cc ON c.ConditionID = cc.ConditionID
116                 LEFT JOIN dbo.P_ConditionOwning co ON c.ConditionID = co.ConditionID
117                 LEFT JOIN dbo.P_CIManageAge ca ON c.ConditionID = ca.ConditionID
118                 LEFT JOIN dbo.P_ConditionManage cm ON c.ConditionID = cm.ConditionID
119                 LEFT JOIN dbo.P_ConditionIdentity ci ON c.ConditionID = ci.ConditionID
120                 LEFT JOIN dbo.P_ConditionPlace cp ON c.ConditionID = cp.ConditionID
121
122
123     END
124   --exec dbo.SearchProduct   10000.00,12,‘  ‘ ,3,1

dal层 多表查询

 1   /// <summary>
 2         /// 分页获取数据列表json
 3         /// </summary>
 4         public string GetListByPageJsonn( decimal ben, int yue,int PageSize, int PageIndex, string strWhere)
 5         {
 6             DataSet Ds = new DataSet();
 7             StringBuilder strSql = new StringBuilder();
 8
 9             strSql.Append("  declare @yue1  int ,   @ben1 decimal(38,2)   set  @yue1= ");
10             strSql.Append(yue);
11
12             strSql.Append("   set @ben1 =");
13             strSql.Append(ben);
14
15             strSql.Append("    SELECT  DISTINCT  p.ProductID ,p.ProductName ,i.InstitutionName ,i.IconUrl ,i.InstitutionName + ‘ - ‘ + p.ProductName AS PNames , CASE WHEN CHARINDEX(‘企业主‘, ISNULL(c.ConditionContent, ‘‘)) > 0  AND CHARINDEX(‘个体户‘, ISNULL(c.ConditionContent, ‘‘)) > 0 AND CHARINDEX(‘上班族‘, ISNULL(c.ConditionContent, ‘‘)) > 0 THEN ‘企业主,个体户,上班族‘ WHEN CHARINDEX(‘企业主‘, ISNULL(c.ConditionContent, ‘‘)) > 0 AND CHARINDEX(‘个体户‘, ISNULL(c.ConditionContent, ‘‘)) > 0 THEN ‘企业主,个体户‘ WHEN CHARINDEX(‘企业主‘, ISNULL(c.ConditionContent, ‘‘)) > 0 AND CHARINDEX(‘上班族‘, ISNULL(c.ConditionContent, ‘‘)) > 0 THEN ‘企业主,上班族‘ WHEN CHARINDEX(‘个体户‘, ISNULL(c.ConditionContent, ‘‘)) > 0 AND CHARINDEX(‘上班族‘, ISNULL(c.ConditionContent, ‘‘)) > 0 THEN ‘个体户,上班族‘ WHEN CHARINDEX(‘企业主‘, ISNULL(c.ConditionContent, ‘‘)) > 0 AND CHARINDEX(‘个体户‘, ISNULL(c.ConditionContent, ‘‘)) = -1 AND CHARINDEX(‘上班族‘, ISNULL(c.ConditionContent, ‘‘)) = -1 THEN ‘企业主‘ WHEN CHARINDEX(‘企业主‘, ISNULL(c.ConditionContent, ‘‘)) = -1 AND CHARINDEX(‘个体户‘, ISNULL(c.ConditionContent, ‘‘)) > 0 AND CHARINDEX(‘上班族‘, ISNULL(c.ConditionContent, ‘‘)) = -1 THEN ‘个体户‘ WHEN CHARINDEX(‘企业主‘, ISNULL(c.ConditionContent, ‘‘)) = -1 AND CHARINDEX(‘个体户‘, ISNULL(c.ConditionContent, ‘‘)) = -1 AND CHARINDEX(‘上班族‘, ISNULL(c.ConditionContent, ‘‘)) > 0 THEN ‘上班族‘ ELSE ‘无身份要求‘                 END AS Identitys , c.ConditionContent , LoanTime , CASE WHEN ( POWER(( 1 + MothRateMin ), @yue1) - 1 ) <> 0 THEN ( @ben1 * MothRateMin * POWER(( 1 + MothRateMin ), @yue1) ) / ( POWER(( 1 + MothRateMin ), @yue1) - 1 )ELSE 0 END AS yuegong , CASE WHEN ( POWER(( 1 + MothRateMin ), @yue1) - 1 ) <> 0 THEN ( ( @ben1 * MothRateMin * POWER(( 1 + MothRateMin ),@yue1) )/ ( POWER(( 1 + MothRateMin ), @yue1) - 1 ) )* @yue1 - @ben1 ELSE 0 END AS SumRateMin ,  case when    charindex(‘</li>‘,isnull(c.ConditionContent,‘‘))   <=0  or charindex(‘</li>‘,isnull(c.ConditionContent,‘‘),charindex(‘</li>‘,isnull(c.ConditionContent,‘‘))+1)<=0  or charindex(‘</li>‘,isnull(c.ConditionContent,‘‘), charindex(‘</li>‘,isnull(c.ConditionContent,‘‘),charindex(‘</li>‘,isnull(c.ConditionContent,‘‘))+1)+1)<=0 or ( charindex(‘</li>‘,isnull(c.ConditionContent,‘‘), charindex(‘</li>‘,isnull(c.ConditionContent,‘‘), charindex(‘</li>‘,isnull(c.ConditionContent,‘‘))+1)+1)+4 )   <=0    then c.ConditionContent else   SUBSTRING(isnull(c.ConditionContent,‘‘),1,charindex(‘</li>‘,isnull(c.ConditionContent,‘‘), charindex(‘</li>‘,isnull(c.ConditionContent,‘‘), charindex(‘</li>‘,isnull(c.ConditionContent,‘‘))+1)+1)+4) end as   ConditionContents, e.TypeName ,pt.PledgeName ,CAST(LimitMin AS VARCHAR) + ‘ ~ ‘ + CAST(LimitMax AS VARCHAR) AS LimitMin ,CAST(DeadLineMin AS VARCHAR) + ‘ ~ ‘ + CAST(DeadLineMax AS VARCHAR) AS DeadLineMin ,m.RepaymentName ,MothRateMin AS RateMin ,CAST(MothRateMin AS VARCHAR) + ‘ %~ ‘+ CAST(MothRateMax AS VARCHAR) + ‘%‘ AS MothRateMins ,CASE p.SynthesizeRate WHEN ‘确切‘ THEN CAST(RateMin AS VARCHAR) + ‘% ~ ‘+ CAST(RateMax AS VARCHAR) + ‘%‘ ELSE p.SynthesizeRate END AS SynthesizeRate ,CASE p.SecurityCost WHEN ‘确切‘ THEN CAST(CostMin AS VARCHAR) + ‘% ~ ‘ + CAST(CostMax AS VARCHAR) + ‘%‘ ELSE p.SecurityCost END AS SecurityCost , CASE OneTimeFee WHEN ‘确切‘ THEN CAST(FeeMin AS VARCHAR) + ‘% ~ ‘ + CAST(FeeMax AS VARCHAR) + ‘%‘ ELSE OneTimeFee END AS OneTimeFee FROM    dbo.P_LoanProduct p  LEFT JOIN dbo.I_Institution i ON p.InstitutionID = i.InstitutionID LEFT JOIN dbo.I_InstitutionType t ON i.InstitutioniTypeID = t.InstitutioniTypeID LEFT JOIN dbo.P_PledgeType pt ON p.PledgeID = pt.PledgeID LEFT JOIN dbo.P_ProductType e ON p.ProductTypeID = e.ProductTypeID LEFT JOIN dbo.P_RepaymentMode m ON p.ModeID = m.ModeID LEFT JOIN dbo.P_Product_Condition pc ON p.ProductID = pc.ProductID LEFT JOIN dbo.P_Condition c ON pc.ConditionID = c.ConditionID LEFT JOIN dbo.P_ConditionCredit ct ON c.ConditionID = ct.ConditionID LEFT JOIN dbo.P_ConditionProperty py ON c.ConditionID = py.ConditionID LEFT JOIN dbo.P_ResidenceAge re ON c.ConditionID = re.ConditionID LEFT JOIN dbo.P_WorkAge w ON  c.ConditionID = w.ConditionID LEFT JOIN dbo.P_ShopAge s ON c.ConditionID = s.ConditionID LEFT JOIN dbo.P_Condition_Certificate cc ON c.ConditionID = cc.ConditionID LEFT JOIN dbo.P_ConditionOwning co ON c.ConditionID = co.ConditionID LEFT JOIN dbo.P_CIManageAge ca ON c.ConditionID = ca.ConditionID LEFT JOIN dbo.P_ConditionManage cm ON c.ConditionID = cm.ConditionID LEFT JOIN dbo.P_ConditionIdentity ci ON c.ConditionID = ci.ConditionID LEFT JOIN dbo.P_ConditionPlace cp ON c.ConditionID = cp.ConditionID  ");
16             if (strWhere.Trim() != "")
17             {
18                 strSql.Append("  where  " + strWhere);
19             }
20             DbHelperSQL.GotDataList(strSql.ToString(), "DataList", Ds, PageIndex * PageSize, PageSize);//分页后的数据
21             return DbHelperSQL.ToJson(Ds.Tables[0], GetRecordCountn(ben,yue, strWhere));
22         }
23
24         /// <summary>
25         /// 获取记录总数
26         /// </summary>
27         public int GetRecordCountn(decimal ben, int yue, string strWhere)
28         {
29             DataSet Ds = new DataSet();
30             StringBuilder strSql = new StringBuilder();
31
32             strSql.Append("  declare @yue1  int ,   @ben1 decimal(38,2)   set  @yue1= ");
33             strSql.Append(yue);
34
35             strSql.Append("   set @ben1 =");
36             strSql.Append(ben);
37             strSql.Append("select  count(1) from    ( ");
38             strSql.Append("    SELECT  DISTINCT  p.ProductID ,p.ProductName ,i.InstitutionName ,i.IconUrl ,i.InstitutionName + ‘ - ‘ + p.ProductName AS PNames , CASE WHEN CHARINDEX(‘企业主‘, ISNULL(c.ConditionContent, ‘‘)) > 0  AND CHARINDEX(‘个体户‘, ISNULL(c.ConditionContent, ‘‘)) > 0 AND CHARINDEX(‘上班族‘, ISNULL(c.ConditionContent, ‘‘)) > 0 THEN ‘企业主,个体户,上班族‘ WHEN CHARINDEX(‘企业主‘, ISNULL(c.ConditionContent, ‘‘)) > 0 AND CHARINDEX(‘个体户‘, ISNULL(c.ConditionContent, ‘‘)) > 0 THEN ‘企业主,个体户‘ WHEN CHARINDEX(‘企业主‘, ISNULL(c.ConditionContent, ‘‘)) > 0 AND CHARINDEX(‘上班族‘, ISNULL(c.ConditionContent, ‘‘)) > 0 THEN ‘企业主,上班族‘ WHEN CHARINDEX(‘个体户‘, ISNULL(c.ConditionContent, ‘‘)) > 0 AND CHARINDEX(‘上班族‘, ISNULL(c.ConditionContent, ‘‘)) > 0 THEN ‘个体户,上班族‘ WHEN CHARINDEX(‘企业主‘, ISNULL(c.ConditionContent, ‘‘)) > 0 AND CHARINDEX(‘个体户‘, ISNULL(c.ConditionContent, ‘‘)) = -1 AND CHARINDEX(‘上班族‘, ISNULL(c.ConditionContent, ‘‘)) = -1 THEN ‘企业主‘ WHEN CHARINDEX(‘企业主‘, ISNULL(c.ConditionContent, ‘‘)) = -1 AND CHARINDEX(‘个体户‘, ISNULL(c.ConditionContent, ‘‘)) > 0 AND CHARINDEX(‘上班族‘, ISNULL(c.ConditionContent, ‘‘)) = -1 THEN ‘个体户‘ WHEN CHARINDEX(‘企业主‘, ISNULL(c.ConditionContent, ‘‘)) = -1 AND CHARINDEX(‘个体户‘, ISNULL(c.ConditionContent, ‘‘)) = -1 AND CHARINDEX(‘上班族‘, ISNULL(c.ConditionContent, ‘‘)) > 0 THEN ‘上班族‘ ELSE ‘无身份要求‘                 END AS Identitys , c.ConditionContent , LoanTime , CASE WHEN ( POWER(( 1 + MothRateMin ), @yue1) - 1 ) <> 0 THEN ( @ben1 * MothRateMin * POWER(( 1 + MothRateMin ), @yue1) ) / ( POWER(( 1 + MothRateMin ), @yue1) - 1 )ELSE 0 END AS yuegong , CASE WHEN ( POWER(( 1 + MothRateMin ), @yue1) - 1 ) <> 0 THEN ( ( @ben1 * MothRateMin * POWER(( 1 + MothRateMin ),@yue1) )/ ( POWER(( 1 + MothRateMin ), @yue1) - 1 ) )* @yue1 - @ben1 ELSE 0 END AS SumRateMin ,  case when    charindex(‘</li>‘,isnull(c.ConditionContent,‘‘))   <=0  or charindex(‘</li>‘,isnull(c.ConditionContent,‘‘),charindex(‘</li>‘,isnull(c.ConditionContent,‘‘))+1)<=0  or charindex(‘</li>‘,isnull(c.ConditionContent,‘‘), charindex(‘</li>‘,isnull(c.ConditionContent,‘‘),charindex(‘</li>‘,isnull(c.ConditionContent,‘‘))+1)+1)<=0 or ( charindex(‘</li>‘,isnull(c.ConditionContent,‘‘), charindex(‘</li>‘,isnull(c.ConditionContent,‘‘), charindex(‘</li>‘,isnull(c.ConditionContent,‘‘))+1)+1)+4 )   <=0    then c.ConditionContent else   SUBSTRING(isnull(c.ConditionContent,‘‘),1,charindex(‘</li>‘,isnull(c.ConditionContent,‘‘), charindex(‘</li>‘,isnull(c.ConditionContent,‘‘), charindex(‘</li>‘,isnull(c.ConditionContent,‘‘))+1)+1)+4) end as   ConditionContents, e.TypeName ,pt.PledgeName ,CAST(LimitMin AS VARCHAR) + ‘ ~ ‘ + CAST(LimitMax AS VARCHAR) AS LimitMin ,CAST(DeadLineMin AS VARCHAR) + ‘ ~ ‘ + CAST(DeadLineMax AS VARCHAR) AS DeadLineMin ,m.RepaymentName ,MothRateMin AS RateMin ,CAST(MothRateMin AS VARCHAR) + ‘ %~ ‘+ CAST(MothRateMax AS VARCHAR) + ‘%‘ AS MothRateMins ,CASE p.SynthesizeRate WHEN ‘确切‘ THEN CAST(RateMin AS VARCHAR) + ‘% ~ ‘+ CAST(RateMax AS VARCHAR) + ‘%‘ ELSE p.SynthesizeRate END AS SynthesizeRate ,CASE p.SecurityCost WHEN ‘确切‘ THEN CAST(CostMin AS VARCHAR) + ‘% ~ ‘ + CAST(CostMax AS VARCHAR) + ‘%‘ ELSE p.SecurityCost END AS SecurityCost , CASE OneTimeFee WHEN ‘确切‘ THEN CAST(FeeMin AS VARCHAR) + ‘% ~ ‘ + CAST(FeeMax AS VARCHAR) + ‘%‘ ELSE OneTimeFee END AS OneTimeFee FROM    dbo.P_LoanProduct p  LEFT JOIN dbo.I_Institution i ON p.InstitutionID = i.InstitutionID LEFT JOIN dbo.I_InstitutionType t ON i.InstitutioniTypeID = t.InstitutioniTypeID LEFT JOIN dbo.P_PledgeType pt ON p.PledgeID = pt.PledgeID LEFT JOIN dbo.P_ProductType e ON p.ProductTypeID = e.ProductTypeID LEFT JOIN dbo.P_RepaymentMode m ON p.ModeID = m.ModeID LEFT JOIN dbo.P_Product_Condition pc ON p.ProductID = pc.ProductID LEFT JOIN dbo.P_Condition c ON pc.ConditionID = c.ConditionID LEFT JOIN dbo.P_ConditionCredit ct ON c.ConditionID = ct.ConditionID LEFT JOIN dbo.P_ConditionProperty py ON c.ConditionID = py.ConditionID LEFT JOIN dbo.P_ResidenceAge re ON c.ConditionID = re.ConditionID LEFT JOIN dbo.P_WorkAge w ON  c.ConditionID = w.ConditionID LEFT JOIN dbo.P_ShopAge s ON c.ConditionID = s.ConditionID LEFT JOIN dbo.P_Condition_Certificate cc ON c.ConditionID = cc.ConditionID LEFT JOIN dbo.P_ConditionOwning co ON c.ConditionID = co.ConditionID LEFT JOIN dbo.P_CIManageAge ca ON c.ConditionID = ca.ConditionID LEFT JOIN dbo.P_ConditionManage cm ON c.ConditionID = cm.ConditionID LEFT JOIN dbo.P_ConditionIdentity ci ON c.ConditionID = ci.ConditionID LEFT JOIN dbo.P_ConditionPlace cp ON c.ConditionID = cp.ConditionID  ");
39             if (strWhere.Trim() != "")
40             {
41                 strSql.Append("  where  " + strWhere);
42             }
43             strSql.Append(") as a");
44             object obj = DbHelperSQL.GetSingle(strSql.ToString());
45             if (obj == null)
46             {
47                 return 0;
48             }
49             else
50             {
51                 return Convert.ToInt32(obj);
52             }
53         }
时间: 2024-10-08 21:53:52

多表查询存储过程的相关文章

多表查询分页存储过程,解决了第二页不显示的问题

SET ANSI_NULLS OFFGOSET QUOTED_IDENTIFIER OFFGO ALTER PROCEDURE [dbo].[UP_Pagination]/****************************************************************** 千万数量级分页存储过程 *****************************************************************参数说明:1.Tables :表名称,视

SQL 中怎么查询数据库中具有的表、存储过程、试图数目、总触发器数、作业数

用户表:select count(*) 总表数 from sysobjects where xtype='u' 刚才那个是用户表,下面这个是系统表加用户表: select count(*) 总表数 from sysobject s where xtype in('u','s') 总视图数:select count(*) 总视图数 from sysobjects where xtype='v' 总存储过程数:select count(*) 总存储过程数 from sysobjects where

oracle系统表查询

oracle查询用户下的所有表 select * from all_tab_comments -- 查询所有用户的表,视图等select * from user_tab_comments -- 查询本用户的表,视图等select * from all_col_comments --查询所有用户的表的列名和注释.select * from user_col_comments -- 查询本用户的表的列名和注释select * from all_tab_columns --查询所有用户的表的列名等信息

sql server快速删除整个数据库表和存储过程

情况:在远程数据库删除表执行太慢,表过多,数据库无权删除 结果:保留空数据库 方法:利用sql语句,查询网络文摘解决. 说明: 有些有约束,不能直接delete,需要先删除所有约束,语句: DECLARE c1 cursor for select 'alter table ['+ object_name(parent_obj) + '] drop constraint ['+name+']; ' from sysobjects where xtype = 'F' open c1 declare

交叉表—用存储过程实现的普通交叉表(一)

交叉表-用存储过程实现的普通交叉表(一) 开发工具:C#2008/2010 数据库:Sql Server 2000/2005/2008 界面:WinForm 关于交叉表,各位网友用各种方法实现的不少了,本文主要从用存储过程实现交叉表功能进行探讨,这种方法给具体用户也做了不少.界面如下: 一.基本数据结构 (一)销售单主表结构 (二)销售单明细明 (三)由上述两表组成的视图 二.存储过程 --业务经理销售或兑换分品种按客户汇总表CREATE PROCEDURE YWYXSDHFPZKHHZ(@TJ

oracle 常用的系统表查询

(转自:http://blog.csdn.net/marshalchen/article/details/6552103) select * from user_tab_cols where column_name=upper('xxxxx');查询哪些表中有某一列 select status from user_objects where object_name=upper('f_get_multicountry_from_code')  查询过程或函数是否编译完成 alter procedu

03: 数据导入导出 、 表记录基本操作 、 查询及匹配条件 、 多表查询

day03一数据导入二数据导出三管理表记录 *3.1 插入表记录3.2 查询表记录 (单表 多表 嵌套 连接)3.3 条件匹配3.4 更新表记录字段的值3.5 删除表记录++++++++++++++++++++++++++++++++一数据导入 : 把系统文件的内容存储到数据库的表里.把系统已有的用户信息存储到studb.user表/etc/passwd用户名 密码站位符 uid gid 描述信息 家目录 shell create database studb;create table stud

树形结构表查询,只用一条SQL语句查询所有父级ID解决办法

在树形结构表查询中用得最多的就是查询指定分类的所有下级分类,这个性能比较好的解决方案是为分类加一个编码(路径)把父级的ID都拼接上,最后通过like 'x%'就能把所有下级分类select出来.但是有时也会遇到反过来,找出指定分类的所有上级分类,这个情况尤其在分销或类传销的系统中最常见,因为他们分成都是上级分成,所以要找出指定人的上级集合. 下面分享一下我的解决方案(只用一条SQL语句.不用存储过程.函数): 有下面所在的新闻分类表. ParentID为父级的ID. 下面要找出ID为52的所有上

多表查询-inner join 、left join、 right join、full join

一.基础 1.1 SQL查询的基本原理 第一.单表查询:根据WHERE条件过滤表中的记录,形成中间表(这个中间表对用户是不可见的):然后根据SELECT的选择列选择相应的列进行返回最终结果.第二.两表连接查询:对两表求积(笛卡尔积)并用ON条件和连接连接类型进行过滤形成中间表:然后根据WHERE条件过滤中间表的记录,并根据SELECT指定的列返回查询结果.第三.多表连接查询:先对第一个和第二个表按照两表连接做查询,然后用查询结果和第三个表做连接查询,以此类推,直到所有的表都连接上为止,最终形成一