易截截图软件、单文件、免安装、纯绿色、仅160KB

Linq to SQL Like Operator(转载)


As a response for customer's question, I decided to write about using Like Operator in Linq to SQL queries.
Starting from a simple query from Northwind Database;
var query = from c in ctx.Customers
            where c.City == "London"
            select c;
The query that will be sent to the database will be:
SELECT CustomerID, CompanyName, ...
from    dbo.Customers
WHERE  City = [London]
There are some ways to write a Linq query that reaults in using Like Operator in the SQL statement:
1. Using String.StartsWith or String.Endswith
Writing the following query:
var query = from c in ctx.Customers
            where c.City.StartsWith("Lo")
            select c;
will generate this SQL statement:
SELECT CustomerID, CompanyName, ...
from    dbo.Customers
WHERE  City LIKE [Lo%]
which is exactly what we wanted. Same goes with String.EndsWith.
But, what is we want to query the customer with city name like "L_n%"? (starts with a Capital 'L', than some character, than 'n' and than the rest of the name). Using the query
var query = from c in ctx.Customers
            where c.City.StartsWith("L") && c.City.Contains("n")
            select c;
generates the statement:
SELECT CustomerID, CompanyName, ...
from    dbo.Customers
WHERE  City LIKE [L%]
AND      City LIKE [%n%]
which is not exactly what we wanted, and a little more complicated as well.
2. Using SqlMethods.Like method
Digging into System.Data.Linq.SqlClient namespace, I found a little helper class called SqlMethods, which can be very usefull in such scenarios. SqlMethods


相关文档:

SQL 数据库生成自动编号代码

--exec  [P_AutoGenerateNumber]  'reception_apply','generate_code','',7
/*
 过程说明:生成自动编号 
 创建时间:2010年1月12日
 作者:feng
 debug:尚未考虑编号溢出情况
*/ 
ALTER proc [P_AutoGenerateNumber]
  (
  @table ......

如何连接SQL Server数据库(Java版)

用Java连接SQL Server2000数据库有多种方法,下面介绍其中最常用的两种(通过JDBC驱动连接数据库)。
1. 通过Microsoft的JDBC驱动连接。此JDBC驱动共有三个文件,分别是mssqlserver.jar、msutil.jar和msbase.jar,可以到微软的网站去下载(http://www.microsoft.com/downloads/details.aspx?FamilyId=07287B11-0502-461A-B ......

总结经典常用的SQL语句(1)

说明:复制表(只复制结构,源表名:a 新表名:b)  
  SQL: select * into b from a where 1<>1
  说明:拷贝表(拷贝数据,源表名:a 目标表名:b)  
  SQL: insert into b(a, b, c) select d,e,f from b;
  说明:显示文章、提交人和最后回复时间  
  SQL: select a.title,a.username,b ......

SQL分页方法

表中主键必须为标识列,[ID] int IDENTITY (1,1)
也可以使用联合主键 id+id2+id3+……
 
1.分页方案一:(利用Not In和SELECT TOP分页)
语句形式:  
SELECT TOP 10 *
from TestTable
WHERE (ID NOT IN
          (SELECT TOP 20 id
&nb ......

【Oracle】SQL优化的重要工具 AUTOTRACE

【AUTOTRACE】SQL优化的重要工具--AUTOTRACE
提到SQL优化,不能不提AUTOTRACE的强大功能。使用起来非常便捷,不过在是使用之前,需要做一些配置的工作。简要的描述一下这个过程,供没有使用过的朋友参考。
1.使用sys用户执行plustrce脚本
sys@ora10g> @?/sqlplus/admin/plustrce
sys@ora10g> drop role plustrace ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号