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 ...
随机推荐
- C errors recods
error: unterminated #ifndef 1,权限问题 2,少了#endif
- 【C/C++】Linux下使用system()函数一定要谨慎
[C/C++]Linux下使用system()函数一定要谨慎 http://my.oschina.net/renhc/blog/53580 曾经的曾经,被system()函数折磨过,之所以这样,是因为 ...
- 网易云课堂_C++程序设计入门(上)_第4单元:物以类聚 – 对象和类_第4单元作业【3】- 在线编程(难度:难)
1 在本单元作业[1]和作业[2]的基础上,创建一个MyRectangle类,并在main函数中创建类的实例.(10分) 题目难度: 难 题目内容: Screen类: 与作业[2]要求完全相同. 如果 ...
- Swift流程控制之循环语句和判断语句详解
Swift提供了所有c类语言的控制流结构.包括for和while循环来执行一个任务多次:if和switch语句来执行确定的条件下不同的分支的代码:break和continue关键字能将运行流程转到你代 ...
- 《面试题精选》15.O(logn)求Fibonacci数列
题目:定义Fibonacci数列例如以下: / 0 n=0 f(n)= 1 n=1 ...
- 浅谈web前端就业的学习路线
初级前端 主要学习三个部分:HTML,CSS,JavaScript 一.html + css部分: 这部分特别简单,到网上搜资料,书籍视频非常多.css中盒子模型,流动,block,inline,层叠 ...
- Vim 扩展工具 vim-ide (转)
通过简单的配置文件将 vim 打造成专业 ide,支持 mac linux cygwin.看过数篇 vim 配置文件,必要时去定制vim 的插件,将 vim 的 ide 用户体验尽量做到极致. 使用范 ...
- 重新理解一遍UpdatePanel
楼主只是想每天写点东西这样帮助自己的一个累积吧. 说明:楼主现在已经清楚了AJAX是怎么回事了,现在由于工作原因又摆弄起了UpdatePanel所以从AJAX的角度来分析一下UpdatePanel的使 ...
- mysql5.7慢查询开启配置
1.问题 当然又被度娘(我冤枉)坑了噻,网友说配置文件写下面三行: log-slow-queries=D:\Program Files\mysql-5.7.11-winx64\data\low.log ...
- Go语言AST尝试
Go语言有很多工具, goimports用于package的自动导入或者删除, golint用于检查源码中不符合Go coding style的地方, 比如全名,注释等. 还有其它工具如gorenam ...