Select语句头快爆炸!高手指点!

xxd88 2008-09-19 08:43:04
Gridview结构:
审核部门 审核状态 审核人 通过审核日期
Users表结构:
UserName…………..UserBm…………LxSh……….
LxSh表结构:
…………..BmName………...UserName……..TgTime

问题:
想实现在Gridview中的“审核部门”列显示Users表中的LxSh=1的distinct(UserBm)列。
GridView中的“审核状态”列显示如果LxSh表中BmName=User.UserBm那么该行显示“通过审核”否则显示“没通过审核”。
GridView中的“审核人”和“通过审核日期”两列,如果“审核状态”列为“通过审核”则分别显示LxSh表中的UserName和TgTime如果“审核状态”为“没通过审核”这两列则显示“无”。
这样的邦定GridView的select语句我该怎么写!!!
...全文
116 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxd88 2008-09-19
  • 打赏
  • 举报
回复
通过gridview列的绑定事件来处理!!
获得表的所有记录!!
然后判断审核状态!!
这些我知道!
我就是不知道怎么取数据!
Select *, distinct(UserBm)from Users As a Join Left LxSh As b On a.UserBm=b.BmName where a.LxSh
='1' 写不行该怎么写!!!!
cco3322 2008-09-19
  • 打赏
  • 举报
回复
你又是*,又是distinct的,矛盾不??

想玩死MS SQL server啊??
xxd88 2008-09-19
  • 打赏
  • 举报
回复
Select *, distinct(UserBm)from Users As a Join Left LxSh As b On a.UserBm=b.BmName where a.LxSh
='1'
这样获取整个数据吗?
但好像不可以
lovehongyun 2008-09-19
  • 打赏
  • 举报
回复
RowDataBound绑定事件中判断一下即可.


或是sql中就处理.

利用case when

cco3322 2008-09-19
  • 打赏
  • 举报
回复
oracle:


select u.username,u.userbm,u.lxsh,l.bmname,
case when l.bmname is null then '没通过审核' else '通过审核' end,
case when l.bmname is null then'无' elsel.username end,
case when l.bmanme is null then'无' else l.tgtime end
from users u,lxsh l
where l.bmname = u.userbm(+)

关键字:
外连接
case when .. then .. else .. end
shulei521 2008-09-19
  • 打赏
  • 举报
回复
可以判断审核状态
if (审核状态通过)
{
全部显示
}
if (审核状态没通过)
{
this.WaterGridView1.Columns[0].Visible = fasle;
this.WaterGridView1.Columns[1].Visible = fasle;
}
隐藏对应的gridview列
编程有钱人了 2008-09-19
  • 打赏
  • 举报
回复

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType==DataControlRowType.DataRow)
{

if (e.Row.Cells[4].Text.Trim() == "0")
{
e.Row.Cells[4].Text = "<font color=red>隐藏</font>";
}
else
{
e.Row.Cells[4].Text = "公开";
}
if (e.Row.Cells[5].Text.Trim() == "0")
{
e.Row.Cells[5].Text = "<font color=red>新留言</font>";
}
else
{
e.Row.Cells[5].Text = "已回复";
}

}
}
yagebu1983 2008-09-19
  • 打赏
  • 举报
回复
通过gridview列的绑定事件来处理!!
获得表的所有记录!!
然后判断审核状态!!
代码自己写!!
xxd88 2008-09-19
  • 打赏
  • 举报
回复
LxSh字段代表用户是否有一个功能的权限!
当LxSh=1时就代表有权限等于0时表示没权限
cco3322 2008-09-19
  • 打赏
  • 举报
回复
再者,你能不能把你表里字段给个简单注释,我猜了半天没猜出来你那个LxSh字段是做什么用的

害得我又掉了2根头发,干~~
cco3322 2008-09-19
  • 打赏
  • 举报
回复
如果遇到自认古怪的需求,并且数据量不大的情况下

一个简单的办法:循环遍历,单独处理

以你说的情况,先用检索条件缩小范围,再对结果进行处理



早上起来还不清醒 没仔细看 过会再看看

62,046

社区成员

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

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

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

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