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

这么的语句你能写出存储过程,算你SQL学到家了

2011-12-12 
这样的语句你能写出存储过程,算你SQL学到家了!selecttop10*fromlybiaowhereidnotin(selecttoptempidfromly

这样的语句你能写出存储过程,算你SQL学到家了!
select   top   10   *   from   lybiao   where   id   not   in   (   select   top   temp     id     from   lybiao   order   by   id   desc)   order   by   id   desc  
//     里面的   temp   是一个变量哦,由参数传过来的,如果不是一个变量,那这个存储过程谁都会写,就不用请高手了!
哪位高手能把上面的语句给我写出存储过程,能写出来的真的可以说SQL能用得出神入化了!  


[解决办法]
If Exists (Select 1
From sysobjects
Where id = object_id( 'Proc_Name ')
And type = 'P ')
Drop Procedure Proc_Name
Go

Create Procedure Proc_Name(
@P_Temp int
)
As
Begin
Declare @sql varchar(8000)
Set @sql = 'select top 10 * from lybiao where id not in
( select top ' + @P_Temp + ' id from lybiao order by id desc) order by id desc '
Exec @sql
End

热点排行