html循环查询的数据,SQL查询遍历数据方法一 [ 临时表 + While循环]
以下以SQL Server 2000中的NorthWind數(shù)據(jù)庫(kù)中的Customers表為例,
用?臨時(shí)表 + While循環(huán)?的方法, 對(duì)Customers表中的CompanyName列進(jìn)行遍歷
create table?#temp
(
id?int?identity(1,1),
customer?nvarchar(50)
)
declare?@customer?nvarchar(50)
declare?@n????????int
declare?@rows?????int
select?@n=1
insert?#temp(customer)?select distinct?companyname?from?customers
select?@rows =?@@rowcount
while?@n <= @rows
begin
select?@customer = companyname
from?customers
where?companyname=(select customer?from?#temp?where?id = @n)
order by?companyname?desc
print(@customer)
select?@n = @n + 1
end
運(yùn)行后, 輸出結(jié)果如下:
(所影響的行數(shù)為 91 行)
Alfreds Futterkiste
Ana Trujillo Emparedados y helados
Antonio Moreno Taquería
Around the Horn
Berglunds snabbk?p
Blauer See Delikatessen
Blondesddsl père et fils
Bólido Comidas preparadas
Bon app‘
Bottom-Dollar Markets
B‘s Beverages
Cactus Comidas para llevar
Centro comercial Moctezuma
Chop-suey Chinese
Comércio Mineiro
Consolidated Holdings
Die Wandernde Kuh
Drachenblut Delikatessen
Du monde entier
Eastern Connection
Ernst Handel
Familia Arquibaldo
FISSA Fabrica Inter. Salchichas S.A.
Folies gourmandes
Folk och f? HB
France restauration
Franchi S.p.A.
Frankenversand
Furia Bacalhau e Frutos do Mar
Galería del gastrónomo
Godos Cocina Típica
Gourmet Lanchonetes
Great Lakes Food Market
GROSELLA-Restaurante
...... (以下略) ..................................
原文:http://www.cnblogs.com/shiyh/p/7171858.html
總結(jié)
以上是生活随笔為你收集整理的html循环查询的数据,SQL查询遍历数据方法一 [ 临时表 + While循环]的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Golang——时间日期函数
- 下一篇: java list 重复数据_java