--where子句可以进行优化
--首先查询条件可以合并
--where子句是短路匹配,所以,应该先进行IsPass=1 and IsDel=0再进行字符串匹配
--字符串匹配,我改了一下。希望我的意思,你能看懂
declare @ColumnCode varchar(100)
set @ColumnCode='..'
where IsPass=1 and IsDel=0
or @ColumnCode in (left(columnCode, len(@ColumnCode)),
left(columnCode2, len(@ColumnCode)),
left(columnCode3, len(@ColumnCode)))
select TOP 11 *
from (
SELECT TOP 11 [ID],COLUMNID,COLUMNNAME,TITLE,TCOLOR,AddDate,IsImg,IsTop,isDown
FROM [Content]
//****WHERE (ColumnCode like '"&ColumnCode&"%' and IsPass=1 and IsDel=0)
//****or (ColumnCode2 like '"&ColumnCode&"%' and IsPass=1 and IsDel=0)
//****or (ColumnCode3 like '"&ColumnCode&"%' and IsPass=1 and IsDel=0) "
where (ColumnCode like '"&ColumnCode&"%' or ColumnCode2 like '"&ColumnCode&"%' or ColumnCode3 like '"&ColumnCode&"%' ) and IsPass=1 and IsDel=0
sql=sql&" union all "
sql=sql&"
SELECT TOP 11 [ID],COLUMNID,COLUMNNAME,TITLE,TCOLOR,AddDate,IsImg,IsTop,isDown
FROM [DownContent]
WHERE (ColumnCode like '"&ColumnCode&"%'
or ColumnCode2 like '"&ColumnCode&"%'
or ColumnCode3 like '"&ColumnCode&"%' )
and IsPass=1 and IsDel=0)
) "
sql=sql& "a order by AddDate desc,id desc"兄弟用这个试试可以的话给个回答