ÈýÖÖ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
//×Ô¼º»¹¿ÉÒÔ¼ÓÉÏһЩ²éѯÌõ¼þ
Àý:
select top 2 *
from Sys_Material_Type
where (MT_ID not in
(select top (2*(3-1)) MT_ID from Sys_Material_Type order by MT_ID))
order by MT_ID
2.·ÖÒ³·½°¸¶þ£º(ÀûÓÃID´óÓÚ¶àÉÙºÍSELECT TOP·ÖÒ³£©
Óï¾äÐÎʽ£º
SELECT TOP ÿҳ¼Ç¼ÊýÁ¿ *
from ±íÃû
WHERE (ID >
(SELECT MAX(id)
from (SELECT TOP ÿҳÐÐÊý*Ò³Êý id from ±í
ORDER BY id) AS T)
)
ORDER BY ID
Àý:
SELECT TOP 2 *
from Sys_Material_Type
WHERE (MT_ID >
(SELECT MAX(MT_ID)
from (SELECT TOP (2*(3-1)) MT_ID
from Sys_Material_Type
ORDER BY MT_ID) AS T))
ORDER BY MT_ID
3.·ÖÒ³·½°¸Èý£º(ÀûÓÃSQLµÄÓαê´æ´¢¹ý³Ì·ÖÒ³)
create procedure SqlPager
@sqlstr nvarchar(4000), --²éѯ×Ö·û´®
@currentpage int, --µÚNÒ³
@pagesize int --ÿҳÐÐÊý
as
set nocount on
declare @P1 int, --P1ÊÇÓαêµÄid
@rowcount int
exec sp_cursoropen @P1 output,@sqlstr,@scrollopt=1,@ccopt=1, @rowcount=@rowcount output
select ceiling(1.0*@rowcount/@pagesize) as ×ÜÒ³Êý--,@rowcount as ×ÜÐÐÊý,@currentpage as µ±Ç°Ò³
set @currentpage=(@currentpage-1)*@pagesize+1
exec sp_cursorfetch @P1,16,@currentpage,@pagesize
exec sp_cursorclose @P1
set nocount off
4.×ܽá:
ÆäËüµÄ·½°¸£ºÈç¹ûûÓÐÖ÷¼ü£¬¿ÉÒÔÓÃÁÙʱ±í£¬Ò²¿ÉÒÔÓ÷½°¸Èý×ö£¬µ«ÊÇЧÂÊ»áµÍ¡£
½¨ÒéÓÅ»¯µÄʱºò£¬¼ÓÉÏÖ÷¼üºÍË÷Òý£¬²éѯЧÂÊ»áÌá¸ß¡£
ͨ¹ýSQL ²éѯ·ÖÎöÆ÷£¬ÏÔʾ±È½Ï£ºÎҵĽáÂÛÊÇ:
·ÖÒ³·½°¸¶þ£º(ÀûÓÃID´óÓÚ¶àÉÙºÍSELECT TOP·ÖÒ³£©Ð§ÂÊ×î¸ß£¬Ð
Ïà¹ØÎĵµ£º
1. ÀûÓòâÊÔ¹¤¾ßÄ£Äâ¶à¸ö×îÖÕÓû§½øÐв¢·¢²âÊÔ; ÕâÖÖ²âÊÔ·½·¨µÄȱµã£º×îÖÕÓû§ÍùÍù²¢²»ÊÇÖ±½ÓÁ¬½Óµ½Êý¾Ý¿âÉÏ£¬¶øÊÇÒª¾¹ýÒ»¸öºÍ¶à¸öÖмä·þÎñ³ÌÐò£¬ËùÒÔ²¢²»Äܱ£Ö¤·ÃÎÊÊý¾Ý¿âʱ»¹ÊDz¢·¢¡£Æä´Î£¬ÕâÖÖ²âÊÔ·½·¨ÐèÒªµÈµ½¿Í»§¶Ë³ÌÐò¡¢·þÎñ¶Ë³ÌÐòÈ«²¿Íê³É²ÅÄܽøÐÐ; 2. ÀûÓòâÊÔ¹¤¾ß±àд½Å±¾£¬Ö±½ÓÁ¬½ÓÊý¾Ý¿â½øÐв¢·¢²âÊÔ; ÕâÖÖ·½ ......
SQL2005ÖÐrow_number( )¡¢rank( )¡¢dense_rank( )¡¢ntile( )º¯ÊýµÄÓ÷¨(2) ÊÕ²Ø
SQL server 2005ÐÂÔöµÄ¼¸¸öº¯Êý,·Ö±ðÊÇrow_number( )¡¢rank( )¡¢,DENSE_RANK( )¡¢ntile( )ÏÂÃæÒÔʵÀý·Ö±ð¼òµ¥½²½â¡£
1.row_number( )
ÏÈÀ´µãÊý¾Ý,ÏȽ¨¸ö±í
SET NOCOUNT ......
sql server 2008 bcp ÅúÁ¿¸´ÖƳÌÐò ³ö´í
C:\Documents and Settings>bcp MSPetShop4.dbo.product out c:\1.txt -T
SQLState = 08001, NativeError = -1
Error = [Microsoft][SQL Native Client]SQL ÍøÂç½Ó¿Ú: ¶¨Î»Ö¸¶¨µÄ Server/Instance
ʱ³ö´í [xFFFFFFFF].
SQLState = HYT00, NativeError = 0
Error = [Micros ......
/*
±êÌ⣺ÆÕͨÐÐÁÐת»»(version 2.0)
×÷Õߣº°®Ð¾õÂÞ.ع»ª
ʱ¼ä£º2008-03-09
µØµã£º¹ã¶«ÉîÛÚ
˵Ã÷£ºÆÕͨÐÐÁÐת»»(version 1.0)½öÕë¶Ôsql server 2000Ìṩ¾²Ì¬ºÍ¶¯Ì¬Ð´·¨£¬version 2.0Ôö¼Ósql server 2005µÄÓйØд·¨¡£
ÎÊÌ⣺¼ÙÉèÓÐÕÅѧÉú³É¼¨±í(tb)ÈçÏÂ:
ÐÕÃû ¿Î³Ì ·ÖÊý
ÕÅÈý ÓïÎÄ 74
ÕÅÈý Êýѧ 83
ÕÅÈý ÎïÀí 93 ......