Hi.  You could open the H2 Console and create a function like this:

DROP ALIAS IF EXISTS GET_ITEM_SUPPLIERS;

CREATE ALIAS GET_ITEM_SUPPLIERS AS $$
String getItemSuppliers(java.sql.Connection con, String itemId, String 
supplierId) throws Exception {

StringBuilder buff = new StringBuilder();
java.sql.ResultSet rs = con.createStatement().executeQuery(
" SELECT some_field " +
" FROM some_table " +
" WHERE ITEM_ID = " + itemId  +
" AND SUPPLIER_ID = " + supplierId +
" ORDER BY some_field");
 
boolean first = true;
while(rs.next()){
if(first){
first = false;
}else{
buff.append(", ");
}

buff.append(rs.getString(1));
}

return buff.toString();
}
$$;


You can now use this function in normal sql.  You can just query it 
directly with something like:
SELECT GET_ITEM_SUPPLIERS(1, 5);

or more likely as part of another sql statement:
SELECT item_number, some_other_fields, GET_ITEM_SUPPLIERS(item_id, (select 
id from supplier where name = 'some_name'))
FROM item
WHERE item_description like 'some_value%'

The above H2 Function would select some data and return a comma separated 
String of values which you could use later on.
You could of course do a lot more complex logic than this, but it should 
give you an idea. 

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to