使用 IF..ELSE IF 在 T-SQL SP 中控制流 - 还有其他方法吗?

Control flow in T-SQL SP using IF..ELSE IF - are there other ways?(使用 IF..ELSE IF 在 T-SQL SP 中控制流 - 还有其他方法吗?)
本文介绍了使用 IF..ELSE IF 在 T-SQL SP 中控制流 - 还有其他方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我需要将我的 T-SQL 存储过程 (MS SQL 2008) 控制流分支到多个方向:

I need to branch my T-SQL stored procedure (MS SQL 2008) control flow to a number of directions:

CREATE PROCEDURE [fooBar]
   @inputParam INT
AS
BEGIN
  IF @inputParam = 1
  BEGIN
    ...
  END
  ELSE IF @inputParam = 3
  BEGIN
    ...
  END
  ELSE IF @inputParam = 3
  BEGIN
    ...
  END
END

还有其他方法吗?例如,在 C# 中,我应该使用 switch-case 块.

Is there any other ways? For example, in C# I shoud use switch-case block.

推荐答案

IF...ELSE... 几乎就是我们在 T-SQL 中得到的.没有什么比结构化编程的 CASE 语句更像的了.如果您有一组扩展的 ...ELSE IF... 需要处理,请确保为每个块包含 BEGIN...END 以保持清晰,并始终记住,一致的缩进是您的朋友!

IF...ELSE... is pretty much what we've got in T-SQL. There is nothing like structured programming's CASE statement. If you have an extended set of ...ELSE IF...s to deal with, be sure to include BEGIN...END for each block to keep things clear, and always remember, consistent indentation is your friend!

这篇关于使用 IF..ELSE IF 在 T-SQL SP 中控制流 - 还有其他方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert varchar to float IF ISNUMERIC(将 varchar 转换为 float IF ISNUMERIC)
multi part identifier could not be bound sql(无法绑定多部分标识符 sql)
Any benefit to explicitly dropping local temporary tables at the end of a stored procedure?(在存储过程结束时显式删除本地临时表有什么好处?)
Check if a column contains text using SQL(使用 SQL 检查列是否包含文本)
Select value if condition in SQL Server(SQL Server 中的条件选择值)
Inserting a multiple records in a table with while loop (使用while循环在表中插入多条记录)