码迷,mamicode.com
首页 > 数据库 > 详细

access数据库多个left join示例

时间:2014-10-13 17:33:19      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   sp   

代码:

bubuko.com,布布扣
/// <summary>
/// 分类检索 查询selectname
/// </summary>
public static DataTable GetSelectName_FLJS(string thing_type_id, string men_id, string gang_id, string mu_id, string ke_id, string shu_id)
{
    StringBuilder sb = new StringBuilder(string.Format(@"
        select sn.Sel_chiname as 中文名, sn.Sel_engname as 英文名, sn.Sel_latname as 学名,
        sn.Thing_id, sn.Sel_type, sn.Thing_shu_id, sn.Thing_pro_id, sn.Thing_area_id
                
        from (((((selectname sn
        left join shu s on sn.thing_shu_id=s.shu_id)
        left join ke k on s.ke_id=k.ke_id)
        left join mu m on m.mu_id=k.mu_id)
        left join gang g on g.gang_id=m.gang_id)
        left join men me on me.men_id=g.men_id)
        left join thing_type tt on tt.thing_type_id=me.thing_type_id

        where 1=1"));

    if (!string.IsNullOrWhiteSpace(thing_type_id)
        && int.Parse(thing_type_id) != Common.OptionAllVal)
    {
        sb.Append(string.Format(@" 
            and tt.thing_type_id={0}", strUtil.SqlClean(thing_type_id)));
    }

    if (!string.IsNullOrWhiteSpace(men_id)
        && int.Parse(men_id) != Common.OptionAllVal)
    {
        sb.Append(string.Format(@" 
            and me.men_id={0}", strUtil.SqlClean(men_id)));
    }

    if (!string.IsNullOrWhiteSpace(gang_id)
        && int.Parse(gang_id) != Common.OptionAllVal)
    {
        sb.Append(string.Format(@" 
            and g.gang_id={0}", strUtil.SqlClean(gang_id)));
    }

    if (!string.IsNullOrWhiteSpace(mu_id)
        && int.Parse(mu_id) != Common.OptionAllVal)
    {
        sb.Append(string.Format(@" 
            and m.mu_id={0}", strUtil.SqlClean(mu_id)));
    }

    if (!string.IsNullOrWhiteSpace(ke_id)
        && int.Parse(ke_id) != Common.OptionAllVal)
    {
        sb.Append(string.Format(@" 
            and k.ke_id={0}", strUtil.SqlClean(ke_id)));
    }

    if (!string.IsNullOrWhiteSpace(shu_id)
        && int.Parse(shu_id) != Common.OptionAllVal)
    {
        sb.Append(string.Format(@" 
            and s.shu_id={0}", strUtil.SqlClean(shu_id)));
    }

    sb.Append(" order by sn.Sel_chiname");

    return AccessHelper.DataTable(sb.ToString());
}
View Code

 

access数据库多个left join示例

标签:style   blog   http   color   io   os   ar   for   sp   

原文地址:http://www.cnblogs.com/s0611163/p/4022242.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!