select * from tabTest
WHERE LikeNum(c1+c2+c3+c4+c5,'B')=2其中likenum為自定義函數。
WHERE LikeNum(c1+c2+c3+c4+c5,'B')=2其中likenum為自定義函數。
解决方案 »
- 在VC里用SQL语句多重查询的问题。
- sqlserver2005怎么创建复合主键的?
- pwdencrypt函数的问题
- 分组求出合计的问题??
- 一个很简单的问题,刚学触发器,大家给看看
- 问个语句
- 关于telnet 1433 远程访问MSSQL2000 的疑难问题!!求高手!分不够可以加!加钱都行!!!
- 急!我的这个update该怎么写
- 作为一个数据库开发人员,首先从哪儿入手sql server 2000
- 一个关于游标使用的逻辑问题(高手请入,解决立即给分)
- 谁来帮帮我????????Thank you!!!!!!!!!!!!!!!!!!!!!!!!
- 在从DataGrid修改数据时,怎么样能同步更新数据库中内容!!
where case c1 when 'B' then 1 else 0 end
+case c2 when 'B' then 1 else 0 end
+case c3 when 'B' then 1 else 0 end
+case c4 when 'B' then 1 else 0 end
+case c5 when 'B' then 1 else 0 end
=2
create table tabletest(id int,c1 char(1),c2 char(1),c3 char(1),c4 char(1),c5 char(1))
insert tabletest
select 1,'A','B','A','B','C'
union all select 2,'B','B','B','A','C'
union all select 3,'B','C','C','B','A'
union all select 4,'C','A','A','B','B'
union all select 5,'A','C','A','B','C'
go--查询
select * from tabletest
where case c1 when 'B' then 1 else 0 end
+case c2 when 'B' then 1 else 0 end
+case c3 when 'B' then 1 else 0 end
+case c4 when 'B' then 1 else 0 end
+case c5 when 'B' then 1 else 0 end
=2
go--删除测试
drop table tabletest/*--测试结果
id c1 c2 c3 c4 c5
----------- ---- ---- ---- ---- ----
1 A B A B C
3 B C C B A
4 C A A B B(所影响的行数为 3 行)
--*/
from tabTest
where (case when c1='B' then 1 else 0 end
+when c2='B' then 1 else 0 end
+when c3='B' then 1 else 0 end
+when c4='B' then 1 else 0 end
+when c5='B' then 1 else 0 end )=2
-- DROP FUNCTION dbo.likenum
CREATE FUNCTION dbo.likenum(@vchMainString varchar(1000),@vchChildString varchar(100))
RETURNS int
AS
BEGIN
DECLARE @intCount int
DECLARE @intStart int
DECLARE @intChildLength int
SET @intCount=0
SET @intStart=1
SET @intChildLength=ISNULL(LEN(@vchChildString),0) WHILE( CHARINDEX(@vchChildString,@vchMainString,@intStart)>0)
BEGIN
SET @intStart= CHARINDEX(@vchChildString,@vchMainString,@intStart)+@intChildLength
SET @intCount=@intCount+1
END RETURN(@intCount)END
from tabTest
where len(isnull(c1,'') + isnull(c2,'') + isnull(c3,'') + isnull(c4,'') + isnull(c5,'')) - len(replace(isnull(c1,'') + isnull(c2,'') + isnull(c3,'') + isnull(c4,'') + isnull(c5,''),'b',''))=2