1.       /*  SQL CASE 语句写法

* SELECT TABLE1.USER_ID, TABLE1.COMP_CODE, TABLE1.DEPT_CODE, TABLE1.USER_NAME,

TABLE2.COMP_NAME, TABLE3.DEPT_NAME,

(case when (TABLE1.ADMIN_YN = '1') then '管理员'

else  '普通用户' end) as USER, TABLE1.ADMIN_YN

*/

2.         Replace语法

sql += "AND (REPLACE(BOOK_NAME,' ','') LIKE @BOOK_NAME or ";
                sql += "REPLACE(BOOK_NAME1,' ','') LIKE @BOOK_NAME)";
                ht.Add("@BOOK_NAME", "%" + strSm.Replace(" ","") + "%");

3. Linq

Select

            IQueryable<Tb_TSGL> model = null;

            if ("Keywords".Equals(strValue))
{
model = from r in DataContext.Tb_TSGL
where SqlMethods.Like(r.TSGJC, string.Format("%{0}%", strText))
select r;
}
if ("bookName".Equals(strValue))
{
model = from r in DataContext.Tb_TSGL
where SqlMethods.Like(r.TSM_ZW, string.Format("%{0}%", strText)) || SqlMethods.Like(r.TSM_CW, string.Format("%{0}%", strText))
select r;
}
return model;

Update

        /// <summary>
/// 更新图书小类Table
/// </summary>
/// <param name="model"></param>
public void Tb_TSXL_UpdateAll(Tb_TSXL model)
{
Tb_TSXL updateModel = (from s in DataContext.Tb_TSXL
where s.ID == model.ID
select s).FirstOrDefault<Tb_TSXL>();
updateModel.SFSY = model.SFSY;
updateModel.NAME = model.NAME;
updateModel.TSDL_ID = model.TSDL_ID;
updateModel.KoreanName = model.KoreanName;
updateModel.FL = model.FL; DataContext.SubmitChanges();
}

Insert

        public void Tb_TSDL_Insert(Tb_TSDL model)
{
DataContext.Tb_TSDL.InsertOnSubmit(model);
DataContext.SubmitChanges();
}

Delete

        public void Tb_TSDL_Delete(Tb_TSDL model)
{
Tb_TSDL deleteModel = (from s in DataContext.Tb_TSDL
where s.ID == model.ID
select s).FirstOrDefault<Tb_TSDL>(); DataContext.Tb_TSDL.DeleteOnSubmit(deleteModel);
DataContext.SubmitChanges();
}

4. Procedure

        /// <summary>
/// 利用存储过程,获取图书列表
/// </summary>
/// <param name="f"></param>
/// <param name="language"></param>
/// <param name="pageSize"></param>
/// <param name="pageIndex"></param>
/// <param name="total"></param>
/// <param name="page"></param>
/// <returns></returns>
public DataTable GetBookDefault(string f, int language, int pageSize, int pageIndex, out int total, out int page)
{
IDataParameter[] iData = new IDataParameter[]; iData[] = new SqlParameter("@TableName", "Tb_TSGL");
iData[] = new SqlParameter("@FieldList", "*");
iData[] = new SqlParameter("@PrimaryKey", "ID"); switch (language)
{
case : /*朝文*/
if (f.Equals("Z")) //중점도서
{
iData[] = new SqlParameter("@Where", "SFZDTS = 1 and TSDL_ID = 1 and SFKSXS = 1 and (BType = 'K' or BType = 'U')");
}
else if (f.Equals("T")) //추천도서
{
iData[] = new SqlParameter("@Where", "SFTJTS = 1 and TSDL_ID = 1 and SFKSXS = 1 and (BType = 'K' or BType = 'U')");
}
else if (f.Equals("N")) //최신도서
{
iData[] = new SqlParameter("@Where", "TSDL_ID = 1 and SFKSXS = 1 and (BType = 'K' or BType = 'U')");
} else if (f.Equals("Natural")) //자연과학도서
{
iData[] = new SqlParameter("@Where", "TSXL_ID Like '%N%' and TSDL_ID = 1 and SFKSXS = 1 and (BType = 'K' or BType = 'U')");
}
else if (f.Equals("Complex")) //종합성도서
{
iData[] = new SqlParameter("@Where", "TSXL_ID Like '%Z%' and TSDL_ID = 1 and SFKSXS = 1 and (BType = 'K' or BType = 'U')");
}
else if (f.Equals("Elec")) //전자도서
{
iData[] = new SqlParameter("@Where", "SFDZTS = 1 and (BType = 'K' or BType = 'U') and SFKSXS = 1");
}
else if (f.Equals("Social")) //사회과학도서
{
iData[] = new SqlParameter("@Where", "TSXL_ID Like '%C%' and TSDL_ID = 1 and SFKSXS = 1 and (BType = 'K' or BType = 'U')");
}
else if (f.Equals("Periodical")) //정기간행물
{
iData[] = new SqlParameter("@Where", "TSDL_ID = 2 and SFKSXS = 1 and (BType = 'K' or BType = 'U')");
}
else if (f.Equals("Cheap")) //특가도서
{
iData[] = new SqlParameter("@Where", "SFGDTS = 1 and SFKSXS = 1 and (r.BType = 'K' or BType = 'U')");
} else
{
iData[] = new SqlParameter("@Where", "(BType = 'K' || BType = 'U') and SFKSXS = 1");
}
break; case : //中文 if (f.Equals("Z")) //重点图书
{
iData[] = new SqlParameter("@Where", "SFZDTS = 1 and TSDL_ID = 1 and SFKSXS = 1 and (BType = 'K' or BType = 'U')");
}
else if (f.Equals("T")) //推荐图书
{
iData[] = new SqlParameter("@Where", "SFTJTS = 1 and TSDL_ID = 1 and SFKSXS = 1 and (BType = 'C' or BType = 'U')");
}
else if (f.Equals("N")) //최신도서
{
iData[] = new SqlParameter("@Where", "TSDL_ID = 1 and SFKSXS = 1 and (BType = 'C' or BType = 'U')");
} else if (f.Equals("Natural")) //자연과학도서
{
iData[] = new SqlParameter("@Where", "TSXL_ID Like '%N%' and TSDL_ID = 1 and SFKSXS = 1 and (BType = 'C' or BType = 'U')");
}
else if (f.Equals("Complex")) //종합성도서
{
iData[] = new SqlParameter("@Where", "TSXL_ID Like '%Z%' and TSDL_ID = 1 and SFKSXS = 1 and (BType = 'C' or BType = 'U')");
}
else if (f.Equals("Elec")) //전자도서
{
iData[] = new SqlParameter("@Where", "SFDZTS = 1 and (BType = 'C' or BType = 'U') and SFKSXS = 1");
}
else if (f.Equals("Social")) //사회과학도서
{
iData[] = new SqlParameter("@Where", "TSXL_ID Like '%C%' and TSDL_ID = 1 and SFKSXS = 1 and (BType = 'C' or BType = 'U')");
}
else if (f.Equals("Periodical")) //정기간행물
{
iData[] = new SqlParameter("@Where", "TSDL_ID = 2 and SFKSXS = 1 and (BType = 'C' or BType = 'U')");
}
else if (f.Equals("Cheap")) //특가도서
{
iData[] = new SqlParameter("@Where", "SFGDTS = 1 and SFKSXS = 1 and (r.BType = 'C' or BType = 'U')");
} else
{
iData[] = new SqlParameter("@Where", "(BType = 'C' || BType = 'U') and SFKSXS = 1");
}
break; default:
iData[] = new SqlParameter("@Where", "");
break; }
iData[] = new SqlParameter("@Order", "SCSJ desc");
iData[] = new SqlParameter("@SortType", "");
iData[] = new SqlParameter("@RecorderCount", "");
iData[] = new SqlParameter("@PageSize", pageSize);
iData[] = new SqlParameter("@PageIndex", pageIndex);
iData[] = new SqlParameter("@TotalCount", );
iData[] = new SqlParameter("@TotalPageCount", ); iData[].Direction = ParameterDirection.Output;
iData[].Direction = ParameterDirection.Output; return Dao.GetBookDefault(iData, out total, out page);
}

====================================陆续更新=======================================

SQL 语句整理的更多相关文章

  1. 一个项目涉及到的50个Sql语句(整理版)

    /* 标题:一个项目涉及到的50个Sql语句(整理版) 说明:以下五十个语句都按照测试数据进行过测试,最好每次只单独运行一个语句. */ --1.学生表Student(S,Sname,Sage,Sse ...

  2. 常用sql语句整理:mysql

    ## 常用sql语句整理:mysql1. 增- 增加一张表```CREATE TABLE `table_name`(  ...  )ENGINE=InnoDB DEFAULT CHARSET=utf8 ...

  3. Oracle数据库常用的Sql语句整理

    Oracle数据库常用的Sql语句整理 查看当前用户的缺省表空间 : select username,default_tablespace from user_users; 2.查看用户下所有的表 : ...

  4. 常用的一些SQL语句整理,也许有你想要的。

    本篇文章是对一些常用的sql语句进行了总结与分析,需要的朋友参考下,也许会有你需要的. 1.SQL行列转换 问题:假设有张学生成绩表(tb)如下:姓名 课程 分数张三 语文 74张三 数学 83张三 ...

  5. SQL语句整理(二) 数据定义语言DDL

    前言: 这是我学数据库时整理的学习资料,基本上包括了所以的SQL语句的知识点. 我的教材是人大王珊老师的<数据库系统概论>. 因为是手打的,所以会用一些细节打错了,但都挺明显也不多(考完试 ...

  6. SQL语句整理(一) 数据库查询语言DQL

    前言: 这是我学数据库时整理的学习资料,基本上包括了所以的SQL语句的知识点. 我的教材是人大王珊老师的<数据库系统概论>. 因为是手打的,所以会用一些细节打错了,但都挺明显也不多(考完试 ...

  7. 疑难杂症 - SQL语句整理

    一.关联子查询-查日期最新列 前天在工作中遇到一条非常有用的SQL语句,想了好久愣是没搞出来.今天将这个问题模拟出来:先看表 需求是,对于每个人,仅显示时间最新的那一条记录. 答案如下: select ...

  8. EBS系统管理常用SQL语句整理汇总(参考网上资料&其他人博客)

    --1查找系统用户基本信息 SELECT user_id, user_name, description, employeE_id, person_party_id FROM fnd_user; -- ...

  9. MySQL的一些常用的SQL语句整理

    安装MySQL有两种的方式,一种是解压版本,但是需要配置环境变量,相对而言比较麻烦.所以我们一般采取第二种方式,那就是到MySQL的官网上下载安装版.这样就会省去很多麻烦,在这里我就不再详细的介绍具体 ...

  10. MSSQL注入常用SQL语句整理

    很多情况下使用工具对mssql注入并不完善,所以我们就需要手工注入,一下是本人收集的一些mssql的sql语句. 手工MSSQL注入常用SQL语句 and exists (select * from ...

随机推荐

  1. #include <boost/unordered_set.hpp>

    boost.unordered在C++标准容器std::set,std::multiset,std::map和std::multimap的基础上多实现了四个容器:boost::unordered_se ...

  2. android卸载反馈实现

    博客原地址:http://blog.csdn.net/wang_shaner/article/details/41543787 实现原理 fork分叉函数 fork分叉(分裂)函数可以创建一个新进程, ...

  3. RHEL5.8安装Oracle11g

    1.安装环境[root@rusky-oracle11g ~]# uname -r2.6.18-308.el5[root@rusky-oracle11g ~]# cat /etc/issueRed Ha ...

  4. mvn profile 深层次目录打参数核心配置

    <build> <resources> <resource> <directory>src/main/resources</directory&g ...

  5. javascript 兼容各个浏览器的事件

  6. document.createElement()的用法

    今天做项目需要做个添加地址栏和前面需要一个按钮,就看到了这篇文章! document.createElement()是在对象中创建一个对象,要与appendChild() 或 insertBefore ...

  7. HTML代码中<%%>、<%=%>、<%:%>各是什么意思?分别用来实现什么的?

    运行.获取后台代码或值.<%%>之间可以写服务器端代码,比如 <% for(var i=0;i<10;i++){ //执行循环体 } %> 又如 <% for(va ...

  8. jsp页面适应手机页面

    <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scal ...

  9. EC读书笔记系列之19:条款49、50、51、52

    条款49 了解new-handler的行为 记住: ★set_new_handler允许客户指定一个函数,在内存分配无法获得满足时被调用 ★Nothrow new是一个颇为局限的工具,∵其只适用于内存 ...

  10. js:关于IE6/7下new Date(值)输出为NaN的解决方案

    不得不再次说,万恶的IE,你太守旧了吧,这里出错的原因是IE的时间格式,不是2012-01-23(很多人喜欢用这样的格式) 而是2012/01/23(怎么感觉像是在用VB6和access啊) 搞了好久 ...