1

I have this table

      A      B       C       D
 1   User | priv1 | priv2 | priv3
 2   test |   y   |   n   |   n   
 3   more |   n   |   y   |   n  

and so on and I want to generate db2 commands from that.

 ="GRANT "&(IF B2="y", B1, "")& ", "&(IF C2="y", C1, "" )& ", "&(IF D2="y", D1, "" )&" on DATABSE TO USER "&A2&";"

should there for be

 GRANT priv1 ON DATABASE TO USER test;

However I can't get those IF parts to work.

Any idea? I tried many syntaxes but none get it to work. Google wasn't my friend either.

EXCEL 365 on Windows 10

Thanks

2 Answers 2

1

if you want multiple "y"'s in cells you can use textJoin function

like this:

="GRANT "&TEXTJOIN(", ";1;IF(B2="y";$B$1;"");IF(C2="y";$C$1;"");IF(D2="y";$D$1;""))&" on DATABASE TO USER "&A2&";"

this formula will place commas if needed

here is working example: https://drive.google.com/open?id=1UmuNpkKQz4KWPJIqT8j8iFO1GB5_J119

UPDATE: if you are able to modify source table better to modify it to this:

      A      B       C       D
 1   User | priv1 |       |     
 2   test | priv2 |       |      
 3   more | priv3 |       |   
 4   other| priv1 | priv3 |

then formula will be more simple like this:

="grant "&TEXTJOIN(", ";1;B2:D2)&" on database to user "&A2&";"

here is the example: https://drive.google.com/open?id=1IiSmT3OYLpxMvaeG0KYgK17ZYengWxWu

Sign up to request clarification or add additional context in comments.

2 Comments

I get the #NAME? if I use that
could you please share file?
0

Brackets after the IF

 ="GRANT "&IF(B2="y", B1, "")& ", "&IF(C2="y", C1, "" )& ", "&IF(D2="y", D1, "" )&" on DATABASE TO USER "&A2&";"

EDIT: And quotes aropund the text in B1,C1, D1 and A2

="GRANT "&IF(B2="y", "'"&B1&"'", "")& ", "&IF(C2="y", "'"&C1&"'", "" )& ", "&IF(D2="y","'"&D1&"'", "" )&" on DATABASE TO USER '"&A2&"';"

4 Comments

It works for me - what's the error? - did you copy and paste the formula?
Try a semicolon as seperator symbol?
Where should I put the semicolon
sorry - I forgot to test this with your actual data so i didn't notice the text needing quote marks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.