现在有数据表A和B:A表 B表
--------------------------- --------------------------
uid name topic uid
1 David xxxxx 1
2 Jack xxx 3
3 Mike xxxxxx 0经过存储过程处理后,得到这样一个表C:
C表
-------------------------
topic name
xxxxx David
xxx Mike
xxxxxx 匿名请问,这样的一个存储过程该怎么写?
--------------------------- --------------------------
uid name topic uid
1 David xxxxx 1
2 Jack xxx 3
3 Mike xxxxxx 0经过存储过程处理后,得到这样一个表C:
C表
-------------------------
topic name
xxxxx David
xxx Mike
xxxxxx 匿名请问,这样的一个存储过程该怎么写?
解决方案 »
- 程序优化的问题
- 关于cache添加的一段代码~ 看不懂 求助
- SQL 2008 R2 提示错误信息(provider: SQL Network Interfaces, error: 25 - 连接字符串无效)
- Asp.net 从数据库中读取图片存储在字节数组后输出到页面,另一个页面调用。如何判断图片是否存在?
- 我写的asp.net网页,是繁体的,其中有个论坛,繁体写进数据库是正常的,但简体输入到数据库后,显示的是乱码
- 想办一个网站,同时申请一个国际域名,不知道哪里的虚拟空间好?
- datagrid中TextBox的值无论怎么修改,最后得到的值仍是最初从库中取出的原始值?
- (asp.net)url重写二级域名问题!!!!!!!!!!!!!?????????
- 请教:参数 0: String 类型的“@temp”,Size 属性具有无效大小值: 0
- 如何DetailsView手动增删改
- 大伙帮帮忙,小弟先谢了!!!怎么解决这个问题???
- 郁闷!上传后,web congig错误???
LEFT JOIN
A表 a
on a.uid = b.uid
select b.topic, (case a.name when null then '匿名' else a.name end ) as NAME
FROM B表 b
LEFT JOIN
A表 a
on a.uid = b.uid
ASbegin
select b.topic, (case a.name when null then '匿名' else a.name end ) as NAME
FROM B表 b
LEFT JOIN
A表 a
on a.uid = b.uid
end
GO
不过问一句,左外连接LEFT outer JOIN 的outer可以省略吗?从来没敢省过。
楼上的, outer 是可以省略的
as
begin
select topic,uname = case when (select [NAME] from 表A where 表A.uid=表B.uid) is null then '匿名' else (select [NAME] from 表A where 表A.uid=表B.uid) end from 表Bend
不过还是要谢谢大家的帮助。