各種功能 的 存儲過程 (一)

/*根據設置的位置和顯示的記錄數量獲取新聞數據*/
create proc tgr_GetNewsInfoByFlags @Keyid int, @KeyS nvarchar(50)
as
begin
 exec('select top '+@Keyid+'* from RTO_TbNews where charindex("'+@KeyS+'",position)<>0 order by AddDate desc')
end


/*根據id號獲取新聞數據*/
create proc tgr_GetNewsInfoBySid @keyid int
as
begin
  select top 5 *from RTO_TbNews where Sid=@keyid order by AddDate desc
end


/*獲取某一類新聞數據*/
create proc tgr_GetOneClassNewsInfo @KeyId int,@IntI int
as
begin
declare @IntPageSize int set @IntPageSize=10
declare @TmpSelect nvarchar(600) select RTO_Bclass.B_Name,RTO_Sclass.S_Name,RTO_TbNews.*
  into #temptable from RTO_TbNews inner join RTO_Sclass on RTO_TbNews.Sid=RTO_Sclass.Sid 
  inner join RTO_Bclass on RTO_TbNews.Bid=RTO_Bclass.Bid where RTO_TbNews.Sid=@KeyId
if @IntI<>0
   begin
      set @TmpSelect ='select top '+str(@IntPageSize)+'* from #temptable where Nid not in(select top '+str((@IntI-1)*@IntPageSize)+' Nid from #temptable order by adddate desc) order by adddate desc'
   end
else
   begin
     set @TmpSelect='select count(*) as sumNum from #temptable'
   end
execute sp_executesql @TmpSelect
drop table #temptable
end

/*根據id號獲取某一類隨機新聞數據*/
create proc tgr_GetOneClassInfoByNid @KeyID int
as
begin 
   declare @Sid int
   select @Sid=Sid from RTO_TbNews where Nid=@KeyID
   select top 5 * from RTO_TbNews where Sid=@Sid and Nid<>@KeyID order by newID()
end

/*根據id號獲取用戶評論信息*/
create proc tgr_GetNewsCommentByNid @KeyID int ,@IntI int
as
begin
  declare @intPageSize int set @intPageSize=10
  declare @TmpSelect nvarchar(600) select RTO_Commen.* ,RTO_TbNews.Title,RTO_TbNews.HtmlFileName
    into #temptable  from TRO_TbNews inner join RTO_Commen on RTO_TbNews.Nid=RTO_Commen.Nid where RTO_Commen.Nid=@KeyID
  if @IntI <>0
    begin
          set @TmpSelect='select top '+str(@intPageSize)+' * from #temptable where Did not in(select top '+str((@IntI-1)*@intPageSize)+'Did from #temptable order by adddate desc) order by adddate desc'
      end
else 
 begin
    set @TmpSelect='select count(*) as sumNum from #temptable'
end
execute sp_executesql @TmpSelect
drop table #temptable
end


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章