天天看點

sql2005 分頁

-top-前n名的訂單

declare @n int 

set @n = 10 

select TOP(@n) * from Orders

-分頁-按Freight從小到大排序,求20到30行的結果 

select * from( 

    select OrderId, Freight, ROW_NUMBER() OVER(order by Freight) as row from Orders 

) a

where row between 20 and 30

-排名-

select * from( 

    select OrderId, Freight, RANK() OVER(order by Freight) as rank from Orders 

) a

where rank between 20 and 30

-try catch-

SET XACT_ABORT ON  -- 打開 try功能 

BEGIN TRY 

    begin tran 

        insert into Orders(CustomerId) values(-1) 

    commit tran 

    print 'commited' 

END TRY 

BEGIN CATCH 

    rollback    

    print 'rolled back' 

END CATCH

-cte-例子:結合通用表達式進行分頁

WITH OrderFreight AS( 

    select OrderId, Freight, ROW_NUMBER() OVER(order by Freight) as row from Orders 

select OrderId, Freight from OrderFreight where row between 10 and 20

-直接釋出webservice-DataSet CustOrdersOrders(string customerID) 

CREATE ENDPOINT Orders_Endpoint 

state=started 

as http( 

    path='/sql/orders', 

    AUTHENTICATION=(INTEGRATED), 

    ports=(clear) 

for soap( 

    WebMethod 'CustOrdersOrders'(   

        name='Northwind.dbo.CustOrdersOrders' 

    ), 

    wsdl=default, 

    database='Northwind', 

    namespace='http://mysite.org/'