22,209
社区成员
发帖
与我相关
我的任务
分享
declare @Table_chanpin table( ID int,名称 varchar(20),上传时间 datetime, photoinfo varchar(20))
insert @Table_chanpin select
1 , '散热器' , '2009-8-17', '好用' union all select
2 , '隔膜阀' , '2009-8-17' , '真好用' union all select
3 , '配液罐' , '2009-8-17' , '真好用' union all select
4 , '止回阀', '2009-8-17' , '卫生级'
declare @key varchar(20)
set @key='阀'
select * from @Table_chanpin where 名称 like '%'+@key+'%'
ID 名称 上传时间 photoinfo
----------- -------------------- ----------------------- --------------------
2 隔膜阀 2009-08-17 00:00:00.000 真好用
4 止回阀 2009-08-17 00:00:00.000 卫生级
(2 行受影响)
想要什么结果?
--> 测试数据:[ta]
if object_id('[ta]') is not null drop table [ta]
go
create table [ta]([ID] int,[名称] varchar(6),[上传时间] datetime,[photoinfo] varchar(6))
insert [ta]
select 1,'散热器','2009-8-17','好用' union all
select 2,'隔膜阀','2009-8-17','真好用' union all
select 3,'配液罐','2009-8-17','真好用' union all
select 4,'止回阀','2009-8-17','卫生级'
select * from [ta]
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([ID] int,[名称] varchar(10),[上传时间] datetime,[photoinfo] varchar(6))
insert [tb]
select 1,'纯水罐','2009-8-17','好用' union all
select 2,'球形浓缩罐','2009-8-17','真好用' union all
select 3,'呼吸器','2009-8-17','真好用' union all
select 4,'酒精回收塔','2009-8-17','卫生级'
----------------查询开始---------------------
select * from [ta] a where a.名称 like '%罐%'
union all
select * from [tb] b where b.名称 like '%罐%'
/*
ID 名称 上传时间 photoinfo
----------- ---------- ----------------------- ---------
3 配液罐 2009-08-17 00:00:00.000 真好用
1 纯水罐 2009-08-17 00:00:00.000 好用
2 球形浓缩罐 2009-08-17 00:00:00.000 真好用
(3 行受影响)
*/
EXEC('select distinct a.名称,b.名称,a.ID,b.ID,a.上传时间,b.上传时间,a.photoinfo,b.photoinfo from Table_chanpin a, Table_chanpin2 b where a.名称 like ''%' + [key] + '%'' or b.名称 like ''%' + [key] + '%''')
"select distinct a.名称,b.名称,a.ID,b.ID,a.上传时间,b.上传时间,a.photoinfo,b.photoinfo from Table_chanpin a, Table_chanpin2 b where a.名称 like '%'" + key + "'%' or b.名称 like '%'" + key + "'%'";
]"select distinct a.名称,b.名称,a.ID,b.ID,a.上传时间,b.上传时间,a.photoinfo,b.photoinfo from Table_chanpin a, Table_chanpin2 b where a.名称 like '%"' + key + '"%' or b.名称 like '%"' + key + '"%'";
???string sqlstr = "select distinct a.名称,b.名称,a.ID,b.ID,a.上传时间,b.上传时间,a.photoinfo,b.photoinfo from Table_chanpin a, Table_chanpin2 b where a.名称 like '%" + key + "%' or b.名称 like '%" + key + "%'";