27,579
社区成员
发帖
与我相关
我的任务
分享
create table t(f_id int,f_cityID nvarchar(10),f_name nvarchar(10),f_flag nvarchar(10))
insert into t select 1,'1000','天津','无效'
insert into t select 2,'1000','天津','有效'
insert into t select 3,'1002','北京','有效'
insert into t select 4,'1003','上海','有效'
go
DECLARE @fid int;
SELECT @fid=f_ID FROM t WHERE (f_cityID =1000) order by f_id desc
select @fid
go
drop table t
DECLARE @fid int
Declare ff Cursor Local Keyset For
SELECT f_ID FROM t WHERE f_cityID =1000
Open ff
Fetch first From ff into @fid
While (@@FETCH_STATUS <> -1)
Begin
print @fid
FETCH NEXT FROM ff into @fid
End
close ff
deallocate ff