以下以SQL Server 2000中的NorthWind数据库中的Customers表为例,
用 临时表 + While循环 的方法, 对Customers表中的CompanyName列进行遍历
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 = @@rowc

本文通过SQL Server 2000的NorthWind数据库中Customers表的例子,展示了如何利用临时表和While循环遍历并打印CompanyName列的所有值。首先创建临时表存储distinct的companyname,然后通过变量和循环结构逐条读取并输出结果,最终成功遍历了91行数据。
最低0.47元/天 解锁文章

1024

被折叠的 条评论
为什么被折叠?



