自娱自乐

本人收藏的一些文章,供学习使用
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

(原创)多关键字查询

Posted on 2007-11-06 23:24  lwjacky  阅读(315)  评论(0编辑  收藏  举报

select DownloadTypeName,DownloadTypeDesc,SelectWord,ParentID,DownloadTypeLevel,IsLeaf,IDTree,MasterID,AddDate,ReleaseDate,iLanguage into Test from DS_DownloadType where SelectWord like '%测试%' and Isleaf=1
insert into Test select DownloadTypeName,DownloadTypeDesc,SelectWord,ParentID,DownloadTypeLevel,IsLeaf,IDTree,MasterID,AddDate,ReleaseDate,iLanguage from DS_DownloadType where (DownloadTypeID not in (select DownloadTypeID from DS_DownloadType where SelectWord like '%测试%' and Isleaf=1) and isleaf=1)
ALTER TABLE Test ADD TempID INT IDENTITY(1,1)
select * from Test order by TempID
drop table Test

ALTER PROCEDURE DS_GetDataList_SelectKeyWord
 (
  @strWhere1 varchar(1500) = '', -- 或查询条件 (注意: 不要加 where)SelectWord like '%测试%' or SelectWord like '%手机%'
  @strWhere2 varchar(1500) = ''  -- 与查询条件 (注意: 不要加 where)SelectWord like '%测试%' and SelectWord like '%手机%'
 )
AS
 declare @strSQL varchar(5000) -- 主语句
 declare @strTmp varchar(1000) -- 临时变量

set @strSQL = 'select DownloadTypeName,DownloadTypeDesc,SelectWord,ParentID,DownloadTypeLevel,IsLeaf,IDTree,MasterID,AddDate,ReleaseDate,iLanguage into DS_Test from DS_DownloadType where DownloadTypeID not in (select DownloadTypeID from DS_DownloadType where ('+ @strWhere1 +') and Isleaf=1) and isleaf=1'
exec (@strSQL)

set @strSQL = 'insert into DS_Test select DownloadTypeName,DownloadTypeDesc,SelectWord,ParentID,DownloadTypeLevel,IsLeaf,IDTree,MasterID,AddDate,ReleaseDate,iLanguage from DS_DownloadType where ('+ @strWhere2 +') and Isleaf=1'
exec (@strSQL)

set @strSQL = 'insert into DS_Test select DownloadTypeName,DownloadTypeDesc,SelectWord,ParentID,DownloadTypeLevel,IsLeaf,IDTree,MasterID,AddDate,ReleaseDate,iLanguage from DS_DownloadType where ('+ @strWhere1 +') and not ('+ @strWhere2 +') and Isleaf=1'
exec (@strSQL)

exec ('ALTER TABLE DS_Test ADD TempID INT IDENTITY(1,1)')
exec ('select * from DS_Test order by TempID')
exec ('drop table DS_Test')