Question: I have a database (on DB2 9.7) A in which suppose I have tables X,Y,Z...n
Now I have created same tables X,Y,Z...n in database B. I want to provide same GRANTs to users in database B as it was in database A. So based on SYSCAT.TABAUTH I am trying to generate GRANT SQLs. I have written the following query for it:

```
db2 "select 'GRANT '||
case INSERTAUTH
    WHEN 'Y' THEN 'INSERT,'
    WHEN 'N' THEN ' '
    END||
case ALTERAUTH
    WHEN 'Y' THEN 'ALTER,'
    WHEN 'N' THEN ' '
    END||
case DELETEAUTH
    WHEN 'Y' THEN 'DELETE,'
    WHEN 'N' THEN ' '
    END||
case SELECTAUTH
    WHEN 'Y' THEN 'SELECT,'
    WHEN 'N' THEN ' '
    END||
case UPDATEAUTH
    WHEN 'Y' THEN 'UPDATE,'
    WHEN 'N' THEN ' '
    END||
' ON '||TABSCHEMA||'.'||TABNAME||' TO '||GRANTEE from SYSCAT.TABAUTH 
where INSERTAUTH='Y' OR  ALTERAUTH='Y' OR DELETEAUTH='Y' OR SELECTAUTH='Y' OR UPDATEAUTH='Y'"

```

However, the problem I am facing is of the additional ',' at end.
Suppose a user has only Insert auth, the above query will generate GRANT sql as:

```
GRANT INSERT, ON SCHEMA.TABLE TO GRANTEENAME
or if user has insert and select grants then:
GRANT INSERT,SELECT, ON SCHEMA.TABLE TO GRANTEENAME

```

How can I solve this? Please help..

Answer: 
Have `myfunction` accept a callback:

```
function myfunction(callback)
{
    var value = "myvalue";
    var post_url = "ajax.php";

    $.post(post_url, { value: value }, callback);
}

```

And then you can pass in any function to be executed when the `POST` comes back:

```
myfunction(function(responseText){  
    var json = JSON.parse(responseText);
    if (json.success)
    {
        console.log('success'); 
    }
});

```
Yes, you will either need to have a parameter to identify the caller, like

```
function myfunction(caller) {
    if (caller == "Foo") {
        // some code
    }
}

myFunction("Foo");

```

Or use a global variable

```
function myFunction() {
    if (caller == "Foo") {
        // some code
    }
}

caller = "Foo";
myFunction();

```