SQL 语句整理
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 语句整理的更多相关文章
- 一个项目涉及到的50个Sql语句(整理版)
/* 标题:一个项目涉及到的50个Sql语句(整理版) 说明:以下五十个语句都按照测试数据进行过测试,最好每次只单独运行一个语句. */ --1.学生表Student(S,Sname,Sage,Sse ...
- 常用sql语句整理:mysql
## 常用sql语句整理:mysql1. 增- 增加一张表```CREATE TABLE `table_name`( ... )ENGINE=InnoDB DEFAULT CHARSET=utf8 ...
- Oracle数据库常用的Sql语句整理
Oracle数据库常用的Sql语句整理 查看当前用户的缺省表空间 : select username,default_tablespace from user_users; 2.查看用户下所有的表 : ...
- 常用的一些SQL语句整理,也许有你想要的。
本篇文章是对一些常用的sql语句进行了总结与分析,需要的朋友参考下,也许会有你需要的. 1.SQL行列转换 问题:假设有张学生成绩表(tb)如下:姓名 课程 分数张三 语文 74张三 数学 83张三 ...
- SQL语句整理(二) 数据定义语言DDL
前言: 这是我学数据库时整理的学习资料,基本上包括了所以的SQL语句的知识点. 我的教材是人大王珊老师的<数据库系统概论>. 因为是手打的,所以会用一些细节打错了,但都挺明显也不多(考完试 ...
- SQL语句整理(一) 数据库查询语言DQL
前言: 这是我学数据库时整理的学习资料,基本上包括了所以的SQL语句的知识点. 我的教材是人大王珊老师的<数据库系统概论>. 因为是手打的,所以会用一些细节打错了,但都挺明显也不多(考完试 ...
- 疑难杂症 - SQL语句整理
一.关联子查询-查日期最新列 前天在工作中遇到一条非常有用的SQL语句,想了好久愣是没搞出来.今天将这个问题模拟出来:先看表 需求是,对于每个人,仅显示时间最新的那一条记录. 答案如下: select ...
- EBS系统管理常用SQL语句整理汇总(参考网上资料&其他人博客)
--1查找系统用户基本信息 SELECT user_id, user_name, description, employeE_id, person_party_id FROM fnd_user; -- ...
- MySQL的一些常用的SQL语句整理
安装MySQL有两种的方式,一种是解压版本,但是需要配置环境变量,相对而言比较麻烦.所以我们一般采取第二种方式,那就是到MySQL的官网上下载安装版.这样就会省去很多麻烦,在这里我就不再详细的介绍具体 ...
- MSSQL注入常用SQL语句整理
很多情况下使用工具对mssql注入并不完善,所以我们就需要手工注入,一下是本人收集的一些mssql的sql语句. 手工MSSQL注入常用SQL语句 and exists (select * from ...
随机推荐
- 【LeetCode练习题】Gas Station
Gas Station There are N gas stations along a circular route, where the amount of gas at station i is ...
- 灵活使用getconf命令来获取系统信息
http://blog.chinaunix.net/uid-23105261-id-109513.html 灵活使用getconf命令来获取系统信息 我们时常需要查询系统相关的信息,比如页面大小,整数 ...
- kindeditor 下图片链接取消边框
在项目中使用了 kindeditor,版本是4.1.10,在发布信息的时候,将图片设置成了超链接,在 IE8 或者其他个别浏览器下会自动的为图片加一个蓝色的边框,效果如下图: 这个蓝框可以通过修改信息 ...
- eclipse/myeclipse使用技巧
热键篇: Template:Alt + / 修改处:Window->Preference->Workbench->Keys->Command->Edit->Cont ...
- ExtJs3学习资料分享
最近在学习EXTJS3,在网上找了一些pdf的书.不过网上分享的有些书都是Ext2.0的.Ext3的比较少.有些书也不全.很多是样章.最近找到一本分享的书<ExtJS源码分析与开发实例宝典> ...
- BigDecimal用法详解(转)
BigDecimal用法详解 http://www.cnblogs.com/linjiqin/p/3413894.html 一.简介Java在java.math包中提供的API类BigDecim ...
- Windows中的句柄
(一)句柄 在程序设计中,句柄(handle)是一种特殊的智能指针.当一个应用程序要引用其他系统(如数据库.操作系统)所管理的内存块或对象时,就要使用句柄. 句柄与普通指针的区别在于,指针包含的是引用 ...
- 图片与文字在div里实现垂直水平都居中
第一种方法,利用盒布局实现 <style type="text/css">/*盒布局实现图片与文字水平垂直居中*/ .div1{ width: 100%; heig ...
- Android _优雅实现元素间的分割线 (支持3.0以下)
转:http://blog.csdn.net/lmj623565791/article/details/42407923 1.概述 话说,随着Android SDK版本的升级,很多控件增加了新的属性方 ...
- thinkphp批量删除的实现
今天自己在写后台的时候需要把以前上传的测试文章全部删除掉,但是利用 [操作]里面的一个个删除比较慢,因此想出一个批量删除的解决方案. 首先在前端页面里面建立一个表单,这个表单是把你选中的单选按钮提交到 ...