首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

这样存储过程该如何实现

2012-02-02 
这样存储过程该怎么实现?现在有数据表A和B:A表B表-----------------------------------------------------

这样存储过程该怎么实现?
现在有数据表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               匿名

请问,这样的一个存储过程该怎么写?

[解决办法]
select b.topic, (case a.name when null then 'a.name ' else a.name end ) as NAME

FROM B表 b
LEFT JOIN
A表 a
on a.uid = b.uid
[解决办法]
select b.topic, ISNULL(a.name, '匿名 ') from B表 b LEFT JOIN A表 a ON a.uid = b.uid

[解决办法]
create procedure P_test
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 表B

end

热点排行