如何在 Netezza 中对 SQL 使用 IF ELSE 条件

问题描述 投票:0回答:1

我想根据从 json 传递的参数执行某些 SQL 语句集,它们都应该在单个 SQL 中。

我有3个条件即

1。给 2.拿 3.两者都

现在在 Netezza SQL 中,

我想要的东西如下:

if %input = 'Give'
   set of give sql statements
else if %input = 'Take'
    set of take sql statements
else
    set of both sql statements.

搜索后我找到了以下链接,但不确定在 Netezza 中是否可行。

你能在 SQL 中使用 if-then-else 逻辑吗?

如何在 SQL SELECT 中执行 IF...THEN?

有人可以指导我吗?

我是 Netezza db 的新手

谢谢 麦迪

sql netezza
1个回答
0
投票

您可以尝试使用

case
dynamic SQL(您可能需要检查语法,因为我没有太多使用 Netezza):

declare sql nvarchar(10000)
sql := case 
        when %input = 'Give' then 'statement1; statement2;'
        when %input = 'Take' then 'statement3; statement4;'
        else 'statement5; statement6;'
       end
execute immediate sql
© www.soinside.com 2019 - 2024. All rights reserved.