SQL问题欢迎来看

jlcs2002 2011-04-22 12:00:19

谢谢认真的看完
select top(" + paramTopNote + ") id,BatchID,GenTime,Mobile, prov, city, case when MsgContent is null then (select MsgContent from MsgBatchID where MsgBatchID.BatchID = MsgTasks.BatchID) else MsgContent end as MsgContent,Prior,MobileRange,MobileRange2,UserID,"
+ " case when IsSending=1 then '是' else '否' end as IsSending, case when convert(varchar(50),SendServerID)='-1' then '无' else convert(varchar(50),SendServerID) end as SendServerID,SendOK,IsTest "
+ " from MsgTasks where sendok <> 1 "
+ " and id not in("
+ " select top(" + paramNotTopNote + ") id "
+ " from View_MsgTasks where sendok <> 1 and ( " + strSqlAndUserID + " " + strSqlAnd + " " + paramTextContent + ") order by id desc ) and ( " + strSqlAndUserID + " " + strSqlAnd + "" + paramTextContent + ") order by id desc";

这可以得到一个新表显示id,BatchID,GenTime,Mobile, prov, city, MsgContent 。。。。。。
我想把里面的MsgContent这个字段的内容取出来进行 内容模糊查询 string sqlLike="MsgContent Like'%"+变量+"%'";
这个应该加在哪里啊 内容只显示 跟内容相似的内容....谢谢




...全文
196 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
laowang134 2011-04-22
  • 打赏
  • 举报
回复

"select top(" + paramTopNote + ") id,BatchID,GenTime,Mobile, prov, city, case when MsgContent is null then (select MsgContent from MsgBatchID where MsgBatchID.BatchID = MsgTasks.BatchID) else MsgContent end as MsgContent,Prior,MobileRange,MobileRange2,UserID,"
+ " case when IsSending=1 then '是' else '否' end as IsSending, case when convert(varchar(50),SendServerID)='-1' then '无' else convert(varchar(50),SendServerID) end as SendServerID,SendOK,IsTest "
+ " from MsgTasks where sendok <> 1 and MsgContent Like'%"+变量+"%'"
+ " and id not in("
+ " select top(" + paramNotTopNote + ") id "
+ " from View_MsgTasks where sendok <> 1 and ( " + strSqlAndUserID + " " + strSqlAnd + " " + paramTextContent + ") order by id desc ) and ( " + strSqlAndUserID + " " + strSqlAnd + "" + paramTextContent + ") order by id desc";


qq346127416 2011-04-22
  • 打赏
  • 举报
回复
MsgContent 是 MsgTasks 里的
还是View_MsgTasks 里的
mayanly 2011-04-22
  • 打赏
  • 举报
回复
再加一个条件
and MsgContent Like'%"+变量+"%'"
laowang134 2011-04-22
  • 打赏
  • 举报
回复
跟上面的有什么不一样么。。
Lisliefor 2011-04-22
  • 打赏
  • 举报
回复
你这个问题在于对于MsgContent 为空的时候,有一个从其他表查询的特殊处理,如果你把sqlLike="MsgContent Like'%"+变量+"%'"加在后面,sql会提示MsgContent列名无效。

这样写,在外层再套一个查询。

seect id,BatchID,GenTime,Mobile, prov, city,MsgContent,Prior,MobileRange,MobileRange2,UserID,IsSending,SendServerID,SendOK,IsTest
from (
-- 这里写你的上面贴的查询语句
)
where MsgContent like '%' + 变量 + '%'

这样应该就OK了。

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧