请教一个把ID转换成name的问题~

来源:百度知道 编辑:UC知道 时间:2024/06/04 04:24:12
ChatLog 表是这样的
charid charname chatdata chattime

2 NULL(空的) 你好啊 12:10
3 李 好~ 12:10
2 NULL(空的) 在干什么 12:10
2 张 没 12:10
3 NULL(空的) ```` 12:10
2 张 ```` 12:10
......................................这个表后面还有很多数据

<!--#include file="./incc/chatlogdx.asp" -->
<%
set rs2=server.CreateObject("adodb.recordset")
sql2="SELECT TOP 200 * FROM ChatLog WHERE chattype=5 ORDER BY row deSC"
rs2.open sql2,conn2,1,1

%>

<style type="text/css">
<!--
body {
background-color: #f1d277;
}
-->
</style>
<style type="text/css">
<!--
.STYLE6 {font-size: 12px}
-->
</style>
<%do while not rs2.

因为chatlog里面不是每一行都有charname,建议你建一张id charname的视图,然后用联合查询。

建立试图:
create view charname as
select distinct charid, charname from chatlog where charname is not null;

建立视图之后的联合查询语句:
SELECT TOP 200 chatlog.charid, charname.charname, chatlog.chatdata, chatlog.chattime FROM ChatLog LEFT OUTER JOIN charname WHERE chatlog.chattype=5 AND chatlog.charid = charname.charid ORDER BY row deSC