27,579
社区成员
发帖
与我相关
我的任务
分享
declare @t varchar(10)
set @t='A'
select No, msg ,(case @A when fname then hostname else fname) name , time from tb
where (fname=@A and hostname<>@A)
or (fname<>@A and hostname=@A)
declare @a table(No INT, msg VARCHAR(20), fname VARCHAR(20), hostname VARCHAR(20), TIME DATETIME)
insert @a select 1, NULL ,'A', 'B', '2010-06-09 23:52:39.903'
union all select 2, NULL ,'A', 'C', '2010-06-09 23:52:39.937'
union all select 3, NULL ,'C', 'B', '2010-06-09 23:53:22.450'
union all select 4, NULL ,'D', 'A', '2010-06-09 23:54:53.403'
union all select 5, NULL ,'C', 'A', '2010-06-09 23:58:53.140'
DECLARE @b CHAR(1)
SET @b='A'
SELECT No,msg,isnull(NULLIF(fname,@b),'')+isnull(NULLIF(hostname,@b),'') NAME, TIME
FROM @a WHERE CHARINDEX(@b,fname+hostname)>0
--result
/*No msg NAME TIME
----------- -------------------- ------------------------------ ------------------------------
1 NULL B 2010-06-09 23:52:39.903
2 NULL C 2010-06-09 23:52:39.937
4 NULL D 2010-06-09 23:54:53.403
5 NULL C 2010-06-09 23:58:53.140
(所影响的行数为 4 行)
*/
declare @t varchar(10)
set @t='A'
select * from tb
where (fname=@A and hostname<>@A)
or (fname<>@A and hostname=@A)