2011年9月1日 星期四

MSSQL 自動產生流水號

2005,2008 寫法:

SELECT ROW_NUMBER() OVER(ORDER BY [排名欄位] ) AS RNO FROM [資料表]

--
SELECT ROW_NUMBER() OVER(ORDER BY [Sno] DESC) AS RNO FROM [TableName]


2000 寫法:
select count(*) sn, a.CustomerID from Customers a , Customers b
where b.CustomerID <= a.CustomerID
group by a.CustomerID
order by a.customerid

沒有留言:

張貼留言