我需要将我的 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 中控制流 - 还有其他方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
将每个子标记转换为具有多个分隔符的单列-SQLConverting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(将每个子标记转换为具有多个分隔符的单列-SQ
如何从多个表创建视图?How can I create a view from more than one table?(如何从多个表创建视图?)
根据前一行内的计算值创建计算值Create calculated value based on calculated value inside previous row(根据前一行内的计算值创建计算值)
如何将表格的前两列堆叠成一列,但也仅将第三How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何将表格的前两列堆
递归 t-sql 查询Recursive t-sql query(递归 t-sql 查询)
将月份名称转换为日期/月份编号(问题和答案的组Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(将月份名称转换为日期/月份编号(问题和答案的组合