22,209
社区成员
发帖
与我相关
我的任务
分享
'select * from 表 where D <> 0 and A like''%张三%'' and B=10 or C=10'
if OBJECT_ID('tempdb..#temp', 'u') is not null drop table #temp;
go
create table #temp( [A] varchar(100), [B] varchar(100), [C] varchar(100), [D] varchar(100));
insert #temp
select '张三','10','0','' union all
select '张三','0','10','' union all
select '李四','10','0','' union all
select '王五','10','10','' union all
select '赵六','0','10','' union all
select '孙七','20','20',''
--SQL:
select * from #temp where D <> '0' and A LIKE '%张三%' and (B=10 or C=10)
/*
A B C D
张三 10 0
张三 0 10
*/
create table #a(A varchar(10),B int,C int,D int)
insert into #a(A,B,C)
select '张三',10,0
union all select '张三',0,10
union all select '李四',10,0
union all select '王五',10,10
union all select '赵六',0,10
union all select '孙七',20,20
select * from #a
where A='张三'
/*
A B C D
-------------------------
张三 10 0 NULL
张三 0 10 NULL
*/
Declare @table table(A nvarchar(10),B int ,C int ,D int)
insert @table
select N'张三', 10, 0,null union all
select N'张三', 0,10,null union all
select N'李四', 10, 0,null union all
select N'王五', 10,10,null union all
select N'赵六', 0,10,null union all
select N'孙七', 20,20,null
select *
from @table t
where t.A like '%张三%'
--and (t.B=10 or t.C=10)--B和C 判断 根据你的需要 是否要添加吧
/*
A B C D
张三 10 0 NULL
张三 0 10 NULL
*/