select A from Table where A like '%你要查的内容%' union select B from Table where B like '%你要查的内容%' union select C from Table where C like '%你要查的内容%'
半精确查找: select A , B , C from (Select A , B , C , O = case when CharIndex('Word' , A) > 0 then 1 when CharIndex('Word' , B) > 0 then 2 when CharIndex('Word' , C) > 0 then 3 end from TableName where A like 'Word' or B like 'Word' or C like 'Word') TX order by O
select A , B , C from ( select A , B , C , O = 1 from TableName where A like '%xxx%' union select A , B , C , O = 2 from TableName where B like '%xxx%' and A not like '%xxx%' union select A , B , C , O = 3 from TableName where C like '%xxx%' and A not like '%xxx%' and B not like '%xxx%' ) TX order by O
select B from Table where B like '%你要查的内容%' union
select C from Table where C like '%你要查的内容%'
select A , B , C from
(Select A , B , C , O = case
when CharIndex('Word' , A) > 0 then 1
when CharIndex('Word' , B) > 0 then 2
when CharIndex('Word' , C) > 0 then 3
end
from TableName where A like 'Word' or B like 'Word' or C like 'Word') TX order by O
(
select A , B , C , O = 1 from TableName where A like '%xxx%' union
select A , B , C , O = 2 from TableName where B like '%xxx%' and A not like '%xxx%' union
select A , B , C , O = 3 from TableName where C like '%xxx%' and A not like '%xxx%' and B not like '%xxx%'
) TX order by O
CBUILDER兄说声感谢,连分都忘了给呢? :)
另外,zhq2000的SQL语句中,不能选择text、ntext,image的列,而我恰恰需要选择这样的列,我做了试验,发现是union的问题,请指教!
另外,zhq2000的SQL语句中,不能选择text、ntext,image的列,而我恰恰需要选择这样的列,我做了试验,发现是union的问题,请指教!