Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

SQL SERVER 2005¹ý³Ì·ÖÒ³

AspNetPagerÊÇÒ»¸ö±È½ÏºÃµÄ·ÖÒ³¿Ø¼þ,¸Ã¿Ø¼þʹÓùý³Ì·Öҳʮ·Ö·½±ã,¹ý³ÌÈçÏÂ:
Create PROCEDURE [dbo].[pt_AspNetPager]
(
@tableName varchar(255), -- ±íÃû
@fieldName varchar(400)= '*', -- ×Ö¶ÎÃû
@strWhere varchar(255) = Null,
@fieldOrder varchar(100), --²»ÄÜΪ¿Õ
@startIndex int,
@endIndex int
)
AS
declare @strSQL varchar(4000)
begin
set @strSQL='WITH temp AS (SELECT ROW_NUMBER() OVER (ORDER BY '+@fieldOrder+') as row,'+@fieldName+' from '+@tableName
if @strWhere<>''
SELECT @strSQL=@strSQL+' where '+@strWhere
SELECT @strSQL=@strSQL+')'
SELECT @strSQL=@strSQL+' SELECT * from temp where row between '+cast(@startIndex as varchar(10))+' and '+cast(@endIndex as varchar(10))
print @strSQL
exec (@strSQL)
END


Ïà¹ØÎĵµ£º

SQL³£Ó÷ÖÒ³µÄ°ì·¨

SQL³£Ó÷ÖÒ³µÄ°ì·¨:
±íÖÐÖ÷¼ü±ØÐëΪ±êʶÁУ¬[ID] int IDENTITY (1,1)
1.·ÖÒ³·½°¸Ò»£º(ÀûÓÃNot InºÍSELECT TOP·ÖÒ³)
Óï¾äÐÎʽ£º 
SELECT TOP Ò³¼Ç¼ÊýÁ¿ *
from ±íÃû
WHERE (ID NOT IN
  (SELECT TOP (ÿҳÐÐÊý*(Ò³Êý-1)) ID
  from ±íÃû
  ORDER BY ID))
  ORDER BY ID
//×Ô ......

sqlÓï¾ä

select *from student
select student_id from student
select student_id ,student_name from student
select student_id student_name from student  ½«student_name ×÷Ϊstudent_idµÄ±ðÃû´¦Àí
È磺   select student_id a from student
 select a=student_id from student
´Óstudent±íÖзֱð¼ ......

¡¾Ð¡Ð¡ÎÊÌ⼯½õ13Ö® ¹ØÓÚ·Ö×é¼Ó˳ÐòºÅµÄSQLд·¨¡¿


/*
Ô­±í£º  
thid      other  
a              1  
a              1  
b              0  
b              0  
......

¹ØÓÚSQLÓï¾äCountµÄÒ»µãϸ½Ú

countÓï¾äÖ§³Ö*¡¢ÁÐÃû¡¢³£Á¿¡¢±äÁ¿,²¢ÇÒ¿ÉÒÔÓÃdistinct¹Ø¼ü×ÖÐÞÊΣ¬ ²¢ÇÒcount(ÁÐÃû)²»»áÀÛ¼ÆnullµÄ¼Ç¼¡£ÏÂÃæËæ±ãÓÃһЩÀý×Óʾ·¶Ò»ÏÂcountµÄ¹æÔò£º±ÈÈç¶ÔÈçϱí×öͳ¼Æ£¬ËùÓÐÁÐÕâÀï¶¼ÓÃsql_variantÀàÐÍÀ´±íʾ¡£
if (object_id ('t_test' )> 0 )
    drop table t_test
go
create table t_test (a ......

SQLµÄÈýÖÖ·ÖÒ³·½·¨

±íÖÐÖ÷¼ü±ØÐëΪ±êʶÁУ¬[ID] int IDENTITY (1,1)
1.·ÖÒ³·½°¸Ò»£º(ÀûÓÃNot InºÍSELECT TOP·ÖÒ³)
Óï¾äÐÎʽ£º 
SELECT TOP Ò³¼Ç¼ÊýÁ¿ *
from ±íÃû
WHERE (ID NOT IN
  (SELECT TOP (ÿҳÐÐÊý*(Ò³Êý-1)) ID
  from ±íÃû
  ORDER BY ID))
  ORDER BY ID
//×Ô¼º»¹¿ÉÒÔ¼ÓÉÏһЩ²éѯ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ