常用存储过程

一.查询

CREATE????? PROC sp_GetBBSPost
?@board_id int
/*

=====================================================
功能:?得到该版块的所有帖子
参数:
?@board_id int??:?该版块ID
=====================================================

*/
AS
select *,COALESCE(last_replay_time,send_time)
?from bbs_post
?where? (sysbulletin = 1)

union all

SELECT *,COALESCE(last_replay_time,send_time)
?FROM bbs_post b
?WHERE board_id = @board_id AND (bulletin = 1 )
?

union all

SELECT *,COALESCE(last_replay_time,send_time)
?FROM bbs_post c
?WHERE board_id = @board_id AND (bulletin = 0 OR bulletin IS NULL) AND (sysbulletin = 0 OR sysbulletin IS NULL)
?
ORDER BY sysbulletin desc,bulletin desc,COALESCE(last_replay_time,send_time) DESC
GO

posted @ 2005-03-26 01:09  meteorcui  阅读(90)  评论(0编辑  收藏  举报