0

I want execute certain set of SQL statements based on parameters passed on from json and they all should be in single SQL.

I have 3 conditions namely

1. Give 2. Take 3. Both

Now in Netezza SQL,

I would like to have something as below:

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

After searching I found below links,but not sure if this is possible in Netezza.

Can you have if-then-else logic in SQL?

How do I perform an IF...THEN in an SQL SELECT?

Can anyone please guide me?

I am new to Netezza db

Thanks Maddy

Community
  • 1
  • 1
maddy kemen
  • 67
  • 2
  • 9

1 Answers1

0

You could try and do this using case and dynamic SQL (you might need to check the syntax, since I haven't used Netezza much):

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
rohitvats
  • 1,811
  • 13
  • 11
  • Will check.Could you please explain the declaration of sql as nvarchar there? – maddy kemen Sep 03 '16 at 12:16
  • @maddykemen That's just to declare a variable to hold the dynamic SQL statements to be executed, which will be returned by the `case` statement. But please correct me if the syntax to declare a variable is different in Netezza. – rohitvats Sep 03 '16 at 12:18
  • will try and let you know – maddy kemen Sep 03 '16 at 16:32