Hello Stas
You can concat your SQL code snippets as you like. I have two samples to give you an idea how to solve your problem:
OrderNumber = 12345;
text_block_DB_0 = "select t1.* from DB1 t1";
if(selection_button, // can be a choice of the user
text_block_DB_1 = " and t1.[time]=(select max(t2.[time]) from DB1 t2 where t1.[SN] = t2.[SN])"; // get the laste entry of a serial number dependend of time)
,
text_block_DB_1 = ""; // gives all SN
)
dt = Open Database(__DSN_String,text_block_DB_0 || " where t1.[Order] = " || char(OrderNumber) || text_block_DB_1);
OrderNumber = 12345;
text_block_DB_0 = "select t1.* from DB1 t1 where t1.[Order] = *insert_order_number* ";
if(selection_button,
text_block_DB_1 = " and t1.[time]=(select max(t2.[time]) from DB1 t2 where t1.[SN] = t2.[SN])";
,
text_block_DB_1 = "";
)
dt = Open Database(__DSN_String,substitute(text_block_DB_0,"*insert_order_number*", char(OrderNumber)) || text_block_DB_1);
"I thought about our dilemma, and I came up with a solution that I honestly think works out best for one of both of us"
- GLaDOS