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

多字段模糊查询sql like %% 优化与区别

多字段模糊查询sql like %% 优化与区别
http://anforen.5d6d.com/
SELECT *
  from [KLims].[dbo].[Task] 
where  ClientCompany like '%a%' or [Address] like '%a%'
SELECT *
  from [KLims].[dbo].[Task] 
where  ClientCompany + [Address] like '%a%'
但当其中一字段为null时,用第二种会找不到数据。
http://four-corner.appspot.com/
因为当某一字段为null时,拼接的字段整体都为null,要让第二种办法可以使用,可以这样写,将为null的字段,替换为'';
SELECT *
  from [KLims].[dbo].[Task] 
where  isnull(ClientCompany,'') + isnull([Address],'') like '%a%'
这样既可正常执行,又高效。


相关文档:

SQL Server 数据格式修改时,没有保存按钮的情况解决

如果你使用的是 SQL Server 2008, 当你修改数据结构后,保存时会报下图情况: Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can't be re-created or enabled the option Prevent saving cha ......

从SQL数据库里随机读取一条记录



怎样从数据库里随机读取
一条记录,
SELECT TOP 1 * from dbo.Customers ORDER BY  NEWID()
这样,如果是随机10
条,100条。。。。
SELECT TOP 10 * from dbo.Customers ORDER BY  NEWID()
很简单吧。
不过top后面数字越大,运行速度越慢。不推荐数据字太大。
以后代码在SQL2000 ......

SQL Server的定序(Collation)

使用SQL Server的朋友們應該都知道SQL Server的資料庫有一個設定叫做定序(Collation),今天我們就來看看定序這東西是什麼,首先我們看一下Wiki上對定序的說明:
Collation is the assembly of written information into a sta ......

SQL中Case的使用方法(下篇)

接上篇
四,根据条件有选择的UPDATE。
例,有如下更新条件
工资5000以上的职员,工资减少10%
工资在2000到4600之间的职员,工资增加15%
很容易考虑的是选择执行两次UPDATE语句,如下所示
--条件1
UPDATE Personnel
SET salary = salary * 0.9
WHERE salary >= 5000;
--条件2
UPDATE Personnel
SET sala ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号