从“特定视图的记录"中按值选择值存储过程 [英] Selecting Value by value From Records Of Specific view Stored procedure

查看:78
本文介绍了从“特定视图的记录"中按值选择值存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我有一个包含两个列F1和F2的视图.

我想从第一个记录到最后一个记录循环浏览该视图,并为每个记录选择F2的值(如果它满足某些条件),请执行一些操作并继续到下一条记录,否则也继续到下一条记录.

有人可以帮我遍历如上所述的从第一条记录到最后一条记录的视图吗?
使用SQL吗?

谢谢

Hi every one

I have a view consist of two Column F1 and F2.

I want to loop through this View from first record To last record and select for each record the value of F2 if it satisfy some condition, do some actions and continue to the next record, otherwise continue to next record too.

Can any one help me in looping through the View From the first record to the last one as I mentioned above
using SQL ?

Thanks

推荐答案

这是未经测试的-来自内存,请原谅任何错误-但这应该可以帮助您入门.

在您的存储过程中,请执行以下操作.


This is untested - from memory so excuse any errors - but it should get you started.

In your stored procedure do something like this..


DECLARE cursorForView
    CURSOR LOCAL FAST FORWARD FOR
       SELECT F1, F2 from yourView

OPEN cursorForView

Declare @f1 as int
Declare @f2 as int

Fetch next from cursorForView into @F1, @F2

WHILE @@FETCH_STATUS = 0
BEGIN
  IF @F2 = somecondition
  BEGIN
    dosomething
  END


Fetch next from cursorForView into @F1, @F2

END

CLOSE cursorForView
DEALLOCATE cursorForView


这篇关于从“特定视图的记录"中按值选择值存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆