sqlserver 存储过程 游标实例
时间:2021-07-01 10:21:17
帮助过:11人阅读
exists(
select *
from sysobjects
where id = object_id(N
‘dbo.test_cursor‘) and type =
‘P‘)
drop PROCEDURE dbo.test_cursor
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE test_cursor
AS
Declare @acctNbr varchar(100);
Declare @acctName nvarchar(100);
Declare MyCursor Cursor
for Select AcctNbr,AcctName From
base._Member Order By ID
Open MyCursor
Fetch next From MyCursor
Into @acctNbr,@acctName
while(@@fetch_status=
0)
begin
begin
Select @acctNbr = Convert(varchar(
100),@acctNbr)
Select @acctName = Convert(nvarchar(
100),@acctName)
print N‘会员卡号:‘+@acctNbr + N
‘-----会员姓名:‘ +
@acctName
end
fetch next From MyCursor Into @acctNbr,@acctName
end
Close MyCursor
Deallocate MyCursor
--execute test_cursor
sqlserver 存储过程 游标实例
标签:eal ext 存储过程 ber color arch close for exe