在游标中调用 PROC
我有一个名为 my_table
的表,其架构如下:
+----+--------------------------+-----------------------------+--------------------+
| ID | name (4 possible values) | action (2 possible values) | sequence (1,2...n) |
+----+--------------------------+-----------------------------+--------------------+
我想创建一个存储过程,可以根据 sequence
列中的顺序处理数据。该存储过程应该查看sequence
中的值,然后执行相应的存储过程。目前我有 8 个独立的存储过程。
例如,如果seq = 1
,则应执行存储过程#1。 如果seq = 2
,它将根据name
和action
的值转到存储过程#4。有 8 种可能的匹配。
这是我的尝试:
SET NOCOUNT ON
DECLARE @name varchar(20), @action varchar(20), @ID int, @Seq varchar(20)
DECLARE ILOOP CURSOR FOR SELECT ID, Name, Action, Seq FROM my_table
OPEN ILOOP
FETCH NEXT FROM iloop INTO @ID, @name, @Action, @Seq
WHILE @@Fetch_Status = 0 BEGIN
SELECT * From my_table WHERE Name = case Name when 'provider'
then EXEC sp1
END
CLOSE ILOOP
DEALLOCATE ILOOP
RETURN
I have table called my_table
with this schema:
+----+--------------------------+-----------------------------+--------------------+
| ID | name (4 possible values) | action (2 possible values) | sequence (1,2...n) |
+----+--------------------------+-----------------------------+--------------------+
I want to create a stored procedure that can process the data according to the sequence from the sequence
column. This stored procedure should look at the value in sequence
then execute the corresponding stored procedure. Current I have 8 separate stored procedures.
For example, if seq = 1
then stored procedure #1 should be executed.
If seq = 2
it goes to stored procedure #4 depending on the values of name
and action
. There are 8 possible matches.
Here's my attempt:
SET NOCOUNT ON
DECLARE @name varchar(20), @action varchar(20), @ID int, @Seq varchar(20)
DECLARE ILOOP CURSOR FOR SELECT ID, Name, Action, Seq FROM my_table
OPEN ILOOP
FETCH NEXT FROM iloop INTO @ID, @name, @Action, @Seq
WHILE @@Fetch_Status = 0 BEGIN
SELECT * From my_table WHERE Name = case Name when 'provider'
then EXEC sp1
END
CLOSE ILOOP
DEALLOCATE ILOOP
RETURN
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
您忽略了告诉我们有关用于选择存储过程的特定逻辑或它们采用哪些参数的任何信息,但您似乎需要一些类似的信息。
You have neglected to tell us anything about the specific logic used to select the stored procedures or what parameters they take but it seems you need something along these lines.