sqlServer 游标的使用
USE [CA-PG]
GO
IF EXISTS (SELECT name FROM sysObjects where name ='pg_GetlatestRate' and type='p' )
DROP PROCEDURE [dbo].pg_GetlatestRate
GO
CREATE PROCEDURE pg_GetlatestRate(@RATE_CURSOR cursor varying output)
AS
DECLARE @CRID int, @CurrCode char(3), @CurrName char(3), @ExchRate DECIMAL(18,2), @LMDate VARCHAR(23);
SET @rate_cursor = CURSOR FOR
SELECT CRID,CurrCode,CurrName,ExchRate,CONVERT(VARCHAR(10),LMDate,23) LMDATE FROM [CA-PG]..[PG_CurrRate] ORDER BY LMDate DESC;
OPEN @RATE_CURSOR
DROP PROC pg_GetlatestRate
GO
DECLARE @RATE_CURSOR cursor, @CRID int, @CurrCode char(3), @CurrName char(3), @ExchRate DECIMAL(18,2), @LMDate VARCHAR(23);
exec pg_GetlatestRate @RATE_CURSOR output;
fetch next from @RATE_CURSOR into @CRID, @CurrCode, @CurrName, @ExchRate
WHILE (@@FETCH_STATUS =0 )
BEGIN
FETCH NEXT FROM @RATE_CURSOR INTO @CRID, @CurrCode, @CurrName, @ExchRate
PRINT @CRID + @CurrCode + @CurrName + @ExchRate
END
CLOSE @RATE_CURSOR;
go

浙公网安备 33010602011771号