diff --git a/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/bulkmail/entityfields/documenttemplate_id/customproperties/translate4log/property.js b/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/bulkmail/entityfields/documenttemplate_id/customproperties/translate4log/property.js
index 0323e52461762d8b246786c89c2fda67412ef534..1c34e31e8ccd4d848b42fedb4ce04b4600c92bec 100644
--- a/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/bulkmail/entityfields/documenttemplate_id/customproperties/translate4log/property.js
+++ b/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/bulkmail/entityfields/documenttemplate_id/customproperties/translate4log/property.js
@@ -5,8 +5,9 @@ import("system.result");
 import("Loghistory_lib");
 
 var params = Translate4LogParams.load();
-var res = db.cell(SqlCondition.begin()
-    .andPrepare("DOCUMENTTEMPLATE.DOCUMENTTEMPLATEID", params.value)
-    .buildSql("select NAME from DOCUMENTTEMPLATE", "1=2"));
+var res = newSelect("NAME")
+            .from("DOCUMENTTEMPLATE")
+            .where("DOCUMENTTEMPLATE.DOCUMENTTEMPLATEID", params.value)
+            .cell();
     
 result.string(res);
diff --git a/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/serialletter/entityfields/documenttemplate_id/customproperties/translate4log/property.js b/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/serialletter/entityfields/documenttemplate_id/customproperties/translate4log/property.js
index 0323e52461762d8b246786c89c2fda67412ef534..1c34e31e8ccd4d848b42fedb4ce04b4600c92bec 100644
--- a/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/serialletter/entityfields/documenttemplate_id/customproperties/translate4log/property.js
+++ b/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/serialletter/entityfields/documenttemplate_id/customproperties/translate4log/property.js
@@ -5,8 +5,9 @@ import("system.result");
 import("Loghistory_lib");
 
 var params = Translate4LogParams.load();
-var res = db.cell(SqlCondition.begin()
-    .andPrepare("DOCUMENTTEMPLATE.DOCUMENTTEMPLATEID", params.value)
-    .buildSql("select NAME from DOCUMENTTEMPLATE", "1=2"));
+var res = newSelect("NAME")
+            .from("DOCUMENTTEMPLATE")
+            .where("DOCUMENTTEMPLATE.DOCUMENTTEMPLATEID", params.value)
+            .cell();
     
 result.string(res);
diff --git a/aliasDefinition/Data_alias/indexsearchgroups/salesorder/query.js b/aliasDefinition/Data_alias/indexsearchgroups/salesorder/query.js
index 2ffeb89a270aad2faa93e843109cfcd93defb5e9..f40738184c61fdaf0fac3f1a19606c292d6d2fe2 100644
--- a/aliasDefinition/Data_alias/indexsearchgroups/salesorder/query.js
+++ b/aliasDefinition/Data_alias/indexsearchgroups/salesorder/query.js
@@ -12,7 +12,7 @@ queryCondition = "";
 if (vars.exists("$local.idvalue")) {
     affectedIds = vars.get("$local.idvalue");
     queryCondition = "where SALESORDERID in ('" + affectedIds.map(function (v){return db.quote(v);}).join("', '") + "')";
-    //TODO: refactor this for incremental indexer (injections?) ----> use SqlCondition Lib
+    //TODO: refactor this for incremental indexer (injections?) ----> use SqlBuilder Lib
 }
 sqlHelper = new SqlMaskingUtils();
 sqlQuery = "select SALESORDERID, " 
diff --git a/entity/360Degree_entity/recordcontainers/jdito/contentProcess.js b/entity/360Degree_entity/recordcontainers/jdito/contentProcess.js
index 92fef480e511705c8f175b3190c3bbb40303a32d..25d347e733fa9f78f520c6a2ef9585c6e154f98f 100644
--- a/entity/360Degree_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/360Degree_entity/recordcontainers/jdito/contentProcess.js
@@ -89,9 +89,9 @@ function _get360Data(pSelectMap, pBaseContextId, pContactId, pContextList, pActi
         
         for (subContextId in subContexts)
         {
-            var subContextSql = subContexts[subContextId][0];
+            var subContextSelect = subContexts[subContextId][0];
             // select Ids from subcontexts
-            var subContextContactIds = db.array(db.COLUMN, subContextSql);
+            var subContextContactIds = subContextSelect.arrayColumn();
 
             subContextContactIds.forEach(function(pId) {
                                                                                                                                         // V-- do not add subcontexts deeper than one layer
diff --git a/entity/ActivityLink_entity/recordcontainers/db/conditionProcess.js b/entity/ActivityLink_entity/recordcontainers/db/conditionProcess.js
index 6e4af217f1b188cb44d3218b7acd239b5f1723c5..174ad7f6d1a52dda34c6476bf86ec19f02b242a2 100644
--- a/entity/ActivityLink_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/ActivityLink_entity/recordcontainers/db/conditionProcess.js
@@ -3,8 +3,7 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = SqlCondition.begin()
-                       .andPrepareVars("ACTIVITYLINK.ACTIVITY_ID", "$param.ActivityId_param");
+var cond = newWhereIfSet("ACTIVITYLINK.ACTIVITY_ID", "$param.ActivityId_param");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 0"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/Activity_entity/recordcontainers/db/conditionProcess.js b/entity/Activity_entity/recordcontainers/db/conditionProcess.js
index c5efd80ad1e9b3cf7af09e80bdd641bae8d994cb..a90c77ea69bef0ebc370e9842321a1ffe006c56c 100644
--- a/entity/Activity_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Activity_entity/recordcontainers/db/conditionProcess.js
@@ -5,7 +5,7 @@ import("system.result");
 import("Sql_lib");
 
 var loadNothing = false;
-var cond = new SqlCondition();
+var cond = newWhere();
 if (vars.exists("$param.RowId_param") && vars.get("$param.RowId_param") && vars.exists("$param.ObjectId_param") && vars.get("$param.ObjectId_param"))
 {
     var rowId = vars.get("$param.RowId_param");
@@ -13,24 +13,29 @@ if (vars.exists("$param.RowId_param") && vars.get("$param.RowId_param") && vars.
     var rowIdCond = null;
     if (vars.get("$param.ObjectId_param") == "Person")
     {
-        rowIds = db.array(db.COLUMN, SqlCondition.begin()
-                                                 .andPrepare("CONTACT.CONTACTID", rowId)
-                                                 .buildSql("select CONTACT.CONTACTID \n\
-                                                            from CONTACT \n\
-                                                            where CONTACT.PERSON_ID = (select CONTACT.PERSON_ID from CONTACT", null, ")"));
+        var personIdSelect = newSelect("CONTACT.CONTACTID")
+                                    .from("CONTACT")
+                                    .where("CONTACT.CONTACTID", rowId)
+                                    .and("CONTACT.PERSON_ID", newSelect("CONTACT.PERSON_ID")
+                                                                .from("CONTACT")
+                                                                .where("CONTACT.CONTACTID", rowId));                                     
+        rowIds = personIdSelect.array(db.COLUMN);
     }
-    var activityLinkCond = SqlCondition.begin().andIn("ACTIVITYLINK.OBJECT_ROWID", rowIds)
-                                               .andPrepareVars("ACTIVITYLINK.OBJECT_TYPE", "$param.ObjectId_param");
-
-                                                            // TODO: more performant way than IN. Maybe a join??
-    cond.and(SqlUtils.translateStatementWithQuotes(activityLinkCond.buildSql("ACTIVITY.ACTIVITYID in (select ACTIVITYLINK.ACTIVITY_ID from ACTIVITYLINK", "1=2", ")")))
+    
+    var activityLinkSubselect = newSelect("ACTIVITYLINK.ACTIVITY_ID")
+                                        .from("ACTIVITYLINK")
+                                        .where("ACTIVITYLINK.OBJECT_ROWID", rowIds, SqlBuilder.IN())
+                                        .and("ACTIVITYLINK.OBJECT_TYPE", "$param.ObjectId_param");
+        
+                                    // TODO: more performant way than IN. Maybe a join??
+    cond.and("ACTIVITY.ACTIVITYID", activityLinkSubselect, SqlBuilder.IN());
 }
     
 if(vars.getString("$param.OnlyInnate_param") == "true") 
 {
     var ownContactId = EmployeeUtils.getCurrentContactId();
     if (ownContactId)
-        cond.andPrepareIfSet("ACTIVITY.RESPONSIBLE", ownContactId);
+        cond.and("ACTIVITY.RESPONSIBLE", ownContactId);
     else
         loadNothing = true;
 }
@@ -41,7 +46,8 @@ if (loadNothing)
 }
 else
 {
-    //TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-    var resCond = cond.translate("1 = 1");
+    //TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+    var resCond = cond.toString();
 }
+
 result.string(resCond);
\ No newline at end of file
diff --git a/entity/Activity_entity/recordcontainers/db/onDBDelete.js b/entity/Activity_entity/recordcontainers/db/onDBDelete.js
index 3ede97828741f9baed6f5ef05de7d3913953e3fc..856d48640eb398efbf305f5ab60d78e876043f7d 100644
--- a/entity/Activity_entity/recordcontainers/db/onDBDelete.js
+++ b/entity/Activity_entity/recordcontainers/db/onDBDelete.js
@@ -2,7 +2,5 @@ import("system.vars");
 import("system.db");
 import("Sql_lib");
 
-var activityObjectsCondition = SqlCondition.begin()
-                                           .andPrepareVars("ACTIVITYLINK.ACTIVITY_ID", "$field.ACTIVITYID");
-
-db.deleteData("ACTIVITYLINK", activityObjectsCondition.build("1=2"));
\ No newline at end of file
+newWhere("ACTIVITYLINK.ACTIVITY_ID", "$field.ACTIVITYID")
+    .deleteData(true, "ACTIVITYLINK");
\ No newline at end of file
diff --git a/entity/AddressType_entity/recordcontainers/db/conditionProcess.js b/entity/AddressType_entity/recordcontainers/db/conditionProcess.js
index ff21b51fb9a1c05da35c77e00a354d2cdde7a488..35e253cd86a8a86cb382ea85ceac7539447d61e8 100644
--- a/entity/AddressType_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/AddressType_entity/recordcontainers/db/conditionProcess.js
@@ -5,21 +5,20 @@ import("KeywordRegistry_basic");
 import("Sql_lib");
 import("Keyword_lib");
 
-var cond = SqlCondition.begin()
-                       .andPrepare("AB_KEYWORD_ENTRY.CONTAINER", $KeywordRegistry.addressType());
+var cond = newWhere("AB_KEYWORD_ENTRY.CONTAINER", $KeywordRegistry.addressType());
 
 
 var usageFilter = vars.get("$param.UsageFilter_param");
 if (usageFilter)
 {
     var keywordAttribute = new KeywordAttribute($KeywordRegistry.addressType(), usageFilter);
-    cond.andAttachPrepared(SqlCondition.begin()
-                                       .andPrepare("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ATTRIBUTE_ID", keywordAttribute.id)
-                                       .andPrepare("AB_KEYWORD_ATTRIBUTERELATION." + keywordAttribute.dbField, "1")
-                                       .buildSql("AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID in (\n\
-                                                    select AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID \n\
-                                                    from AB_KEYWORD_ATTRIBUTERELATION ", null, ")"));
+    
+    cond.and("AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID", 
+                newSelect("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID")
+                    .from("AB_KEYWORD_ATTRIBUTERELATION")
+                    .where(["AB_KEYWORD_ATTRIBUTERELATION", keywordAttribute.dbField], "1"),
+            SqlBuilder.IN())
 }
 
-cond = cond.translate("1 = 2");
-result.string(cond);
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/Address_entity/conditionProcess.js b/entity/Address_entity/conditionProcess.js
index 80ab73670379630d15912e5b02b3309e05ad117b..2a2a40bad76b7c7bf6a7845b81df92b5cfa85ee2 100644
--- a/entity/Address_entity/conditionProcess.js
+++ b/entity/Address_entity/conditionProcess.js
@@ -2,5 +2,5 @@ import("Sql_lib");
 import("system.db");
 import("system.result");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(SqlCondition.begin().andPrepareVars("ADDRESS.CONTACT_ID", "$param.ContactId_param").translate("1=1"));  
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(newWhereIfSet("ADDRESS.CONTACT_ID", "$param.ContactId_param").toString());
diff --git a/entity/Address_entity/entityfields/defaultaddressid_param/valueProcess.js b/entity/Address_entity/entityfields/defaultaddressid_param/valueProcess.js
index 9c5d394a1a55a336b53ea24c4bbe5cc5afa53be7..f48ba8fc6f36cd8aa1a0eea6f78e31420e2e5565 100644
--- a/entity/Address_entity/entityfields/defaultaddressid_param/valueProcess.js
+++ b/entity/Address_entity/entityfields/defaultaddressid_param/valueProcess.js
@@ -12,9 +12,10 @@ import("system.vars");
 var contactId = vars.get("$param.ContactId_param");
 if (contactId)
 {
-    var sql = SqlCondition.begin()
-    .andPrepare("CONTACT.CONTACTID", contactId)
-    .buildSql("select CONTACT.ADDRESS_ID from CONTACT");
-    var organisationId = db.cell(sql);
+    var organisationId = newSelect("CONTACT.ADDRESS_ID")
+                            .from("CONTACT")
+                            .where("CONTACT.CONTACTID", contactId)
+                            .cell();
+
     result.string(organisationId);
 }
\ No newline at end of file
diff --git a/entity/Address_entity/entityfields/organisationandcontactaddresses/children/organisationid_param/valueProcess.js b/entity/Address_entity/entityfields/organisationandcontactaddresses/children/organisationid_param/valueProcess.js
index c4bf0500f2c4d1835300f8dbcb921f28b8917f7c..5af79d4be9b6850ab8d8ec8b820e9dd757706168 100644
--- a/entity/Address_entity/entityfields/organisationandcontactaddresses/children/organisationid_param/valueProcess.js
+++ b/entity/Address_entity/entityfields/organisationandcontactaddresses/children/organisationid_param/valueProcess.js
@@ -12,9 +12,9 @@ import("system.vars");
 var contactId = vars.get("$param.ContactId_param");
 if (contactId)
 {
-    var sql = SqlCondition.begin()
-                          .andPrepare("CONTACT.CONTACTID", contactId)
-                          .buildSql("select CONTACT.ORGANISATION_ID from CONTACT");
-    var organisationId = db.cell(sql);
+    var organisationId = newSelect("CONTACT.ORGANISATION_ID")
+                            .from("CONTACT")
+                            .where("CONTACT.CONTACTID", contactId)
+                            .cell();
     result.string(organisationId);
 }
\ No newline at end of file
diff --git a/entity/Address_entity/recordcontainers/childgroup/query.js b/entity/Address_entity/recordcontainers/childgroup/query.js
index 17e6d413dd07573ab64f90b56924072230038dee..1776a08e6416ed6180c17953fd575c30e9af514e 100644
--- a/entity/Address_entity/recordcontainers/childgroup/query.js
+++ b/entity/Address_entity/recordcontainers/childgroup/query.js
@@ -8,13 +8,15 @@ if (vars.exists("$local.idvalue")) {
     affectedIds = vars.get("$local.idvalue");
 }
 
-result.string(SqlUtils.translateStatementWithQuotes(SqlCondition.begin()
-            .andIn("ADDRESS.ADDRESSID", affectedIds)
-            .buildSql("select \n\
-                        ADDRESS.ADDRESSID as \"_uid_\", \n\
-                        ADDRESS.ADDRESSID, \n\
-                        ADDRESS.ZIP as ZIP, \n\
-                        ADDRESS.CITY as CITY, \n\
-                        ADDRESS.COUNTRY, \n\
-                        ADDRESS.ADDRESS, \n\
-                        ADDRESS.BUILDINGNO from ADDRESS", "", "order by ADDRESS.ADDRESSID")));
\ No newline at end of file
+var addressSelect = newSelect("ADDRESS.ADDRESSID as \"_uid_\", \n\
+                               ADDRESS.ADDRESSID, \n\
+                               ADDRESS.ZIP as ZIP, \n\
+                               ADDRESS.CITY as CITY, \n\
+                               ADDRESS.COUNTRY, \n\
+                               ADDRESS.ADDRESS, \n\
+                               ADDRESS.BUILDINGNO")
+                            .from("ADDRESS")
+                            .where("ADDRESS.ADDRESSID", affectedIds, SqlBuilder.IN())
+                            .orderBy("ADDRESS.ADDRESSID")
+
+result.string(addressSelect.toString());
\ No newline at end of file
diff --git a/entity/Address_entity/recordcontainers/db/conditionProcess.js b/entity/Address_entity/recordcontainers/db/conditionProcess.js
index 3494351fa8201c63d3d4574a6e47c4765d95dd68..c4efac40ae8a5341a729f2731f5dbf1c2ab995f5 100644
--- a/entity/Address_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Address_entity/recordcontainers/db/conditionProcess.js
@@ -3,19 +3,18 @@ import("system.vars");
 import("system.db");
 import("Sql_lib");
 
-var cond = SqlCondition.begin()
-                       .andPrepareVars("ADDRESS.CONTACT_ID", "$param.ContactId_param");
-                       
+var cond = newWhereIfSet("ADDRESS.CONTACT_ID", "$param.ContactId_param");
+
 var organisationId = vars.get("$param.OrganisationId_param");
 if (organisationId)
 {
-    var organisationContactSql = SqlCondition.begin()
-                                             .andPrepare("CONTACT.ORGANISATION_ID", organisationId)
-                                             .and("CONTACT.PERSON_ID is null")
-                                             .buildSql("select CONTACT.CONTACTID from CONTACT");
-    var organisationContactId = db.cell(organisationContactSql);
-    cond.orPrepare("ADDRESS.CONTACT_ID", organisationContactId);
+    var organisationContactId = newSelect("CONTACT.CONTACTID")
+                                    .from("CONTACT")
+                                    .where("CONTACT.ORGANISATION_ID", organisationId)
+                                    .and("CONTACT.PERSON_ID is null")
+                                    .cell();
+    cond.orIfSet("ADDRESS.CONTACT_ID", organisationContactId);
 }
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 2"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/Analyses_entity/entityfields/myturnover/valueProcess.js b/entity/Analyses_entity/entityfields/myturnover/valueProcess.js
index 9c8e5ea68dc50dc8a1b7f3ddb63eeffa651d316f..ceb6e24e39795b72fc8edc5ac556482018eaac3c 100644
--- a/entity/Analyses_entity/entityfields/myturnover/valueProcess.js
+++ b/entity/Analyses_entity/entityfields/myturnover/valueProcess.js
@@ -6,8 +6,9 @@ import("Date_lib");
 import("Sql_lib");
 import("system.SQLTYPES")
 
-var turnover = db.cell(SqlCondition.begin()
-                                   .andPrepare("SALESORDER.SALESORDERDATE", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER)
-                                   .buildSql("select sum(NET + VAT) from SALESORDER", "1=2"));
+var turnover = newSelect("sum(NET + VAT)")
+                    .from("SALESORDER")
+                    .where("SALESORDER.SALESORDERDATE", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER)
+                    .cell();
                                   
 result.string(turnover);
\ No newline at end of file
diff --git a/entity/Analyses_entity/entityfields/openoverduetasks/onActionProcess.js b/entity/Analyses_entity/entityfields/openoverduetasks/onActionProcess.js
index a4a99abca7e87092c860c0b4345398aaa83615f3..c1012c359510ebd9b660bbb712a5549afd01d591 100644
--- a/entity/Analyses_entity/entityfields/openoverduetasks/onActionProcess.js
+++ b/entity/Analyses_entity/entityfields/openoverduetasks/onActionProcess.js
@@ -1,15 +1,15 @@
+import("system.neon");
+import("system.db");
+import("ActivityTask_lib");
 import("Employee_lib");
 import("system.vars");
-import("system.datetime");
-import("system.db");
-import("system.neon");
-import("Date_lib");
 import("Sql_lib");
 
-var overduetask = db.table(SqlCondition.begin()
-                    .andPrepare("TASK.MATURITY_DATE", vars.get("$sys.date"), "# < ?")
-                    .and("TASK.EDITOR_CONTACT_ID = '" + EmployeeUtils.getCurrentContactId() + "'")
-                    .and("TASK.STATUS NOT IN ('ENDED', 'ENDED-DONE', 'ENDED-ABANDONED')")
-                    .buildSql("select TASKID from TASK", "1=2"));
+var overdueTask = newSelect("TASKID")
+                    .from("TASK")
+                    .where("TASK.MATURITY_DATE", vars.get("$sys.date"), "# < ?")
+                    .and("TASK.EDITOR_CONTACT_ID", EmployeeUtils.getCurrentContactId())
+                    .and("TASK.STATUS", TaskUtils.getEndedStatuses(), SqlBuilder.NOT_IN())
+                    .array(db.COLUMN)
 
-neon.openContext("Task", "TaskFilter_view", overduetask, neon.OPERATINGSTATE_SEARCH, null);
\ No newline at end of file
+neon.openContext("Task", "TaskFilter_view", overdueTask, neon.OPERATINGSTATE_SEARCH, null);
\ No newline at end of file
diff --git a/entity/Analyses_entity/entityfields/overdue_tasks/valueProcess.js b/entity/Analyses_entity/entityfields/overdue_tasks/valueProcess.js
index b179962d57663f5da1740a7c60c44832d0483613..8b14b5b5c7bf93a96604cc9e741a2523a72eeaaa 100644
--- a/entity/Analyses_entity/entityfields/overdue_tasks/valueProcess.js
+++ b/entity/Analyses_entity/entityfields/overdue_tasks/valueProcess.js
@@ -1,15 +1,14 @@
-import("Employee_lib");
-import("system.db");
-import("system.datetime");
-import("system.result");
 import("system.vars");
-import("Date_lib");
+import("Employee_lib");
 import("Sql_lib");
+import("ActivityTask_lib");
+import("system.result");
+
+var overdueTaskCount = newSelect("count(TASKID)")
+                    .from("TASK")
+                    .where("TASK.MATURITY_DATE", vars.get("$sys.date"), "# < ?")
+                    .and("TASK.EDITOR_CONTACT_ID", EmployeeUtils.getCurrentContactId())
+                    .and("TASK.STATUS", TaskUtils.getEndedStatuses(), SqlBuilder.NOT_IN())
+                    .cell()
 
-var overduetask = db.cell(SqlCondition.begin()
-                                   .andPrepare("TASK.MATURITY_DATE", vars.get("$sys.date"), "# < ?")
-                                   .and("TASK.EDITOR_CONTACT_ID = '" + EmployeeUtils.getCurrentContactId() + "'")
-                                   .and("TASK.STATUS NOT IN ('ENDED', 'ENDED-DONE', 'ENDED-ABANDONED')")
-                                   .buildSql("select count(TASKID) from TASK", "1=2"));
-                                                                  
-result.string(overduetask);
+result.string(overdueTaskCount);
\ No newline at end of file
diff --git a/entity/Analyses_entity/entityfields/turnover_forecast/valueProcess.js b/entity/Analyses_entity/entityfields/turnover_forecast/valueProcess.js
index d6f89d038debab8b78a11020bdcc2b989341414d..72d7b1588dc53ebc626e3d3fe4691d195f95e69d 100644
--- a/entity/Analyses_entity/entityfields/turnover_forecast/valueProcess.js
+++ b/entity/Analyses_entity/entityfields/turnover_forecast/valueProcess.js
@@ -6,8 +6,9 @@ import("Date_lib");
 import("Sql_lib");
 import("system.SQLTYPES")
 
-var forecast = db.cell(SqlCondition.begin()
-                                    .andPrepare("FORECAST.DATE_START", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER)
-                                    .buildSql("select sum(VOLUME) from FORECAST", "1=2"));
+var forecast = newSelect("sum(VOLUME)")
+                .from("FORECAST")
+                .where("FORECAST.DATE_START", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER)
+                .cell();
                                   
 result.string(forecast);
\ No newline at end of file
diff --git a/entity/AnyContact_entity/recordcontainers/db/conditionProcess.js b/entity/AnyContact_entity/recordcontainers/db/conditionProcess.js
index c0688f7572349158469b202d4416f8f856b89fa0..72a71a68054367e4b1bf10e333d5b211785b8d69 100644
--- a/entity/AnyContact_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/AnyContact_entity/recordcontainers/db/conditionProcess.js
@@ -4,7 +4,7 @@ import("system.result");
 import("Sql_lib");
 import("Contact_lib");
 
-var orgContactId;
+var orgContactId = null;
 if (vars.exists("$param.ContactId_param") && vars.get("$param.ContactId_param"))
 {
     var contactId = vars.get("$param.ContactId_param");
@@ -16,19 +16,18 @@ if (vars.exists("$param.ContactId_param") && vars.get("$param.ContactId_param"))
     }
 }
 
-var conditionPrivateOrganisation = SqlCondition.begin()
-                                               .andPrepare("CONTACT.ORGANISATION_ID", "0", "# != ?");
+var conditionPrivateOrganisation = newWhere("CONTACT.ORGANISATION_ID", "0", "# <> ?")
 
 if (vars.getString("$param.WithPrivatePersons_param") == "true")
-    conditionPrivateOrganisation.orSqlCondition(SqlCondition.begin()
-                                                            .andPrepare("CONTACT.ORGANISATION_ID", "0")
-                                                            .and("CONTACT.PERSON_ID is not null")
-                                                );
+{
+    conditionPrivateOrganisation.or(newWhere("CONTACT.ORGANISATION_ID", "0")
+                                        .and("CONTACT.PERSON_ID is not null"));
+}
+    
 
 //exclude private organisation
-var cond = SqlCondition.begin()
-                       .andSqlCondition(conditionPrivateOrganisation)
-                       .andPrepareIfSet("CONTACT.ORGANISATION_ID", orgContactId);
+var cond = newWhereIfSet(conditionPrivateOrganisation)
+               .andIfSet("CONTACT.ORGANISATION_ID", orgContactId);
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate());
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/AppointmentLink_entity/recordcontainers/db/conditionProcess.js b/entity/AppointmentLink_entity/recordcontainers/db/conditionProcess.js
index a49c8d231adf901a8380b6aca4d1aed941b13c0a..b9a9cafdcba80e3ff11803906bddf17e2423c3b3 100644
--- a/entity/AppointmentLink_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/AppointmentLink_entity/recordcontainers/db/conditionProcess.js
@@ -2,8 +2,7 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = SqlCondition.begin()
-                       .andPrepareVars("AB_APPOINTMENTLINK.APPOINTMENT_ID", "$param.AppointmentId_param")
+var cond = newWhereIfSet("AB_APPOINTMENTLINK.APPOINTMENT_ID", "$param.AppointmentId_param")
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/Appointment_entity/recordcontainers/jdito/contentProcess.js b/entity/Appointment_entity/recordcontainers/jdito/contentProcess.js
index ad79e4da1a4442679263baee900df37040397eac..5e49c849c4998887a4362d59b9b1d9dfccec05ca 100644
--- a/entity/Appointment_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/Appointment_entity/recordcontainers/jdito/contentProcess.js
@@ -10,7 +10,7 @@ import("system.eMath");
 import("system.util");
 import("system.neon");
 
-var cond = SqlCondition.begin();
+var appointmentSelect = newSelect("APPOINTMENT_ID").from("AB_APPOINTMENTLINK");
 var appointmentUids;
 
 if(vars.get("$local.idvalues") != null && vars.get("$local.idvalues") != "")
@@ -23,10 +23,8 @@ else if(vars.getString("$param.LinkedAppointmentsFromDashlet_param"))
 {
     var contactid = EmployeeUtils.getCurrentContactId();
     
-    cond.andPrepareIfSet("AB_APPOINTMENTLINK.OBJECT_ROWID", contactid)
-
-    appointmentUids = db.table(cond.buildSql("select APPOINTMENT_ID from AB_APPOINTMENTLINK"));
-    result.object(buildEntriesFromUids(appointmentUids));
+    appointmentSelect.whereIfSet("AB_APPOINTMENTLINK.OBJECT_ROWID", contactid)
+    result.object(buildEntriesFromUids(appointmentSelect.table()));
 }
 
 /**
@@ -34,10 +32,8 @@ else if(vars.getString("$param.LinkedAppointmentsFromDashlet_param"))
  */
 else if(vars.getString("$param.LinkedObjectId_param") != undefined)
 {
-    cond.andPrepareVars("AB_APPOINTMENTLINK.OBJECT_ROWID", "$param.LinkedObjectId_param")
-   
-    appointmentUids = db.table(cond.buildSql("select APPOINTMENT_ID from AB_APPOINTMENTLINK"));
-    result.object(buildEntriesFromUids(appointmentUids));
+    appointmentSelect.whereIfSet("AB_APPOINTMENTLINK.OBJECT_ROWID", "$param.LinkedObjectId_param")
+    result.object(buildEntriesFromUids(appointmentSelect.table()));
 }
 /**
  * Will be used, if the user is operating the calendar.
diff --git a/entity/Appointment_entity/recordcontainers/jdito/onDelete.js b/entity/Appointment_entity/recordcontainers/jdito/onDelete.js
index 426f6fef57e738300c2a731a791bd0fc118feca3..cd469c7c5c068e276d44a78ce534f02e8dfd9420 100644
--- a/entity/Appointment_entity/recordcontainers/jdito/onDelete.js
+++ b/entity/Appointment_entity/recordcontainers/jdito/onDelete.js
@@ -18,8 +18,6 @@ if (vars.exists("$param.Entry_param"))
     /**
      * Deletes ApointmentLinks referring to the deleted Appointment.
      */
-    var cond = SqlCondition.begin();
-    cond.andPrepareIfSet("AB_APPOINTMENTLINK.APPOINTMENT_ID", entry[calendars.ID])
-    
-    db.deleteData("AB_APPOINTMENTLINK", cond.build("1 = 2"));
+    newWhereIfSet("AB_APPOINTMENTLINK.APPOINTMENT_ID", entry[calendars.ID])
+            .deleteData(true, "AB_APPOINTMENTLINK")
 }
\ No newline at end of file
diff --git a/entity/Appointment_entity/recordcontainers/jdito/rowCountProcess.js b/entity/Appointment_entity/recordcontainers/jdito/rowCountProcess.js
index 63e41b300e041444be45983da84cc9c3bd51507e..afff252f743faff586199e13333a707e5d52c51e 100644
--- a/entity/Appointment_entity/recordcontainers/jdito/rowCountProcess.js
+++ b/entity/Appointment_entity/recordcontainers/jdito/rowCountProcess.js
@@ -5,14 +5,15 @@ import("system.vars");
 import("system.result");
 
 var rowCount = "0";
-var cond = SqlCondition.begin();
+var cond = newSelect("count(APPOINTMENT_ID)")
+               .from("AB_APPOINTMENTLINK");
 
 if (vars.exists("$local.idvalues") && vars.get("$local.idvalues"))
     rowCount = "1";
 else if (vars.getString("$param.LinkedAppointmentsFromDashlet_param"))
 {
-    cond.andPrepareIfSet("AB_APPOINTMENTLINK.OBJECT_ROWID", EmployeeUtils.getCurrentContactId());
-    rowCount = db.cell(cond.buildSql("select count(APPOINTMENT_ID) from AB_APPOINTMENTLINK", "1=1"));
+    cond.whereIfSet("AB_APPOINTMENTLINK.OBJECT_ROWID", EmployeeUtils.getCurrentContactId());
+    rowCount = cond.cell();
 }
 
 /**
@@ -20,8 +21,8 @@ else if (vars.getString("$param.LinkedAppointmentsFromDashlet_param"))
  */
 else if (vars.getString("$param.LinkedObjectId_param") != undefined)
 {
-    cond.andPrepareVars("AB_APPOINTMENTLINK.OBJECT_ROWID", "$param.LinkedObjectId_param");
-    rowCount = db.cell(cond.buildSql("select count(APPOINTMENT_ID) from AB_APPOINTMENTLINK", "1=1"));
+    cond.whereIfSet("AB_APPOINTMENTLINK.OBJECT_ROWID", "$param.LinkedObjectId_param");
+    rowCount = cond.cell();
 }
 /**
  * Will be used, if the user is operating the calendar.
diff --git a/entity/AttributeRelation_entity/entityfields/value/displayValueProcess.js b/entity/AttributeRelation_entity/entityfields/value/displayValueProcess.js
index 415b66e5b08b02ef55d723874a37a2ea8c83b1c5..e937b57e12a503145c895cff9e185028ce3034f3 100644
--- a/entity/AttributeRelation_entity/entityfields/value/displayValueProcess.js
+++ b/entity/AttributeRelation_entity/entityfields/value/displayValueProcess.js
@@ -8,10 +8,9 @@ import("system.tools");
 import("Sql_lib");
 
 var attrType = vars.get("$field.ATTRIBUTE_TYPE");
-var dropDownDef = db.cell(
-    SqlCondition.begin()
-        .andPrepareVars("AB_ATTRIBUTE.AB_ATTRIBUTEID", "$field.AB_ATTRIBUTE_ID")
-        .buildSql("select DROPDOWNDEFINITION from AB_ATTRIBUTE")
-);
+var dropDownDef = newSelect("DROPDOWNDEFINITION")
+                    .from("AB_ATTRIBUTE")
+                    .whereIfSet("AB_ATTRIBUTE.AB_ATTRIBUTEID", "$field.AB_ATTRIBUTE_ID")
+                    .cell();
 
 result.string(AttributeTypeUtil.getAttributeViewValue(attrType, vars.get("$field.VALUE"), dropDownDef));
diff --git a/entity/AttributeRelation_entity/recordcontainers/jdito/contentProcess.js b/entity/AttributeRelation_entity/recordcontainers/jdito/contentProcess.js
index ced0fcc55c0a894225ac0adc15e4f66c3aeb9572..8946fb2946e28081a5cd85f11498f576730d536c 100644
--- a/entity/AttributeRelation_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/AttributeRelation_entity/recordcontainers/jdito/contentProcess.js
@@ -33,14 +33,10 @@ var defaultFields = [
 
 //these fields hold the attributeRelation value, depending on the attribute type
 var valueFields = AttributeTypeUtil.getAllDatabaseFields();
-var attributeSql = SqlBuilder.begin()
-    .select(defaultFields.concat(valueFields))
-    .from("AB_ATTRIBUTE")
-    .orderBy("AB_ATTRIBUTE.SORTING asc");
-
-var attributeCond = SqlCondition.begin(); //where-condition (condition for the Attribute)
-var attributeRelationCond = SqlCondition.begin()
-    .and("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID"); //condition for the joined values (for AttributeRelation)
+var attributeSql = newSelect(defaultFields.concat(valueFields))
+                    .from("AB_ATTRIBUTE")
+                    .orderBy("AB_ATTRIBUTE.SORTING asc")
+                    .where(); // go into where mode
 
 var possibleAttributes;
 
@@ -51,13 +47,13 @@ if (idvalues)
         showEmpty = false;
     
     if (showEmpty)
-        attributeCond.andPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", attrId);
+        attributeSql.and("AB_ATTRIBUTE.AB_ATTRIBUTEID", attrId);
     else
     {
-        attributeCond.andIn("AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID", idvalues.map(function(pId) 
+        attributeSql.andIfSet("AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID", idvalues.map(function(pId) 
         {
             return pId[0] == "," ? pId.split(",")[1] : pId;
-        }));
+        }), SqlBuilder.IN());
         objectRowId = null;
     }
     getTree = false;
@@ -65,41 +61,42 @@ if (idvalues)
 else if (showEmpty || objectRowId)
 {
     if (getTheme)
-        attributeCond.andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.THEME);
+        attributeSql.and("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.THEME);
     else
-        attributeCond.andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.THEME, "# != ?");
+        attributeSql.and("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.THEME, "# != ?");
     
     if (showEmpty)
     {
         possibleAttributes = AttributeUtil.getPossibleAttributes(objectType);
         let filtered = vars.exists("$param.FilteredAttributeIds_param") && vars.getString("$param.FilteredAttributeIds_param");
         
-        attributeCond.andIn("AB_ATTRIBUTE.AB_ATTRIBUTEID", possibleAttributes);
+        attributeSql.andIfSet("AB_ATTRIBUTE.AB_ATTRIBUTEID", possibleAttributes, SqlBuilder.IN());
     }
     if (vars.exists("$param.FilteredAttributeIds_param") && vars.getString("$param.FilteredAttributeIds_param"))
     {
         let filteredIds = JSON.parse(vars.getString("$param.FilteredAttributeIds_param"));
 
-        let filteredCondition = new SqlCondition();
         let filteredIdChildren = AttributeUtil.getAllChildren(filteredIds);
         
-        filteredCondition.andIn("AB_ATTRIBUTE.AB_ATTRIBUTEID", filteredIdChildren);
-        filteredCondition.andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE, "# != ?")
+        let filteredCondition = newWhereIfSet("AB_ATTRIBUTE.AB_ATTRIBUTEID", filteredIdChildren, SqlBuilder.IN())
+                                    .and("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE, "# != ?");
     
         // return nothing if filteredAttributeIds is an empty array. (--> and 1=2)
-        attributeCond.andSqlCondition(filteredCondition, "1=2");
+        if (filteredIds && filteredIds.length > 0)
+            attributeSql.and(filteredCondition);
     }
 }
 
+var attributeRelationCond = newWhere("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID"); //condition for the joined values (for AttributeRelation)
+
 if (objectRowId)
 {
-    attributeRelationCond.andPrepare("AB_ATTRIBUTERELATION.OBJECT_ROWID", objectRowId);
+    attributeRelationCond.and("AB_ATTRIBUTERELATION.OBJECT_ROWID", objectRowId);
     if (objectType)
-        attributeRelationCond.andPrepare("AB_ATTRIBUTERELATION.OBJECT_TYPE", objectType);
+        attributeRelationCond.and("AB_ATTRIBUTERELATION.OBJECT_TYPE", objectType);
 }
 
 
-attributeSql.where(attributeCond);
     
 if (showEmpty)
     attributeSql.leftJoin("AB_ATTRIBUTERELATION", attributeRelationCond);
@@ -117,11 +114,12 @@ if (getTree)
     if (!possibleAttributes)
         possibleAttributes = AttributeUtil.getPossibleAttributes(objectType);
     
-    let minUsages = db.table(SqlCondition.begin()
-        .andIn("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", possibleAttributes)
-        .andPrepare("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", objectType)
-        .buildSql("select AB_ATTRIBUTE_ID, MIN_COUNT from AB_ATTRIBUTEUSAGE", "1=2")
-    );
+    let minUsages = newSelect("AB_ATTRIBUTE_ID, MIN_COUNT")
+                        .from("AB_ATTRIBUTEUSAGE")
+                        .whereIfSet("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", possibleAttributes)
+                        .and("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", objectType)
+                        .table(true);
+
     minUsages.forEach(function (usage)
     {
         this[usage[0]] = {
@@ -131,7 +129,7 @@ if (getTree)
     }, minCountInsurance);
 }
 
-var attrRelations = db.table(attributeSql.build()).map(
+var attrRelations = attributeSql.table(true).map(
     function (row) 
     {
         var [attrRelId, attrId, attrParentId, attrType, attrName, dropDownDef, comboViewVal, dateNew, userNew, dateEdit, userEdit] = row;
@@ -195,14 +193,17 @@ function _buildAttributeTree (pAttrRelations)
  */
 function _fetchParentAttributes (pAttributeIds, pParentAttributes)
 {
-    var attributeCond = SqlCondition.begin();
+    var attributeCond = newSelect("AB_ATTRIBUTEID, ATTRIBUTE_PARENT_ID, ATTRIBUTE_NAME")
+                            .from("AB_ATTRIBUTE")
+                            .where()
     var nextIds = [];
     pAttributeIds.forEach(function (id)
     {
         if (!(id in this))
-            attributeCond.orPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", id);
+            attributeCond.andIfSet("AB_ATTRIBUTE.AB_ATTRIBUTEID", id);
     }, attrCatalog);
-    db.table(attributeCond.buildSql("select AB_ATTRIBUTEID, ATTRIBUTE_PARENT_ID, ATTRIBUTE_NAME from AB_ATTRIBUTE", "1=2"))
+    
+    attributeCond.table(true)
         .forEach(function ([attrId, parentId, attrName])
             {
                 this[attrId] = true; //make entry in attrCatalog to avoid duplicates
diff --git a/entity/AttributeRelation_entity/recordcontainers/jdito/onDelete.js b/entity/AttributeRelation_entity/recordcontainers/jdito/onDelete.js
index 607a023f25cbeff1e916650381ecf5dfa3bb42bc..534a178c60095c9485e947863acbb3c4c5cdf9c2 100644
--- a/entity/AttributeRelation_entity/recordcontainers/jdito/onDelete.js
+++ b/entity/AttributeRelation_entity/recordcontainers/jdito/onDelete.js
@@ -6,5 +6,6 @@ import("system.db");
 var rowData = vars.get("$local.rowdata");
 if (rowData["AB_ATTRIBUTE_ID.value"] && rowData["VALUE.value"])
 {
-    db.deleteData("AB_ATTRIBUTERELATION", SqlCondition.equals("AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID", vars.get("$local.uid"), "1=2"));
+    newWhere("AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID", vars.get("$local.uid"))
+        .deleteData(true, "AB_ATTRIBUTERELATION")
 }
\ No newline at end of file
diff --git a/entity/AttributeRelation_entity/recordcontainers/jdito/onUpdate.js b/entity/AttributeRelation_entity/recordcontainers/jdito/onUpdate.js
index 493d61541c3c9e2825e7c3e030445184c81968ca..f15a00e87532e1dd5b9d01cba926572b7bb7bf38 100644
--- a/entity/AttributeRelation_entity/recordcontainers/jdito/onUpdate.js
+++ b/entity/AttributeRelation_entity/recordcontainers/jdito/onUpdate.js
@@ -33,8 +33,8 @@ if (uid.length === 1)
     });
     values[AttributeTypeUtil.getTypeColumnIndex(type) + 3] = rowdata["VALUE.value"];
 
-    db.updateData("AB_ATTRIBUTERELATION", columns, null, values, 
-        SqlCondition.equals("AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID", uid[0], "1=2"));
+    newWhere("AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID", vars.get("$local.uid"))
+        .updateData(true, columns, null, values, "AB_ATTRIBUTERELATION");
 }
 else
 {
diff --git a/entity/AttributeUsage_entity/recordcontainers/db/conditionProcess.js b/entity/AttributeUsage_entity/recordcontainers/db/conditionProcess.js
index be0295177bfe08e538b7658becebe44a2991f8db..4c333a888b165e2b3fff15433861e3de2b785344 100644
--- a/entity/AttributeUsage_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/AttributeUsage_entity/recordcontainers/db/conditionProcess.js
@@ -2,7 +2,6 @@ import("Sql_lib");
 import("system.db");
 import("system.result");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(SqlCondition.begin()
-        .andPrepareVars("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", "$param.AttributeId_param")
-        .translate("1=2"));  
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(newWhereIfSet("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", "$param.AttributeId_param")
+                .toString());  
diff --git a/entity/Attribute_entity/afterUiInit.js b/entity/Attribute_entity/afterUiInit.js
index 6a175be075c7416b21489b44bdcfbbae03fde52d..fa558b3520b5d3239c1b8f299d30cc1a40458411 100644
--- a/entity/Attribute_entity/afterUiInit.js
+++ b/entity/Attribute_entity/afterUiInit.js
@@ -13,10 +13,10 @@ if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW
     var parentId = vars.get("$param.AttrParentId_param");
     var attributeId = vars.get("$field.UID");
 
-    var usageSql = SqlCondition.begin()
-        .andPrepare("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", parentId)
-        .buildSql("select OBJECT_TYPE from AB_ATTRIBUTEUSAGE", "1=0");
-    var usages = db.array(db.COLUMN, usageSql);
+    var usages = newSelect("OBJECT_TYPE")
+                       .from("AB_ATTRIBUTEUSAGE")
+                       .and("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", parentId)
+                       .array(db.COLUMN, true)
 
     //preset the usages with the ones from the parent
     usages.forEach(function (usage) 
diff --git a/entity/Attribute_entity/entityfields/attribute_type/stateProcess.js b/entity/Attribute_entity/entityfields/attribute_type/stateProcess.js
index 6497e4914e1a22e0791b90958b14e81632de4976..14e8942fd3bac90595fa14dfee62454d043d60ab 100644
--- a/entity/Attribute_entity/entityfields/attribute_type/stateProcess.js
+++ b/entity/Attribute_entity/entityfields/attribute_type/stateProcess.js
@@ -1,3 +1,4 @@
+import("system.logging");
 import("system.db");
 import("system.neon");
 import("system.result");
@@ -13,12 +14,10 @@ if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT || vars.get("$sys.r
     var parentType = AttributeUtil.getAttributeType(vars.get("$field.ATTRIBUTE_PARENT_ID"));
     if (AttributeTypeUtil.isGroupType(type))
     {
-        var hasSubordinate = db.cell(SqlCondition.begin()
-            .andPrepareVars("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", "$field.UID")
-            .buildSql(
-                "select count(*) from AB_ATTRIBUTE", "1=2" //TODO: is there a way exists could be used in all dbms?
-                )
-            ) != "0";
+        var hasSubordinate = newSelect("count(*)")
+                                .from("AB_ATTRIBUTE")
+                                .where("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", "$field.UID")
+                                .cell() != "0"
         if (hasSubordinate)
             state = neon.COMPONENTSTATE_READONLY;
     }
diff --git a/entity/Attribute_entity/onValidation.js b/entity/Attribute_entity/onValidation.js
index 1c657ef6317d37e10a6b46d12f5cdc36eb430db5..f1b6c7fc1f437ab9ba090ab87e297514e884eb3a 100644
--- a/entity/Attribute_entity/onValidation.js
+++ b/entity/Attribute_entity/onValidation.js
@@ -11,9 +11,12 @@ if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
     var parentId = vars.get("$field.ATTRIBUTE_PARENT_ID");
     if (parentId)
     {
-        var cond = SqlCondition.begin().andPrepare("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", parentId);
         var maskingHelper = new SqlMaskingUtils();
-        var newCodeNumber = db.cell(cond.buildSql("select " + maskingHelper.max("AB_ATTRIBUTE.SORTING") + " from AB_ATTRIBUTE", "1 = 2"));
+        var newCodeNumber = newSelect(maskingHelper.max("AB_ATTRIBUTE.SORTING"))
+                        .from("AB_ATTRIBUTE")
+                        .where("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", parentId)
+                        .cell();
+                        
         newCodeNumber = Number(newCodeNumber);//if no number exists till no, start value will be 1 (due to: ++0)
         if (isNaN(newCodeNumber))
             throw new TypeError(translate.text("The code number is not a valid number."));
diff --git a/entity/Attribute_entity/recordcontainers/jdito/contentProcess.js b/entity/Attribute_entity/recordcontainers/jdito/contentProcess.js
index 1d07b4b9769c969d6e19b8c7c8ffd3daae70c505..a7b6c13eace48fe528b78dcaf529cb043068fc0c 100644
--- a/entity/Attribute_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/Attribute_entity/recordcontainers/jdito/contentProcess.js
@@ -15,33 +15,28 @@ var parentType = vars.exists("$param.AttrParentType_param") && vars.get("$param.
 var fetchUsages = true;
 var translateName = false;
 
-var sqlSelect = "select AB_ATTRIBUTEID, ATTRIBUTE_PARENT_ID, ATTRIBUTE_NAME, ATTRIBUTE_ACTIVE, DROPDOWNDEFINITION, DROPDOWNFILTER, SORTING, ATTRIBUTE_TYPE, " 
-    + KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.attributeType(), "ATTRIBUTE_TYPE") //3
-    + ", '', '', '' from AB_ATTRIBUTE"; 
-
-var sqlOrder = " order by ATTRIBUTE_PARENT_ID asc, SORTING asc";
-
-var condition = SqlCondition.begin();
+var condition = newWhere()
 
 if (vars.exists("$local.idvalues") && vars.get("$local.idvalues"))
 {
-    condition.andIn("AB_ATTRIBUTE.AB_ATTRIBUTEID", vars.get("$local.idvalues"));
+    condition.andIfSet("AB_ATTRIBUTE.AB_ATTRIBUTEID", vars.get("$local.idvalues"), SqlBuilder.IN());   
 }
 else if (getGroups) //if getGroups == true, it is the lookup for selecting the superordinate attribute
 {
     //this condition filters out the own id and the children to prevent loops
-    
-    var isGroupCondition = SqlCondition.begin();
+    var isGroupCondition = newWhere();
     for (let type in $AttributeTypes)
+    {
         if ($AttributeTypes[type].isGroup)
         {
-            isGroupCondition.orPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes[type]);
+            isGroupCondition.or("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes[type]);
         }
-    
-    condition.andSqlCondition(SqlCondition.begin()
-        .andSqlCondition(isGroupCondition)
-        .andPrepareVars("AB_ATTRIBUTE.AB_ATTRIBUTEID", "$param.AttrParentId_param", "# != ?")
-        .andIn("AB_ATTRIBUTE.AB_ATTRIBUTEID", AttributeUtil.getAllChildren(vars.getString("$param.AttrParentId_param")), null, true)
+    }
+        
+    condition.and(newWhere()
+                    .and(isGroupCondition)
+                    .andIfSet("AB_ATTRIBUTE.AB_ATTRIBUTEID", "$param.AttrParentId_param", "# <> ?")
+                    .andIfSet("AB_ATTRIBUTE.AB_ATTRIBUTEID", AttributeUtil.getAllChildren(vars.getString("$param.AttrParentId_param")), SqlBuilder.NOT_IN())
     );
 }
 else if (objectType)  //if there's an objectType, it comes from the AttributeRelation entity (lookup for the attribute selection)
@@ -49,7 +44,7 @@ else if (objectType)  //if there's an objectType, it comes from the AttributeRel
     var filteredAttributes = null;
     
     if (vars.exists("$param.AttributeTypes_param") && vars.getString("$param.AttributeTypes_param"))
-        condition.andIn("AB_ATTRIBUTE.ATTRIBUTE_TYPE", JSON.parse(vars.getString("$param.AttributeTypes_param")));
+        condition.and("AB_ATTRIBUTE.ATTRIBUTE_TYPE", JSON.parse(vars.getString("$param.AttributeTypes_param")), SqlBuilder.IN());
     
     if (vars.exists("$param.FilteredAttributeIds_param") && vars.getString("$param.FilteredAttributeIds_param"))
         filteredAttributes = JSON.parse(vars.getString("$param.FilteredAttributeIds_param"));
@@ -60,7 +55,7 @@ else if (objectType)  //if there's an objectType, it comes from the AttributeRel
     var ids = AttributeUtil.getPossibleAttributes(objectType, true, filteredAttributes, attributeCount);
 
     if (ids.length > 0)
-        condition.andIn("AB_ATTRIBUTE.AB_ATTRIBUTEID", ids);
+        condition.and("AB_ATTRIBUTE.AB_ATTRIBUTEID", ids, SqlBuilder.IN());
     else  // do not return anything, if parameter is there but an empty array
         condition.and("1=2");
 
@@ -73,7 +68,7 @@ else if (parentType) //condition for all subordinate attributes of an attribute
     {
         var parentId = vars.exists("$param.AttrParentId_param") && vars.get("$param.AttrParentId_param");
         if (parentId)
-            condition.andIn("AB_ATTRIBUTE.AB_ATTRIBUTEID", AttributeUtil.getAllChildren(vars.getString("$param.AttrParentId_param")));
+            condition.and("AB_ATTRIBUTE.AB_ATTRIBUTEID", AttributeUtil.getAllChildren(vars.getString("$param.AttrParentId_param")), SqlBuilder.IN());
     }
     else
         condition.and("1=2");
@@ -86,18 +81,18 @@ if (vars.exists("$local.filter") && vars.get("$local.filter"))
 {
     var filter = vars.get("$local.filter");
     if (filter.filter)
-        condition.andSqlCondition(JditoFilterUtils.getSqlCondition(filter.filter, "AB_ATTRIBUTE", undefined, {
+        condition.andIfSet(JditoFilterUtils.getSqlCondition(filter.filter, "AB_ATTRIBUTE", undefined, {
             // special filter for usage
             USAGE_FILTER : function (pValue, pOperator)
             {
-                var cond = new SqlCondition();
+                var cond = newWhere();
                 
                 switch (pOperator)
                 {
                     case "EQUAL":
-                        return cond.andPrepare(["AB_ATTRIBUTEUSAGE", "OBJECT_TYPE", "attrUse"], pValue, "exists (select 1 from AB_ATTRIBUTEUSAGE attrUse where attrUse.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID and # = ?)");
+                        return cond.and(["AB_ATTRIBUTEUSAGE", "OBJECT_TYPE", "attrUse"], pValue, "exists (select 1 from AB_ATTRIBUTEUSAGE attrUse where attrUse.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID and # = ?)");
                     case "NOT_EQUAL":
-                        return cond.andPrepare(["AB_ATTRIBUTEUSAGE", "OBJECT_TYPE", "attrUse"], pValue, "not exists (select 1 from AB_ATTRIBUTEUSAGE attrUse where attrUse.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID and # = ?)");
+                        return cond.and(["AB_ATTRIBUTEUSAGE", "OBJECT_TYPE", "attrUse"], pValue, "not exists (select 1 from AB_ATTRIBUTEUSAGE attrUse where attrUse.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID and # = ?)");
                     case "ISNULL":
                         return cond.and("not exists (select 1 from AB_ATTRIBUTEUSAGE attrUse where attrUse.AB_ATTRIBUTE_ID = AB_ATTRIBUTEID)");
                     case "ISNOTNULL":
@@ -110,10 +105,12 @@ if (vars.exists("$local.filter") && vars.get("$local.filter"))
 
 var usages;
 if (fetchUsages) //this query is only necessary in Attribute, not in AttributeRelation
-{
-    var usagesSelect = "select AB_ATTRIBUTE_ID, OBJECT_TYPE from AB_ATTRIBUTEUSAGE \n\
-                        join AB_ATTRIBUTE on AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID";
-    var usageTbl = db.table(condition.buildSql(usagesSelect, "1=1"));
+{                        
+    var usageTbl = newSelect("AB_ATTRIBUTE_ID, OBJECT_TYPE")
+             .from("AB_ATTRIBUTEUSAGE")
+             .join("AB_ATTRIBUTE", newWhere("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID"))
+             .whereIfSet(condition)
+             .table();
     usages = {};
     for (let i = 0, l = usageTbl.length; i < l; i++)
     {
@@ -125,7 +122,18 @@ if (fetchUsages) //this query is only necessary in Attribute, not in AttributeRe
     }
 }
 
-var attributes = db.table(condition.buildSql(sqlSelect, "1=1", sqlOrder));
+
+var sqlSelect = "select AB_ATTRIBUTEID, ATTRIBUTE_PARENT_ID, ATTRIBUTE_NAME, ATTRIBUTE_ACTIVE, DROPDOWNDEFINITION, DROPDOWNFILTER, SORTING, ATTRIBUTE_TYPE, " 
+    + KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.attributeType(), "ATTRIBUTE_TYPE") //3
+    + ", '', '', '' from AB_ATTRIBUTE"; 
+
+var attributes = newSelect("AB_ATTRIBUTEID, ATTRIBUTE_PARENT_ID, ATTRIBUTE_NAME, ATTRIBUTE_ACTIVE, DROPDOWNDEFINITION, DROPDOWNFILTER, SORTING, ATTRIBUTE_TYPE, " 
+                            + KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.attributeType(), "ATTRIBUTE_TYPE") //3
+                            + ", '', '', ''")
+                    .from("AB_ATTRIBUTE")
+                    .whereIfSet(condition)
+                    .orderBy("ATTRIBUTE_PARENT_ID asc, SORTING asc")
+                    .table();
 
 //TODO: attribute name caching like keywords
 var allNames = db.table("select AB_ATTRIBUTEID, ATTRIBUTE_PARENT_ID, ATTRIBUTE_NAME from AB_ATTRIBUTE");
diff --git a/entity/Attribute_entity/recordcontainers/jdito/onDelete.js b/entity/Attribute_entity/recordcontainers/jdito/onDelete.js
index 7368edfb0952b1e71b18ab71f9925a8a4e3df075..f24ac8dd8f5c55cc5a4fcebc51172f524b83af2c 100644
--- a/entity/Attribute_entity/recordcontainers/jdito/onDelete.js
+++ b/entity/Attribute_entity/recordcontainers/jdito/onDelete.js
@@ -3,33 +3,21 @@ import("system.db");
 import("system.vars");
 import("Attribute_lib");
 
-var condition = SqlCondition.begin()
-    .andPrepareVars("AB_ATTRIBUTE.AB_ATTRIBUTEID", "$field.UID")
-    .build("1=2");
-
-db.deleteData("AB_ATTRIBUTE", condition);
+newWhere("AB_ATTRIBUTE.AB_ATTRIBUTEID", "$field.UID")
+    .deleteData(true, "AB_ATTRIBUTE");
 
 var attributeId = vars.get("$field.UID");
 
 var childIds = AttributeUtil.getAllChildren(attributeId).concat(attributeId);
 
-condition = SqlCondition.begin()
-    .andIn("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", childIds)
-    .build();
-
 //delete all entries in AB_ATTRIBUTEUSAGE belonging to the attribute to avoid unrelated entries
-db.deleteData("AB_ATTRIBUTEUSAGE", condition);
-
-condition = SqlCondition.begin()
-    .andIn("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID", childIds)
-    .build();
+newWhereIfSet("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", childIds, SqlBuilder.IN())
+    .deleteData(true, "AB_ATTRIBUTEUSAGE");
 
 //delete all entries in AB_ATTRIBUTERELATION for the attributes
-db.deleteData("AB_ATTRIBUTERELATION", condition);
-
-condition = SqlCondition.begin()
-    .andIn("AB_ATTRIBUTE.AB_ATTRIBUTEID", childIds)
-    .build();
+newWhereIfSet("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID", childIds, SqlBuilder.IN())
+    .deleteData(true, "AB_ATTRIBUTERELATION");
 
 //delete all attribute children
-db.deleteData("AB_ATTRIBUTE", condition);
+newWhereIfSet("AB_ATTRIBUTE.AB_ATTRIBUTEID", childIds, SqlBuilder.IN())
+    .deleteData(true, "AB_ATTRIBUTE");
diff --git a/entity/Attribute_entity/recordcontainers/jdito/onUpdate.js b/entity/Attribute_entity/recordcontainers/jdito/onUpdate.js
index 6150eacfd7a0ae0c76d95332f55417eefa5de6b3..8d2c892612d6103d2cf92218c85e25e95b353546 100644
--- a/entity/Attribute_entity/recordcontainers/jdito/onUpdate.js
+++ b/entity/Attribute_entity/recordcontainers/jdito/onUpdate.js
@@ -21,5 +21,6 @@ var values = [
     rowdata["DROPDOWNFILTER.value"] || "",
     rowdata["SORTING.value"] || ""
 ];
-db.updateData("AB_ATTRIBUTE", columns, null, values, 
-    SqlCondition.equals("AB_ATTRIBUTE.AB_ATTRIBUTEID", vars.get("$field.UID"), "1=2"));
\ No newline at end of file
+
+newWhere("AB_ATTRIBUTE.AB_ATTRIBUTEID", "$field.UID")
+    .updateData(true, columns, null, values, "AB_ATTRIBUTE");
\ No newline at end of file
diff --git a/entity/BulkMailAddRecipients_entity/entityfields/bulkmail_id/displayValueProcess.js b/entity/BulkMailAddRecipients_entity/entityfields/bulkmail_id/displayValueProcess.js
index 697ac6b05dfa6d465e9235433e3b889489cb57dc..908c3e0ae7eaa406fd40e4fe5aeaf0b03822df9d 100644
--- a/entity/BulkMailAddRecipients_entity/entityfields/bulkmail_id/displayValueProcess.js
+++ b/entity/BulkMailAddRecipients_entity/entityfields/bulkmail_id/displayValueProcess.js
@@ -4,6 +4,10 @@ import("system.db");
 import("system.result");
 
 if (vars.get("$this.value"))
-    result.string(db.cell(SqlCondition.begin().andPrepare("BULKMAIL.BULKMAILID", vars.get("$this.value")).buildSql("select NAME from BULKMAIL")));
+    result.string(newSelect("NAME")
+                    .from("BULKMAIL")
+                    .where("BULKMAIL.BULKMAILID", "$this.value")
+                    .buildSql("select NAME from BULKMAIL")
+                    .cell());
 else
     result.string("");
\ No newline at end of file
diff --git a/entity/BulkMailChart_entity/recordcontainers/jdito/contentProcess.js b/entity/BulkMailChart_entity/recordcontainers/jdito/contentProcess.js
index 0869420384ccec1e8f1d42e8c2658734e3e3df7c..4f854db0030823fc7bba0a3435179b3b4c3ba80f 100644
--- a/entity/BulkMailChart_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/BulkMailChart_entity/recordcontainers/jdito/contentProcess.js
@@ -10,7 +10,7 @@ var bulkMailId = vars.get("$param.BulkMailId_param");
 var query = SqlBuilder.begin()
     .select(["STATUS", "STATUS", KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.bulkMailRecipientStatus(), "STATUS"), "count(STATUS)"])
     .from("BULKMAILRECIPIENT")
-    .where(SqlCondition.begin().andPrepare("BULKMAILRECIPIENT.BULKMAIL_ID", bulkMailId))
+    .where("BULKMAILRECIPIENT.BULKMAIL_ID", bulkMailId)
     .groupBy("STATUS");
 
 result.object(db.table(query.build()));
\ No newline at end of file
diff --git a/entity/BulkMailRecipient_entity/entityfields/recipientactions/children/removewithcommrestriction/onActionProcess.js b/entity/BulkMailRecipient_entity/entityfields/recipientactions/children/removewithcommrestriction/onActionProcess.js
index 2c077471d71f89ca3e62c06fa1ec207c5a5b61d2..39179f6988f0b58a40582cc7a18a67b729266368 100644
--- a/entity/BulkMailRecipient_entity/entityfields/recipientactions/children/removewithcommrestriction/onActionProcess.js
+++ b/entity/BulkMailRecipient_entity/entityfields/recipientactions/children/removewithcommrestriction/onActionProcess.js
@@ -7,18 +7,13 @@ import("system.db");
 var recipientIds = db.array(db.COLUMN, SqlBuilder.begin()
     .select("BULKMAILRECIPIENTID")
     .from("BULKMAILRECIPIENT")
-    .join("CONTACT", SqlCondition.begin()
+    .join("CONTACT", newWhere()
         .and("BULKMAILRECIPIENT.CONTACT_ID = CONTACT.CONTACTID")
-        .andSqlCondition(ContactUtils.getCommRestrictionCondition($KeywordRegistry.communicationMediumCampaign$mail())))
-    .where(SqlCondition.begin()
-        .andPrepareVars("BULKMAILRECIPIENT.BULKMAIL_ID", "$param.BulkMailId_param"))
+        .and(ContactUtils.getCommRestrictionCondition($KeywordRegistry.communicationMediumCampaign$mail())))
+    .whereIfSet("BULKMAILRECIPIENT.BULKMAIL_ID", "$param.BulkMailId_param")
     .build());
 
-if (recipientIds.length)
-{
-    db.deleteData("BULKMAILRECIPIENT", SqlCondition.begin()
-        .andIn("BULKMAILRECIPIENT.BULKMAILRECIPIENTID", recipientIds)
-        .build("1=2"));
-}
+newWhereIfSet("BULKMAILRECIPIENT.BULKMAILRECIPIENTID", recipientIds, SqlBuilder.IN())
+    .deleteData(true, "BULKMAILRECIPIENT")
 
 neon.refreshAll();
\ No newline at end of file
diff --git a/entity/BulkMailRecipient_entity/recordcontainers/db/conditionProcess.js b/entity/BulkMailRecipient_entity/recordcontainers/db/conditionProcess.js
index 4c1c1c0723bdbf3a10f0ee85c8b613991ea5ee82..a2473cad7ca8ee6904811861505e0e412ab6c6fa 100644
--- a/entity/BulkMailRecipient_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/BulkMailRecipient_entity/recordcontainers/db/conditionProcess.js
@@ -2,8 +2,5 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var condition = SqlCondition.begin()
-    .andPrepareVars("BULKMAILRECIPIENT.BULKMAIL_ID", "$param.BulkMailId_param");
-
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(condition.translate("1=1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(newWhere("BULKMAILRECIPIENT.BULKMAIL_ID", "$param.BulkMailId_param").toString());
\ No newline at end of file
diff --git a/entity/BulkMailRecipient_entity/recordcontainers/db/recordfieldmappings/hascommrestriction.value/expression.js b/entity/BulkMailRecipient_entity/recordcontainers/db/recordfieldmappings/hascommrestriction.value/expression.js
index 4ccc89e551dc740bee9a7fdeee8f0b3928598391..3020cb618cdf0f0aac9fbf0f9201753a29563a37 100644
--- a/entity/BulkMailRecipient_entity/recordcontainers/db/recordfieldmappings/hascommrestriction.value/expression.js
+++ b/entity/BulkMailRecipient_entity/recordcontainers/db/recordfieldmappings/hascommrestriction.value/expression.js
@@ -4,6 +4,6 @@ import("Contact_lib");
 import("system.db");
 import("system.result");
 
-var commRestrictionCond = ContactUtils.getCommRestrictionCondition($KeywordRegistry.communicationMediumCampaign$mail()).build();
-var sql = "case when (" + SqlUtils.translateStatementWithQuotes(commRestrictionCond) + ") then 'true' else 'false' end";
+var commRestrictionCond = ContactUtils.getCommRestrictionCondition($KeywordRegistry.communicationMediumCampaign$mail());
+var sql = "case when (" + commRestrictionCond.toString() + ") then 'true' else 'false' end";
 result.string(sql);
diff --git a/entity/BulkMailStatusChart_entity/recordcontainers/jdito/contentProcess.js b/entity/BulkMailStatusChart_entity/recordcontainers/jdito/contentProcess.js
index 2057fed00fd1beb8adc1fc585970352ecff790a0..10a4345cc3eeec606b825ea2d8485b0a2333b97c 100644
--- a/entity/BulkMailStatusChart_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/BulkMailStatusChart_entity/recordcontainers/jdito/contentProcess.js
@@ -8,9 +8,9 @@ import("system.vars");
 var bulkMailId = vars.get("$param.BulkMailId_param");
 
 var query = SqlBuilder.begin()
-    .select(["STATUS", "STATUS", KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.bulkMailRecipientStatus(), "STATUS"), "count(STATUS)"])
-    .from("BULKMAILRECIPIENT")
-    .where(SqlCondition.begin().andPrepare("BULKMAILRECIPIENT.BULKMAIL_ID", bulkMailId))
-    .groupBy("STATUS");
+                .select(["STATUS", "STATUS", KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.bulkMailRecipientStatus(), "STATUS"), "count(STATUS)"])
+                .from("BULKMAILRECIPIENT")
+                .where("BULKMAILRECIPIENT.BULKMAIL_ID", bulkMailId)
+                .groupBy("STATUS");
 
 result.object(db.table(query.build()));
\ No newline at end of file
diff --git a/entity/BulkMailTesting_entity/entityfields/testing_contact_id/valueProcess.js b/entity/BulkMailTesting_entity/entityfields/testing_contact_id/valueProcess.js
index 49dff7de739727af391d894fa9afd4d63d0a5f0c..864b32ebe8d9788e901116720f75fc8f1f7fe878 100644
--- a/entity/BulkMailTesting_entity/entityfields/testing_contact_id/valueProcess.js
+++ b/entity/BulkMailTesting_entity/entityfields/testing_contact_id/valueProcess.js
@@ -4,10 +4,11 @@ import("Employee_lib");
 import("system.vars");
 import("system.result");
 
-var contactId = db.cell(SqlCondition.begin()
-    .andPrepareVars("BULKMAIL.BULKMAILID", "$param.BulkMailId_param")
-    .buildSql("select TESTING_CONTACT_ID from BULKMAIL")
-);
+var contactId = newSelect("TESTING_CONTACT_ID")
+                    .from("BULKMAIL")
+                    .whereIfSet("BULKMAIL.BULKMAILID", "$param.BulkMailId_param")
+                    .cell(true);
+                    
 if (!contactId)
     contactId = EmployeeUtils.getCurrentContactId();
     
diff --git a/entity/BulkMailTesting_entity/entityfields/testing_email_address/valueProcess.js b/entity/BulkMailTesting_entity/entityfields/testing_email_address/valueProcess.js
index 261b02cb666e2bdeb75a544dd1ad646dece04c1e..283e49626aec2316433cad2543f8b9c32b46215a 100644
--- a/entity/BulkMailTesting_entity/entityfields/testing_email_address/valueProcess.js
+++ b/entity/BulkMailTesting_entity/entityfields/testing_email_address/valueProcess.js
@@ -4,9 +4,10 @@ import("Employee_lib");
 import("system.vars");
 import("system.result");
 
-var email = db.cell(SqlCondition.begin()
-    .andPrepareVars("BULKMAIL.BULKMAILID", "$param.BulkMailId_param")
-    .buildSql("select TESTING_EMAIL_ADDRESS from BULKMAIL")
-);
+var email = newSelect("TESTING_EMAIL_ADDRESS")
+                .from("BULKMAIL")
+                .whereIfSet("BULKMAIL.BULKMAILID", "$param.BulkMailId_param")
+                .cell(true);
+                
 if (vars.get("$this.value") == null)
     result.string(email);
\ No newline at end of file
diff --git a/entity/BulkMailTesting_entity/recordcontainers/jdito/onInsert.js b/entity/BulkMailTesting_entity/recordcontainers/jdito/onInsert.js
index a2489e0b7b3772dbf08cb0cf881774f3bc0193c4..3fd6cda99e8f2273b38eb4a9e5cf53553f90e669 100644
--- a/entity/BulkMailTesting_entity/recordcontainers/jdito/onInsert.js
+++ b/entity/BulkMailTesting_entity/recordcontainers/jdito/onInsert.js
@@ -11,6 +11,6 @@ BulkMailUtils.sendBulkMailOnServer(bulkMailId, [[testingContact, testingEmail]])
 
 if (vars.get("$field.SAVESETTINGS") == "1")
 {
-    db.updateData("BULKMAIL", ["TESTING_CONTACT_ID", "TESTING_EMAIL_ADDRESS"], null, [testingContact, testingEmail], 
-        SqlCondition.equals("BULKMAIL.BULKMAILID", bulkMailId));
+    newWhere("BULKMAIL.BULKMAILID", bulkMailId)
+        .updateData(true, ["TESTING_CONTACT_ID", "TESTING_EMAIL_ADDRESS"], null, [testingContact, testingEmail], "BULKMAIL");
 }
\ No newline at end of file
diff --git a/entity/BulkMail_entity/entityfields/sendmail/onActionProcess.js b/entity/BulkMail_entity/entityfields/sendmail/onActionProcess.js
index 4a316db7db175aae1530bb366fe02086d1702f45..857f71578f0d721d24548ba5f6d65cdd2fd783e7 100644
--- a/entity/BulkMail_entity/entityfields/sendmail/onActionProcess.js
+++ b/entity/BulkMail_entity/entityfields/sendmail/onActionProcess.js
@@ -10,8 +10,9 @@ import("KeywordRegistry_basic");
 var send = question.askYesNo(translate.text("Bulk mail"), translate.text("Should the mail be sent now?"), false);
 if (send)
 {
-    db.updateData("BULKMAIL", ["STATUS"], null, [$KeywordRegistry.bulkMailStatus$beingSent()], 
-        SqlCondition.equals("BULKMAIL.BULKMAILID", vars.get("$field.BULKMAILID"), "1=2"));
+    newWhere("BULKMAIL.BULKMAILID", vars.get("$field.BULKMAILID"))
+        .updateData(true, ["STATUS"], null, [$KeywordRegistry.bulkMailStatus$beingSent()], "BULKMAIL");
+    
     neon.refreshAll();
     BulkMailUtils.sendBulkMailOnServer(vars.get("$field.BULKMAILID"));
 }
\ No newline at end of file
diff --git a/entity/BulkMail_entity/recordcontainers/db/conditionProcess.js b/entity/BulkMail_entity/recordcontainers/db/conditionProcess.js
index 5898e63c93b3565ce9afee8d251c8800e62c6683..114bc7ba5a6f35edd1be22cbb150d7f47add0d7e 100644
--- a/entity/BulkMail_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/BulkMail_entity/recordcontainers/db/conditionProcess.js
@@ -1,7 +1,4 @@
 import("system.result");
 import("Sql_lib");
 
-var cond = new SqlCondition()
-    .andPrepareVars("BULKMAIL.STATUS", "$param.BulkMailStatus_param");
-
-result.string(cond.translate("1=1"));
\ No newline at end of file
+result.string(newWhereIfSet("BULKMAIL.STATUS", "$param.BulkMailStatus_param").toString());
\ No newline at end of file
diff --git a/entity/BulkMail_entity/recordcontainers/db/onDBDelete.js b/entity/BulkMail_entity/recordcontainers/db/onDBDelete.js
index 8ae5ed9a343fa515dd660cbf3446edac2bf36c41..902488b10ed58e73d75c90dbf13a5c80fb88299c 100644
--- a/entity/BulkMail_entity/recordcontainers/db/onDBDelete.js
+++ b/entity/BulkMail_entity/recordcontainers/db/onDBDelete.js
@@ -2,11 +2,14 @@ import("system.vars");
 import("Sql_lib");
 import("system.db");
 
-db.deleteData("BULKMAILRECIPIENT", SqlCondition.equals("BULKMAILRECIPIENT.BULKMAIL_ID", vars.get("$local.uid"), "1=2"));
+newWhere("BULKMAILRECIPIENT.BULKMAIL_ID", vars.get("$local.uid"))
+    .deleteData(true, "BULKMAILRECIPIENT");
+
 var SYSALIAS = SqlUtils.getBinariesAlias();
-var binaryId = db.cell(SqlCondition.begin(SYSALIAS)
-    .andPrepareVars("ASYS_BINARIES.ROW_ID", "$local.uid")
-    .buildSql("select ID from ASYS_BINARIES"), SYSALIAS);
+var binaryId = newSelect("ID", SYSALIAS)
+                 .from("ASYS_BINARIES")
+                 .where("ASYS_BINARIES.ROW_ID", "$local.uid")
+                 .cell();
 
 if (binaryId)
     db.deleteBinary(binaryId, SYSALIAS);
\ No newline at end of file
diff --git a/entity/BulkMail_entity/recordcontainers/db/onDBUpdate.js b/entity/BulkMail_entity/recordcontainers/db/onDBUpdate.js
index 053ba668100f674c227a29969e40c41c2b0eadd8..daf4625956496cec2e95fbd13c6fa66b6d674729 100644
--- a/entity/BulkMail_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/BulkMail_entity/recordcontainers/db/onDBUpdate.js
@@ -24,9 +24,11 @@ if (template.content)
     if (!template.filename)
         template.filename = bulkMailName + ".html";
     let sysAlias = SqlUtils.getBinariesAlias();
-    var binaryId = db.cell(SqlCondition.begin(sysAlias)
-        .andPrepareVars("ASYS_BINARIES.ROW_ID", "$local.uid")
-        .buildSql("select ID from ASYS_BINARIES", "1=2"), sysAlias);
+    var binaryId = newSelect("ID", sysAlias)
+                        .from("ASYS_BINARIES")
+                        .where("ASYS_BINARIES.ROW_ID", "$local.uid")
+                        .cell()
+        
     db.updateBinary(binaryId, "", template.content, template.filename, "", "", sysAlias);
     neon.refresh(["$field.content"]);
 }
\ No newline at end of file
diff --git a/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js b/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js
index 77b64092bdb0a66d9dab7725677aef4290e5d74d..f4d6e6e52bfa78e1ec984b28790a65a37d221d6e 100644
--- a/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js
+++ b/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js
@@ -30,7 +30,7 @@ if(selectedCampaignId != '')
     var countParticipantsAlreadyInCampaign = 0;
     var countParticipantsToAdd = 0;
     var countValidParticipantsToAdd = 0;
-    var whereCondition = SqlCondition.begin();
+    var whereCondition = newWhere();
     var rowIdsComparisonField = "";
         
     //if theres a selection, we have to use it, otherwise use the condition
@@ -48,13 +48,13 @@ if(selectedCampaignId != '')
          */
         if(isUpdate == "true")
         {
-            whereCondition.andPrepare("CAMPAIGNPARTICIPANT.CAMPAIGNSTEP_ID", selectedCampaignStepId);
-            whereCondition.andIn("CAMPAIGNPARTICIPANT.CAMPAIGNPARTICIPANTID", selectionRowIds)
+            whereCondition.and("CAMPAIGNPARTICIPANT.CAMPAIGNSTEP_ID", selectedCampaignStepId);
+            whereCondition.and("CAMPAIGNPARTICIPANT.CAMPAIGNPARTICIPANTID", selectionRowIds, SqlBuilder.IN())
         }
         else
         {
-            whereCondition.andPrepare("CAMPAIGNPARTICIPANT.CAMPAIGN_ID", selectedCampaignId);
-            whereCondition.andIn("CAMPAIGNPARTICIPANT.CONTACT_ID", selectionRowIds)
+            whereCondition.and("CAMPAIGNPARTICIPANT.CAMPAIGN_ID", selectedCampaignId);
+            whereCondition.and("CAMPAIGNPARTICIPANT.CONTACT_ID", selectionRowIds, SqlBuilder.IN())
         }
         countParticipantsAlreadyInCampaign = CampaignUtils.GetParticipantsCountByCondition(whereCondition);
     }
@@ -81,9 +81,9 @@ if(selectedCampaignId != '')
          * step because one participant can be in a campaign just once.
          */
         if(isUpdate == "true")
-            whereCondition.andPrepare("CAMPAIGNPARTICIPANT.CAMPAIGNSTEP_ID", selectedCampaignStepId);
+            whereCondition.and("CAMPAIGNPARTICIPANT.CAMPAIGNSTEP_ID", selectedCampaignStepId);
         else
-            whereCondition.andPrepare("CAMPAIGNPARTICIPANT.CAMPAIGN_ID", selectedCampaignId);
+            whereCondition.and("CAMPAIGNPARTICIPANT.CAMPAIGN_ID", selectedCampaignId);
 
         whereCondition.and(participantCondition);
         countParticipantsAlreadyInCampaign = CampaignUtils.GetParticipantsAlreadyAddedCountByCondition(whereCondition, useRightJoinToGetOrgs);
diff --git a/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js b/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js
index 81aeb47b23e5a0d9fe087f701064397826b41c3a..95c8bcbdf767eaca6e770385ae73574c27857a48 100644
--- a/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js
+++ b/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js
@@ -73,10 +73,11 @@ function _handleRowIds(pParticipantRowIds)
                  "DATE_EDIT"
                 ];
         
-        let oldSteps = db.table(SqlCondition.begin()
-            .orIn("CAMPAIGNPARTICIPANT.CAMPAIGNPARTICIPANTID", pParticipantRowIds)
-            .buildSql("select CAMPAIGNPARTICIPANTID, CAMPAIGNSTEP_ID from CAMPAIGNPARTICIPANT", "1=2")
-        );
+        let oldSteps = newSelect("CAMPAIGNPARTICIPANTID, CAMPAIGNSTEP_ID")
+                        .from("CAMPAIGNPARTICIPANT")
+                        .whereIfSet("CAMPAIGNPARTICIPANT.CAMPAIGNPARTICIPANTID", pParticipantRowIds, SqlBuilder.IN())
+                        .table(true);
+                        
         oldSteps.forEach(function (step)
         {
             this[step[0]] = step[1];
@@ -107,18 +108,20 @@ function _handleRowIds(pParticipantRowIds)
                             vars.get("$sys.user"),
                             vars.get("$sys.date")];
 
-            let condition = "CONTACT_ID = '" + pParticipantRowIds[participant] + "' OR CAMPAIGNPARTICIPANTID = '" + pParticipantRowIds[participant] + "'";
+            let condition = newWhere("CAMPAIGNPARTICIPANT.CONTACT_ID", pParticipantRowIds[participant])
+                                 .or("CAMPAIGNPARTICIPANT.CAMPAIGNPARTICIPANTID", pParticipantRowIds[participant]);
+                                 
             let valsCampaignParticipantLog = [
                 pParticipantRowIds[participant], 
                 campaignId, 
                 newCampaignStepId, 
-                campaignParticipantLogId, 
+                campaignParticipantLogId,
                 vars.get("$sys.user"), 
                 vars.get("$sys.date"), 
                 oldCampaignStepId
             ];
 
-            statementArray.push(["CAMPAIGNPARTICIPANT", cols, null, updatedValues, condition]);
+            statementArray.push(["CAMPAIGNPARTICIPANT", cols, null, updatedValues, condition.build()]);
             logArray.push(["CAMPAIGNPARTICIPANTLOG", colNamesCampaignParticipantLog, null, valsCampaignParticipantLog]);
         }
         else
diff --git a/entity/CampaignAnalysis_entity/entityfields/currency/valueProcess.js b/entity/CampaignAnalysis_entity/entityfields/currency/valueProcess.js
index 0707325468559c403e49b8cb1410dcfda71b81e5..fa96a8a7bb87aee62f055b6558db9282815c7d4b 100644
--- a/entity/CampaignAnalysis_entity/entityfields/currency/valueProcess.js
+++ b/entity/CampaignAnalysis_entity/entityfields/currency/valueProcess.js
@@ -2,6 +2,7 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-result.string(db.cell(SqlCondition.begin()
-    .andPrepareVars("CAMPAIGN.CAMPAIGNID", "$param.CampaignId_param")
-    .buildSql("select CURRENCY from CAMPAIGN", "1=2")));
\ No newline at end of file
+result.string(newSelect("CURRENCY")
+                .from("CAMPAIGN")
+                .whereIfSet("CAMPAIGN.CAMPAIGNID", "$param.CampaignId_param")
+                .cell());
\ No newline at end of file
diff --git a/entity/CampaignAnalysis_entity/entityfields/fixcosts/valueProcess.js b/entity/CampaignAnalysis_entity/entityfields/fixcosts/valueProcess.js
index 9168ac075a609e9edf1b61e26c867bbcb511445b..ab128c2bf1641e31263a055bc8fb71d59a692368 100644
--- a/entity/CampaignAnalysis_entity/entityfields/fixcosts/valueProcess.js
+++ b/entity/CampaignAnalysis_entity/entityfields/fixcosts/valueProcess.js
@@ -2,7 +2,8 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-result.string(db.cell(SqlCondition.begin()
-            .andPrepareVars("CAMPAIGNCOST.CAMPAIGN_ID", "$param.CampaignId_param")
-            .and("CAMPAIGNSTEP_ID is null")
-            .buildSql("select sum(NET) from CAMPAIGNCOST", "1=2")));
\ No newline at end of file
+result.string(newSelect("sum(NET)")
+                  .from("CAMPAIGNCOST")
+                  .whereIfSet("CAMPAIGNCOST.CAMPAIGN_ID", "$param.CampaignId_param")
+                  .and("CAMPAIGNSTEP_ID is null")
+                  .cell());
\ No newline at end of file
diff --git a/entity/CampaignAnalysis_entity/entityfields/variablecosts/valueProcess.js b/entity/CampaignAnalysis_entity/entityfields/variablecosts/valueProcess.js
index 2899b3d67bb637dd7d9acf5696fcc5033e1db5e4..9ab2aa6361670f65b562d856ef5d1f14171fcba8 100644
--- a/entity/CampaignAnalysis_entity/entityfields/variablecosts/valueProcess.js
+++ b/entity/CampaignAnalysis_entity/entityfields/variablecosts/valueProcess.js
@@ -2,7 +2,8 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-result.string(db.cell(SqlCondition.begin()
-            .andPrepareVars("CAMPAIGNCOST.CAMPAIGN_ID", "$param.CampaignId_param")
-            .and("CAMPAIGNSTEP_ID is not null")
-            .buildSql("select sum(NET) from CAMPAIGNCOST", "1=2")));
\ No newline at end of file
+result.string(newSelect("sum(NET)")
+                .from("CAMPAIGNCOST")
+                .whereIfSet("CAMPAIGNCOST.CAMPAIGN_ID", "$param.CampaignId_param")
+                .and("CAMPAIGNSTEP_ID is not null")
+                .cell());
\ No newline at end of file
diff --git a/entity/CampaignCostChart_entity/recordcontainers/jdito/contentProcess.js b/entity/CampaignCostChart_entity/recordcontainers/jdito/contentProcess.js
index e6bc1f8b2a23816cdfe1b16473df3c10d1f45cb6..262624f94cc0ab7ce11828de30b447312f4e6c2c 100644
--- a/entity/CampaignCostChart_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/CampaignCostChart_entity/recordcontainers/jdito/contentProcess.js
@@ -11,13 +11,14 @@ import("Campaign_lib");
 var campaignId = vars.get("$param.CampaignId_param");
 var campaignName = CampaignUtils.getCampaignNameById(campaignId);
 
-var costSqlSelect = "select CAMPAIGNCOSTID, CAMPAIGNSTEP_ID, CAMPAIGNSTEP.NAME, CATEGORY, " 
+var costSqlFields = "CAMPAIGNCOSTID, CAMPAIGNSTEP_ID, CAMPAIGNSTEP.NAME, CATEGORY, " 
     + KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.campaignStepCostCategory(), "CAMPAIGNCOST.CATEGORY") 
-    + ", NET from CAMPAIGNCOST left join CAMPAIGNSTEP on CAMPAIGNSTEP_ID = CAMPAIGNSTEPID";
-var costData = db.table(SqlCondition.begin()
-    .andPrepare("CAMPAIGNCOST.CAMPAIGN_ID", campaignId)
-    .buildSql(costSqlSelect, "1=2")
-);
+    + ", NET";
+var costData = newSelect(costSqlFields)
+                    .from("CAMPAIGNCOST")
+                    .leftJoin("CAMPAIGNSTEP", newWhere("CAMPAIGNSTEP_ID = CAMPAIGNSTEPID"))
+                    .where("CAMPAIGNCOST.CAMPAIGN_ID", campaignId)
+                    .table();
 
 var types = {
     FIX : "FIX",
diff --git a/entity/CampaignCost_entity/entityfields/keywordcampaignmanagementcostcategory/children/excludedkeyidssubquery_param/valueProcess.js b/entity/CampaignCost_entity/entityfields/keywordcampaignmanagementcostcategory/children/excludedkeyidssubquery_param/valueProcess.js
index aab867d773215c3d8721fb02878ca7b34c173dc1..5ad04d9cf8c02b31fc2aed3eaed0858b543c747e 100644
--- a/entity/CampaignCost_entity/entityfields/keywordcampaignmanagementcostcategory/children/excludedkeyidssubquery_param/valueProcess.js
+++ b/entity/CampaignCost_entity/entityfields/keywordcampaignmanagementcostcategory/children/excludedkeyidssubquery_param/valueProcess.js
@@ -4,15 +4,17 @@ import("system.db");
 import("Sql_lib");
 import("system.result");
 
-var cond = SqlCondition.begin()
-                       .andPrepareVars("CAMPAIGNCOST.CAMPAIGN_ID", "$field.CAMPAIGN_ID");
+var cond = newSelect("CATEGORY")
+                .from("CAMPAIGNCOST")
+                .groupBy("CATEGORY")
+                .whereIfSet("CAMPAIGNCOST.CAMPAIGN_ID", "$field.CAMPAIGN_ID");
 
 if (vars.get("$field.CAMPAIGNSTEP_ID"))
-    cond.andPrepareVars("CAMPAIGNCOST.CAMPAIGNSTEP_ID", "$field.CAMPAIGNSTEP_ID");
+    cond.andIfSet("CAMPAIGNCOST.CAMPAIGNSTEP_ID", "$field.CAMPAIGNSTEP_ID");
 else
     cond.and("CAMPAIGNCOST.CAMPAIGNSTEP_ID is null")
     
 if (vars.get("$sys.recordstate") != neon.OPERATINGSTATE_NEW)
-    cond.andPrepareVars("CAMPAIGNCOST.CAMPAIGNCOSTID", "$field.CAMPAIGNCOSTID", "# <> ?");
+    cond.andIfSet("CAMPAIGNCOST.CAMPAIGNCOSTID", "$field.CAMPAIGNCOSTID", "# <> ?");
 
-result.string(SqlUtils.translateStatementWithQuotes(cond.buildSql("select CATEGORY from CAMPAIGNCOST", "1=2", "group by CATEGORY")));
\ No newline at end of file
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/CampaignCost_entity/recordcontainers/db/conditionProcess.js b/entity/CampaignCost_entity/recordcontainers/db/conditionProcess.js
index ae648de52138a58672e04d6d71882c944c4a2e1f..0d440b3273654c53a9eb47fa0da830499214b1a0 100644
--- a/entity/CampaignCost_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/CampaignCost_entity/recordcontainers/db/conditionProcess.js
@@ -3,12 +3,12 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = SqlCondition.begin()
-                       .andPrepareVars("CAMPAIGNCOST.CAMPAIGNCOSTID", "$param.Uid_param")
-                       .andPrepareVars("CAMPAIGNCOST.CAMPAIGN_ID", "$param.CampaignId_param")
-                       .andPrepareVars("CAMPAIGNCOST.CAMPAIGNSTEP_ID", "$param.CampaignStepId_param");
+var cond = newWhere()
+            .andIfSet("CAMPAIGNCOST.CAMPAIGNCOSTID", "$param.Uid_param")
+            .andIfSet("CAMPAIGNCOST.CAMPAIGN_ID", "$param.CampaignId_param")
+            .andIfSet("CAMPAIGNCOST.CAMPAIGNSTEP_ID", "$param.CampaignStepId_param");
                        
-if (vars.exists("$param.CampaignSteps_param") && vars.get("$param.CampaignSteps_param") == "1")
+if (vars.get("$param.CampaignSteps_param") == "1")
 {
     // only step costs
     cond.and("CAMPAIGNCOST.CAMPAIGNSTEP_ID is not null");
@@ -19,5 +19,5 @@ else
     cond.and("CAMPAIGNCOST.CAMPAIGNSTEP_ID is null");
 }
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1=2"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/CampaignParticipantChart_entity/recordcontainers/jdito/contentProcess.js b/entity/CampaignParticipantChart_entity/recordcontainers/jdito/contentProcess.js
index c0de8da56a189d7fc6347b135c79685f7a76468d..bb8e07562d306e2b1464bbbc8850ea60cf5e117f 100644
--- a/entity/CampaignParticipantChart_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/CampaignParticipantChart_entity/recordcontainers/jdito/contentProcess.js
@@ -5,21 +5,17 @@ import("Sql_lib");
 import("system.vars");
 
 var campaignId = vars.get("$param.CampaignId_param");
-
-var sqlSelect = "select CAMPAIGNSTEPID, CAMPAIGNSTEP.NAME, count(distinct CAMPAIGNPARTICIPANTID), MAXPARTICIPANTS, count(distinct CAMPAIGNPARTICIPANTLOG.CAMPAIGNPARTICIPANT_ID) \n\
-    from CAMPAIGNSTEP \n\
-    left join CAMPAIGNPARTICIPANT on CAMPAIGNSTEPID = CAMPAIGNPARTICIPANT.CAMPAIGNSTEP_ID \n\
-    left join CAMPAIGNPARTICIPANTLOG on CAMPAIGNSTEPID = CAMPAIGNPARTICIPANTLOG.PREVIOUS_CAMPAIGNSTEP_ID and CAMPAIGNPARTICIPANTLOG.CAMPAIGNSTEP_ID != CAMPAIGNPARTICIPANTLOG.PREVIOUS_CAMPAIGNSTEP_ID";
-     //Participated: counts all distinct CAMPAIGNPARTICIPANT_IDs from logs where the PREVIOUS_CAMPAIGNSTEP_ID is the id of the campaign step. Logs where
-     //the new CAMPAIGNSTEP_ID is the same as the PREVIOUS_CAMPAIGNSTEP_ID are not counted. This does not check if the SORTING is correct.
-
-var sqlGroupOrderBy = "group by CAMPAIGNSTEPID, CAMPAIGNSTEP.NAME, MAXPARTICIPANTS, CAMPAIGNSTEP.SORTING order by CAMPAIGNSTEP.SORTING";
-
-var sqlQuery = SqlCondition.begin()
-    .andPrepare("CAMPAIGNSTEP.CAMPAIGN_ID", campaignId)
-    .buildSql(sqlSelect, "1=2", sqlGroupOrderBy);
-
-var stepData = db.table(sqlQuery);
+     
+//Participated: counts all distinct CAMPAIGNPARTICIPANT_IDs from logs where the PREVIOUS_CAMPAIGNSTEP_ID is the id of the campaign step. Logs where
+//the new CAMPAIGNSTEP_ID is the same as the PREVIOUS_CAMPAIGNSTEP_ID are not counted. This does not check if the SORTING is correct.
+var stepData = newSelect("CAMPAIGNSTEPID, CAMPAIGNSTEP.NAME, count(distinct CAMPAIGNPARTICIPANTID), MAXPARTICIPANTS, count(distinct CAMPAIGNPARTICIPANTLOG.CAMPAIGNPARTICIPANT_ID)")
+                    .from("CAMPAIGNSTEP")
+                    .leftJoin("CAMPAIGNPARTICIPANT", "CAMPAIGNSTEPID = CAMPAIGNPARTICIPANT.CAMPAIGNSTEP_ID")
+                    .leftJoin("CAMPAIGNPARTICIPANTLOG", "CAMPAIGNSTEPID = CAMPAIGNPARTICIPANTLOG.PREVIOUS_CAMPAIGNSTEP_ID and CAMPAIGNPARTICIPANTLOG.CAMPAIGNSTEP_ID != CAMPAIGNPARTICIPANTLOG.PREVIOUS_CAMPAIGNSTEP_ID")
+                    .groupBy("CAMPAIGNSTEPID, CAMPAIGNSTEP.NAME, MAXPARTICIPANTS, CAMPAIGNSTEP.SORTING")
+                    .orderBy("CAMPAIGNSTEP.SORTING")
+                    .where("CAMPAIGNSTEP.CAMPAIGN_ID", campaignId)
+                    .table()
 
 var categories = {
     CURRENT : "_CURRENT",
diff --git a/entity/CampaignParticipant_entity/recordcontainers/participantsdbrecordcontainer/recordfieldmappings/standard_email_communication.displayvalue/expression.js b/entity/CampaignParticipant_entity/recordcontainers/participantsdbrecordcontainer/recordfieldmappings/standard_email_communication.displayvalue/expression.js
index 28967142d41b09fd97aa7991b40e836c1248ec95..72c5f0dd3e4d39df1a29d586e9dd06880caa7443 100644
--- a/entity/CampaignParticipant_entity/recordcontainers/participantsdbrecordcontainer/recordfieldmappings/standard_email_communication.displayvalue/expression.js
+++ b/entity/CampaignParticipant_entity/recordcontainers/participantsdbrecordcontainer/recordfieldmappings/standard_email_communication.displayvalue/expression.js
@@ -2,5 +2,5 @@ import("Sql_lib");
 import("system.result");
 import("Communication_lib");
 
-var res = CommUtil.getStandardSubSqlMail(SqlCondition.begin().and("COMMUNICATION.CONTACT_ID = CAMPAIGNPARTICIPANT.CONTACT_ID"));
+var res = CommUtil.getStandardSubSqlMail(newWhere("COMMUNICATION.CONTACT_ID = CAMPAIGNPARTICIPANT.CONTACT_ID"));
 result.string(res);
\ No newline at end of file
diff --git a/entity/CampaignParticipant_entity/recordcontainers/participantsdbrecordcontainer/recordfieldmappings/standard_phone_communication.displayvalue/expression.js b/entity/CampaignParticipant_entity/recordcontainers/participantsdbrecordcontainer/recordfieldmappings/standard_phone_communication.displayvalue/expression.js
index 0af663a72b49fe6bba0cef31244c320786ba6fa7..47f0b2072dccc8896b4cf0a9bce9abdd3467754a 100644
--- a/entity/CampaignParticipant_entity/recordcontainers/participantsdbrecordcontainer/recordfieldmappings/standard_phone_communication.displayvalue/expression.js
+++ b/entity/CampaignParticipant_entity/recordcontainers/participantsdbrecordcontainer/recordfieldmappings/standard_phone_communication.displayvalue/expression.js
@@ -2,5 +2,5 @@ import("system.result");
 import("Communication_lib");
 import("Sql_lib");
 
-var res = CommUtil.getStandardSubSqlPhone(SqlCondition.begin().and("COMMUNICATION.CONTACT_ID = CAMPAIGNPARTICIPANT.CONTACT_ID"));
+var res = CommUtil.getStandardSubSqlPhone(newWhere("COMMUNICATION.CONTACT_ID = CAMPAIGNPARTICIPANT.CONTACT_ID"));
 result.string(res);
\ No newline at end of file
diff --git a/entity/CampaignPlanning_entity/recordcontainers/jditorecordcontainer/contentProcess.js b/entity/CampaignPlanning_entity/recordcontainers/jditorecordcontainer/contentProcess.js
index a568a49afc97feece2ca04fde82bd1787668f8cd..d4672e0ae3c599d5366db35df1817ccdb2960e56 100644
--- a/entity/CampaignPlanning_entity/recordcontainers/jditorecordcontainer/contentProcess.js
+++ b/entity/CampaignPlanning_entity/recordcontainers/jditorecordcontainer/contentProcess.js
@@ -17,15 +17,14 @@ var TARGET_CONTEXT_ELEMENT = "CampaignStep";
 
 var resultRay = [];
 
-var campaignsQuery = "select CAMPAIGNID, CAMPAIGN.\"NAME\""
-                   + "from CAMPAIGN ";
-var stepsQuery = "select CAMPAIGNSTEPID, CAMPAIGNSTEP.\"NAME\", CAMPAIGNSTEP.PREDECESSORSTEP_ID,"
-                        + " CAMPAIGNSTEP.DESCRIPTION, CAMPAIGNSTEP.DATE_START, CAMPAIGNSTEP.DATE_END, CAMPAIGNID"
-                        + " from CAMPAIGN"
-                        + " join CAMPAIGNSTEP on CAMPAIGN.CAMPAIGNID = CAMPAIGNSTEP.CAMPAIGN_ID"
-
-var campaignsRows = db.table(campaignsQuery);
-var stepsRows = db.table(stepCondition.buildSql(stepsQuery, "", "order by SORTING"));
+var campaignsRows = db.table("select CAMPAIGNID, CAMPAIGN.\"NAME\" from CAMPAIGN");
+
+var stepsRows = stepCondition.select("CAMPAIGNSTEPID, CAMPAIGNSTEP.\"NAME\", CAMPAIGNSTEP.PREDECESSORSTEP_ID,"
+                                   + " CAMPAIGNSTEP.DESCRIPTION, CAMPAIGNSTEP.DATE_START, CAMPAIGNSTEP.DATE_END, CAMPAIGNID")
+                             .from("CAMPAIGN")
+                             .join("CAMPAIGNSTEP", "CAMPAIGN.CAMPAIGNID = CAMPAIGNSTEP.CAMPAIGN_ID")
+                             .orderBy("SORTING")
+                             .table();
 
 //First add all Campaign Rows to the resultRay. These are the Root Rows in the Treetable
 for (var campaignRowIndex in campaignsRows) 
diff --git a/entity/CampaignStep_entity/entityfields/newbulkmail/onActionProcess.js b/entity/CampaignStep_entity/entityfields/newbulkmail/onActionProcess.js
index f1ed0b790f38d89d6b30d2eb7de8c8efa3d42a02..090b957b3fb2f37a3f71424c1824faf0a1bda8d8 100644
--- a/entity/CampaignStep_entity/entityfields/newbulkmail/onActionProcess.js
+++ b/entity/CampaignStep_entity/entityfields/newbulkmail/onActionProcess.js
@@ -2,9 +2,10 @@ import("Sql_lib");
 import("system.db");
 import("Bulkmail_lib");
 
-var recipients = db.array(db.COLUMN, SqlCondition.begin()
-    .andPrepareVars("CAMPAIGNPARTICIPANT.CAMPAIGNSTEP_ID", "$field.CAMPAIGNSTEPID")
-    .andPrepareVars("CAMPAIGNPARTICIPANT.CAMPAIGN_ID", "$field.CAMPAIGN_ID")
-    .buildSql("select CONTACT_ID from CAMPAIGNPARTICIPANT"));
+var recipients = newSelect("CONTACT_ID")
+                        .from("CAMPAIGNPARTICIPANT")
+                        .where("CAMPAIGNPARTICIPANT.CAMPAIGNSTEP_ID", "$field.CAMPAIGNSTEPID")
+                        .and("CAMPAIGNPARTICIPANT.CAMPAIGN_ID", "$field.CAMPAIGN_ID")
+                        .arrayColumn()
 
 BulkMailUtils.newBulkMail(recipients);
\ No newline at end of file
diff --git a/entity/CampaignStep_entity/recordcontainers/db/conditionProcess.js b/entity/CampaignStep_entity/recordcontainers/db/conditionProcess.js
index 957728e87b5c717165dc1ea24fdd80892678115a..54338b1d460fcca4eedbc3ad138847e429ba631d 100644
--- a/entity/CampaignStep_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/CampaignStep_entity/recordcontainers/db/conditionProcess.js
@@ -3,10 +3,8 @@ import("Sql_lib");
 import("system.vars");
 import("system.result");
 
-var cond = SqlCondition.begin()
-                       .andPrepareVars("CAMPAIGNSTEP.CAMPAIGN_ID", "$param.campaignId_param");
+var cond = newWhereIfSet("CAMPAIGNSTEP.CAMPAIGN_ID", "$param.campaignId_param")
+                .andIfSet("CAMPAIGNSTEP.SORTING","$param.maxSort_param", "# <= ?");
 
-cond.andPrepareIfSet("CAMPAIGNSTEP.SORTING", vars.getString("$param.maxSort_param"), "# <= ?");
-
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1=1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/Campaign_entity/recordcontainers/db/onDBDelete.js b/entity/Campaign_entity/recordcontainers/db/onDBDelete.js
index 1297d0cd21787d017c6790542c0f0e4f97f80a49..8c3db7d4887c574724a66fa0753364218a868324 100644
--- a/entity/Campaign_entity/recordcontainers/db/onDBDelete.js
+++ b/entity/Campaign_entity/recordcontainers/db/onDBDelete.js
@@ -15,7 +15,7 @@ if (currentId)
     
     toDelete = toDelete.map(function(pTable)
     {
-        return [pTable, SqlCondition.equals(pTable + ".CAMPAIGN_ID", currentId, "1=2")]
+        return [pTable, newWhere(pTable + ".CAMPAIGN_ID", currentId).build()]
     });
     
     db.deletes(toDelete);
diff --git a/entity/ClassificationAdmin_entity/grantDeleteProcess.js b/entity/ClassificationAdmin_entity/grantDeleteProcess.js
index 6a0202d0b06e410bc42a2aa04aef955c32e8c6e5..7c5a620b8e1200d1d117da7462ebd34fc9c6ee04 100644
--- a/entity/ClassificationAdmin_entity/grantDeleteProcess.js
+++ b/entity/ClassificationAdmin_entity/grantDeleteProcess.js
@@ -3,6 +3,12 @@ import("system.db");
 import("system.vars");
 import("Sql_lib");
 
-result.object(parseInt(db.cell(SqlCondition.begin()
-                        .andPrepare("CLASSIFICATION.CLASSIFICATIONTYPE_ID", vars.get("$field.CLASSIFICATIONTYPEID"))
-                        .buildSql("select count(*) from CLASSIFICATION", "1=2"))) <= 0);
\ No newline at end of file
+var count = newSelect("count(*)")
+                .from("CLASSIFICATION")
+                .whereIfSet("CLASSIFICATION.CLASSIFICATIONTYPE_ID", "$field.CLASSIFICATIONTYPEID")
+                .cell(true);
+                
+if (!count)
+    count = 0;
+
+result.object(parseInt(count) <= 0);
\ No newline at end of file
diff --git a/entity/ClassificationAdmin_entity/recordcontainers/jdito/contentProcess.js b/entity/ClassificationAdmin_entity/recordcontainers/jdito/contentProcess.js
deleted file mode 100644
index f167296c2f4e6427feff8e970d10fc84f3bcd302..0000000000000000000000000000000000000000
--- a/entity/ClassificationAdmin_entity/recordcontainers/jdito/contentProcess.js
+++ /dev/null
@@ -1,44 +0,0 @@
-import("JditoFilter_lib");
-import("Classification_lib");
-import("system.vars");
-import("Sql_lib");
-import("system.db");
-import("system.result");
-
-var classificationId;
-var classificationTypeId;
-
-if (vars.exists("$local.idvalues") && vars.get("$local.idvalues") && vars.get("$local.idvalues").length > 0)
-{
-    var selected = vars.get("$local.idvalues")[0];
-    
-    classificationTypeId = selected;
-}
-
-var cond = SqlCondition.begin()
-                .andPrepareVars("CLASSIFICATIONTYPE.CLASSIFICATIONTYPE", "$param.ClassificationType_param")
-                .andPrepareIfSet("CLASSIFICATION.CLASSIFICATIONID", classificationId)
-
-
-
-if (!classificationId)
-{
-    cond.andPrepareIfSet("CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID", classificationTypeId);
-}
-
-if (vars.exists("$local.filter") && vars.get("$local.filter"))
-{
-    var filter = vars.get("$local.filter");
-    if (filter.filter)
-        cond.andSqlCondition((JditoFilterUtils.getSqlCondition(filter.filter, "CLASSIFICATION", undefined, {
-             CLASSIFICATIONTYPE : "CLASSIFICATIONTYPE.CLASSIFICATIONTYPE"
-        })));
-}
-
-var masking = new SqlMaskingUtils();
-result.object(db.table(cond.buildSql("select CLASSIFICATIONTYPEID, CLASSIFICATIONID, CLASSIFICATIONGROUP, CLASSIFICATIONSCORE_ID, CLASSIFICATIONTYPEID, CLASSIFICATIONTYPE_ID, OBJECT_TYPE, OBJECT_ROWID, SCORETYPE, CLASSIFICATIONTYPE.CLASSIFICATIONTYPE from CLASSIFICATION \n\
-                right join CLASSIFICATIONTYPE on " + SqlCondition.begin()
-                    .and("CLASSIFICATIONTYPE_ID = CLASSIFICATIONTYPEID")
-                    .andPrepareVars("CLASSIFICATION.OBJECT_TYPE", "$param.ObjectType_param")
-                    .andPrepareVars("CLASSIFICATION.OBJECT_ROWID", "$param.ObjectRowid_param").translate(), "1=1", "order by CLASSIFICATIONGROUP asc"))
-                );
\ No newline at end of file
diff --git a/entity/ClassificationAdmin_entity/recordcontainers/jdito/onDelete.js b/entity/ClassificationAdmin_entity/recordcontainers/jdito/onDelete.js
deleted file mode 100644
index 2e4243249985e4135deedaf41b24428fb3aeab81..0000000000000000000000000000000000000000
--- a/entity/ClassificationAdmin_entity/recordcontainers/jdito/onDelete.js
+++ /dev/null
@@ -1,26 +0,0 @@
-import("system.neon");
-import("system.question");
-import("Sql_lib");
-import("system.db");
-import("system.util");
-import("system.vars");
-
-var classificationTypeId = vars.get("$field.CLASSIFICATIONTYPEID");
-
-if (1 < db.cell(SqlCondition.begin()
-                        .andPrepare("CLASSIFICATIONTYPE.CLASSIFICATIONTYPE", vars.get("$field.CLASSIFICATIONTYPE"))
-                        .buildSql("select count(*) from CLASSIFICATIONTYPE", "1=2")))
-{
-    db.deleteData("CLASSIFICATION", "CLASSIFICATION.CLASSIFICATIONTYPE_ID in (" + SqlUtils.translateStatementWithQuotes(
-                       SqlCondition.begin()
-                                   .andPrepare("CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID", classificationTypeId)
-                                   .buildSql("select CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID from CLASSIFICATIONTYPE", "1=2")) + ")");
-    db.deleteData("CLASSIFICATIONTYPE", SqlCondition.equals("CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID", classificationTypeId, "1=2"));
-    db.deleteData("CLASSIFICATIONSCORE", SqlCondition.equals("CLASSIFICATIONSCORE.CLASSIFICATIONTYPE_ID", classificationTypeId, "1=2"));
-}
-neon.refreshAll();
-//else
-//{
-    // do not delete anything, because it is the last one. If this one is deleted, there would be no way to add anything again.
-    // TODO: delete-button disable if count(*) <= 1
-//}
diff --git a/entity/ClassificationAdmin_entity/recordcontainers/jdito/onInsert.js b/entity/ClassificationAdmin_entity/recordcontainers/jdito/onInsert.js
deleted file mode 100644
index 7245a3d2d8f9830c28f851d410c42566a721ad0f..0000000000000000000000000000000000000000
--- a/entity/ClassificationAdmin_entity/recordcontainers/jdito/onInsert.js
+++ /dev/null
@@ -1,10 +0,0 @@
-import("system.db");
-import("system.util");
-import("system.vars");
-
-db.insertData("CLASSIFICATIONTYPE", ["CLASSIFICATIONTYPEID", "CLASSIFICATIONTYPE", "SCORETYPE", "CLASSIFICATIONGROUP"], null, [
-    vars.get("$field.UID"),
-    vars.get("$field.CLASSIFICATIONTYPE"),
-    vars.get("$field.SCORETYPE"),
-    vars.get("$field.CLASSIFICATIONGROUP"),
-]);
\ No newline at end of file
diff --git a/entity/ClassificationAdmin_entity/recordcontainers/jdito/onUpdate.js b/entity/ClassificationAdmin_entity/recordcontainers/jdito/onUpdate.js
deleted file mode 100644
index 5670bb7047472418457c8b8bee5aee74dd215a4c..0000000000000000000000000000000000000000
--- a/entity/ClassificationAdmin_entity/recordcontainers/jdito/onUpdate.js
+++ /dev/null
@@ -1,54 +0,0 @@
-import("Classification_lib");
-import("system.neon");
-import("system.util");
-import("Sql_lib");
-import("system.db");
-import("system.vars");
-
-var changed = vars.get("$local.changed");
-
-// check if it already exists. Else it only exists as ScoreType but has no Classification-Entry
-if (vars.get("$field.CLASSIFICATIONID"))
-{
-    if (vars.get("$field.CLASSIFICATIONSCORE_ID"))
-    {
-         db.updateData("CLASSIFICATION", ["CLASSIFICATIONSCORE_ID"], null, [
-            vars.get("$field.CLASSIFICATIONSCORE_ID")
-        ], SqlCondition.equals("CLASSIFICATION.CLASSIFICATIONID", vars.get("$field.CLASSIFICATIONID"), "1=2"));
-    }
-    else
-    {
-        db.deleteData("CLASSIFICATION", SqlCondition.equals("CLASSIFICATION.CLASSIFICATIONID", vars.get("$field.CLASSIFICATIONID")));
-    }
-}
-else if (vars.get("$field.CLASSIFICATIONSCORE_ID"))
-{
-    var newId = util.getNewUUID();
-    db.insertData("CLASSIFICATION", ["CLASSIFICATIONID", "OBJECT_TYPE", "OBJECT_ROWID", "CLASSIFICATIONTYPE_ID", "CLASSIFICATIONSCORE_ID"], null, [
-        newId,
-        vars.get("$field.OBJECT_TYPE"),
-        vars.get("$field.OBJECT_ROWID"),
-        vars.get("$field.CLASSIFICATIONTYPE_ID"),
-        vars.get("$field.CLASSIFICATIONSCORE_ID"),
-    ]);
-    
-    neon.setFieldValue("$field.CLASSIFICATIONID", newId);
-}
-
-// update classificationgroup-name and scoretype-name if they were changed
-changed.forEach(function(change) 
-{
-    switch (change)
-    {
-        case "CLASSIFICATIONGROUP.value":
-            var oldGroupName = ClassificationUtils.getGroupFromDb(vars.get("$field.CLASSIFICATIONTYPEID"));
-            var newGroupName = vars.get("$field.CLASSIFICATIONGROUP");
-
-            ClassificationUtils.changeGroupName(oldGroupName, newGroupName, vars.get("$field.CLASSIFICATIONTYPE"))
-        case "SCORETYPE.value":
-            var classificationTypeId = vars.get("$field.CLASSIFICATIONTYPEID");
-            var newScoreName = vars.get("$field.SCORETYPE");
-
-            ClassificationUtils.changeScoreName(newScoreName, classificationTypeId);
-    }
-})
\ No newline at end of file
diff --git a/entity/ClassificationScore_entity/entityfields/classificationtype_id/displayValueProcess.js b/entity/ClassificationScore_entity/entityfields/classificationtype_id/displayValueProcess.js
index 72ba8be2912ae736749e9ad1a5795efaf8db5e4e..a7f0c5eb4b488c7aaf55e93097d6f05fb37bbd13 100644
--- a/entity/ClassificationScore_entity/entityfields/classificationtype_id/displayValueProcess.js
+++ b/entity/ClassificationScore_entity/entityfields/classificationtype_id/displayValueProcess.js
@@ -2,6 +2,7 @@ import("Sql_lib");
 import("system.db");
 import("system.result");
 
-result.string(db.cell(SqlCondition.begin()
-                                  .andPrepareVars("CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID", "$field.CLASSIFICATIONTYPE_ID")
-                                  .buildSql("select CLASSIFICATIONTYPE.SCORETYPE from CLASSIFICATIONTYPE", "1=2")));
\ No newline at end of file
+result.string(newSelect("CLASSIFICATIONTYPE.SCORETYPE")
+                    .from("CLASSIFICATIONTYPE")
+                    .whereIfSet("CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID", "$field.CLASSIFICATIONTYPE_ID")
+                    .cell(true));
\ No newline at end of file
diff --git a/entity/ClassificationScore_entity/entityfields/maxvalue/valueProcess.js b/entity/ClassificationScore_entity/entityfields/maxvalue/valueProcess.js
index ef3d945788553bdda1d86b71f407986ee53a4463..f5a5e4d108df47cc194937a7391e500a8088bb08 100644
--- a/entity/ClassificationScore_entity/entityfields/maxvalue/valueProcess.js
+++ b/entity/ClassificationScore_entity/entityfields/maxvalue/valueProcess.js
@@ -4,16 +4,17 @@ import("system.db");
 import("Sql_lib");
 
 if (!vars.get("$this.value"))
-{
+{    
     var classificationTypeId = vars.get("$param.ClassificationTypeId_param");
-    var maxValue = db.cell(
-            SqlCondition.begin()
-                        .andPrepare("CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID", classificationTypeId, "# <> ?")
-                        .andPrepare("CLASSIFICATIONTYPE.CLASSIFICATIONGROUP", vars.get("$param.ClassificationGroup_param"))
-                        .andPrepare("CLASSIFICATIONTYPE.CLASSIFICATIONTYPE", vars.get("$param.ClassificationType_param"))
-                        .buildSql("select 100.0 - sum(maxScore) from ( \n\
-                                    select max(SCORE) maxScore from CLASSIFICATIONTYPE \n\
-                                    join CLASSIFICATIONSCORE on CLASSIFICATIONSCORE.CLASSIFICATIONTYPE_ID = CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID", "1=2", "group by CLASSIFICATIONTYPE.SCORETYPE) maxScores"));
+    var maxValue = newSelect("100.0 - sum(maxScore)")
+                        .from(newSelect("max(SCORE) maxScore")
+                                .from("CLASSIFICATIONTYPE")
+                                .join("CLASSIFICATIONSCORE", "CLASSIFICATIONSCORE.CLASSIFICATIONTYPE_ID = CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID")
+                                .whereIfSet("CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID", classificationTypeId, "# <> ?")
+                                .andIfSet("CLASSIFICATIONTYPE.CLASSIFICATIONGROUP", "$param.ClassificationGroup_param")
+                                .andIfSet("CLASSIFICATIONTYPE.CLASSIFICATIONTYPE", "$param.ClassificationType_param")
+                                .groupBy("CLASSIFICATIONTYPE.SCORETYPE"), "maxScores")
+                        .cell();
     if (maxValue == "")
         maxValue = 100;
     
diff --git a/entity/ClassificationScore_entity/recordcontainers/db/conditionProcess.js b/entity/ClassificationScore_entity/recordcontainers/db/conditionProcess.js
index d56a9f5bfc8c9d85a8b4ae236c83531ab921c30f..10dbbac6efbdb80f576dab966afa19ede6ffb645 100644
--- a/entity/ClassificationScore_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/ClassificationScore_entity/recordcontainers/db/conditionProcess.js
@@ -3,7 +3,5 @@ import("Sql_lib");
 import("system.db");
 import("system.result");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(SqlCondition.begin()
-                  .andPrepareVars("CLASSIFICATIONSCORE.CLASSIFICATIONTYPE_ID", "$param.ClassificationTypeId_param")
-                  .translate("1=2"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(newWhereIfSet("CLASSIFICATIONSCORE.CLASSIFICATIONTYPE_ID", "$param.ClassificationTypeId_param").toString());
\ No newline at end of file
diff --git a/entity/ClassificationScore_entity/recordcontainers/db/onDBDelete.js b/entity/ClassificationScore_entity/recordcontainers/db/onDBDelete.js
index 41b093f08de18bd28403c0122382ef68ebdbb13a..c93d5154adcc69f7f390659c88c94eb0eca6929e 100644
--- a/entity/ClassificationScore_entity/recordcontainers/db/onDBDelete.js
+++ b/entity/ClassificationScore_entity/recordcontainers/db/onDBDelete.js
@@ -2,6 +2,5 @@ import("system.vars");
 import("system.db");
 import("Sql_lib");
 
-db.deleteData("CLASSIFICATION", SqlCondition.begin()
-                                   .andPrepare("CLASSIFICATION.CLASSIFICATIONSCORE_ID", vars.get("$field.CLASSIFICATIONSCOREID"))
-                                   .build("1=2"));
\ No newline at end of file
+newWhere("CLASSIFICATION.CLASSIFICATIONSCORE_ID", "$field.CLASSIFICATIONSCOREID")
+    .deleteData(true, "CLASSIFICATION");
\ No newline at end of file
diff --git a/entity/Classification_entity/entityfields/classificationscore_id/displayValueProcess.js b/entity/Classification_entity/entityfields/classificationscore_id/displayValueProcess.js
index 1b0f11a548cc9dc03e46f49851ba078681916eef..0b086fdea352f7d072715c805172bf2e4f680d0c 100644
--- a/entity/Classification_entity/entityfields/classificationscore_id/displayValueProcess.js
+++ b/entity/Classification_entity/entityfields/classificationscore_id/displayValueProcess.js
@@ -8,9 +8,10 @@ import("system.result");
 if (vars.get("$field.CLASSIFICATIONSCORE_ID"))
 {
     // TODO: loadEntity / #Title
-    result.string(translate.text(db.cell(SqlCondition.begin()
-            .andPrepareVars("CLASSIFICATIONSCORE.CLASSIFICATIONSCOREID", "$field.CLASSIFICATIONSCORE_ID")
-            .buildSql("select TITLE from CLASSIFICATIONSCORE", "1=2"))));
+    result.string(translate.text(newSelect("TITLE")
+                                    .from("CLASSIFICATIONSCORE")
+                                    .where("CLASSIFICATIONSCORE.CLASSIFICATIONSCOREID", "$field.CLASSIFICATIONSCORE_ID")
+                                    .cell()));
 } 
 else
 {
diff --git a/entity/Classification_entity/entityfields/info/valueProcess.js b/entity/Classification_entity/entityfields/info/valueProcess.js
index 1ee256fc478b0ac12abb12b41925ac7a1b527205..681613e42afa0630e5667b9b70c85e966c901026 100644
--- a/entity/Classification_entity/entityfields/info/valueProcess.js
+++ b/entity/Classification_entity/entityfields/info/valueProcess.js
@@ -5,9 +5,11 @@ import("system.result");
 import("system.text");
 import("Sql_lib");
 
-var data = db.table(SqlCondition.begin()
-                     .andPrepare("CLASSIFICATIONSCORE.CLASSIFICATIONTYPE_ID", vars.get("$field.CLASSIFICATIONTYPEID"))
-                     .buildSql("select TITLE, SCORE from CLASSIFICATIONSCORE", "1=2", "order by SORT"))
+var data = newSelect("TITLE, SCORE")   
+                .from("CLASSIFICATIONSCORE")
+                .orderBy("SORT")
+                .whereIfSet("CLASSIFICATIONSCORE.CLASSIFICATIONTYPE_ID", "$field.CLASSIFICATIONTYPEID")
+                .table(true);
 
 var resultText = "";
 
diff --git a/entity/Classification_entity/recordcontainers/jdito/contentProcess.js b/entity/Classification_entity/recordcontainers/jdito/contentProcess.js
index ec5ab1675e3112be2f54f359c75704c276bdfd9b..0060716a7dfc788ca41cec5b2dd705d7be19b79c 100644
--- a/entity/Classification_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/Classification_entity/recordcontainers/jdito/contentProcess.js
@@ -7,8 +7,8 @@ import("system.result");
 
 var scores = JSON.stringify(ClassificationUtils.getScore(vars.get("$param.ClassificationType_param"), vars.get("$param.ObjectType_param"), vars.get("$param.ObjectRowid_param")));
 
-var classificationId;
-var classificationTypeId;
+var classificationId = null;
+var classificationTypeId = null;
 
 // if the id starts with "C," it is a classificationId. If it starts with "T,", it is a classificationtypeId
 if (vars.exists("$local.idvalues") && vars.get("$local.idvalues") && vars.get("$local.idvalues").length > 0)
@@ -23,38 +23,40 @@ if (vars.exists("$local.idvalues") && vars.get("$local.idvalues") && vars.get("$
     }
 }
 
-var cond = SqlCondition.begin()
-                .andPrepareVars("CLASSIFICATIONTYPE.CLASSIFICATIONTYPE", "$param.ClassificationType_param")
-                .andPrepareIfSet("CLASSIFICATION.CLASSIFICATIONID", classificationId)
+var masking = new SqlMaskingUtils();
 
+var select = newSelect("case when CLASSIFICATIONID is not null then " + masking.concat(["'C,'", "CLASSIFICATIONID"], "", false) + " else " + masking.concat(["'T,'", "CLASSIFICATIONTYPEID"], "", false) + " end, CLASSIFICATIONID, CLASSIFICATIONGROUP, CLASSIFICATIONSCORE_ID, CLASSIFICATIONTYPEID, CLASSIFICATIONTYPE_ID, OBJECT_TYPE, OBJECT_ROWID, SCORETYPE, CLASSIFICATIONTYPE.CLASSIFICATIONTYPE")
+                .from("CLASSIFICATION")
+                .rightJoin("CLASSIFICATIONTYPE", newWhere()
+                    .and("CLASSIFICATIONTYPE_ID = CLASSIFICATIONTYPEID")
+                    .andIfSet("CLASSIFICATION.OBJECT_TYPE", "$param.ObjectType_param")
+                    .andIfSet("CLASSIFICATION.OBJECT_ROWID", "$param.ObjectRowid_param"))
+                .orderBy("CLASSIFICATIONGROUP asc")
+                .whereIfSet("CLASSIFICATIONTYPE.CLASSIFICATIONTYPE", "$param.ClassificationType_param")
+                .andIfSet("CLASSIFICATION.CLASSIFICATIONID", classificationId)
 
 
 if (!classificationId)
 {
-    cond.andPrepareIfSet("CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID", classificationTypeId)
-        .andSqlCondition(SqlCondition.begin().orPrepareVars("CLASSIFICATION.OBJECT_TYPE", "$param.ObjectType_param")
-                                                     .or("CLASSIFICATION.OBJECT_TYPE is null"))
-        .andSqlCondition(SqlCondition.begin().orPrepareVars("CLASSIFICATION.OBJECT_ROWID", "$param.ObjectRowid_param")
-                                                     .or("CLASSIFICATION.OBJECT_ROWID is null"));
+    select.andIfSet("CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID", classificationTypeId)
+        .and(newWhereIfSet("CLASSIFICATION.OBJECT_TYPE", "$param.ObjectType_param")
+                    .or("CLASSIFICATION.OBJECT_TYPE is null"))
+        .and(newWhereIfSet("CLASSIFICATION.OBJECT_ROWID", "$param.ObjectRowid_param")
+                    .or("CLASSIFICATION.OBJECT_ROWID is null"));
 }
 
 if (vars.exists("$local.filter") && vars.get("$local.filter"))
 {
     var filter = vars.get("$local.filter");
     if (filter.filter)
-        cond.andSqlCondition((JditoFilterUtils.getSqlCondition(filter.filter, "CLASSIFICATION", undefined, {
+        select.andIfSet((JditoFilterUtils.getSqlCondition(filter.filter, "CLASSIFICATION", undefined, {
              CLASSIFICATIONTYPE : "CLASSIFICATIONTYPE.CLASSIFICATIONTYPE"
         })));
 }
 
-var masking = new SqlMaskingUtils();
-result.object(db.table(cond.buildSql("select case when CLASSIFICATIONID is not null then " + masking.concat(["'C,'", "CLASSIFICATIONID"], "", false) + " else " + masking.concat(["'T,'", "CLASSIFICATIONTYPEID"], "", false) + " end, CLASSIFICATIONID, CLASSIFICATIONGROUP, CLASSIFICATIONSCORE_ID, CLASSIFICATIONTYPEID, CLASSIFICATIONTYPE_ID, OBJECT_TYPE, OBJECT_ROWID, SCORETYPE, CLASSIFICATIONTYPE.CLASSIFICATIONTYPE from CLASSIFICATION \n\
-                right join CLASSIFICATIONTYPE on " + SqlCondition.begin()
-                    .and("CLASSIFICATIONTYPE_ID = CLASSIFICATIONTYPEID")
-                    .andPrepareVars("CLASSIFICATION.OBJECT_TYPE", "$param.ObjectType_param")
-                    .andPrepareVars("CLASSIFICATION.OBJECT_ROWID", "$param.ObjectRowid_param").translate(), "1=2", "order by CLASSIFICATIONGROUP asc"))
-                .map(function(pRow)
-                {
-                    pRow.push(scores);
-                    return pRow;
-                }));
\ No newline at end of file
+result.object(select.table()
+                    .map(function(pRow)
+                    {
+                        pRow.push(scores);
+                        return pRow;
+                    }));
\ No newline at end of file
diff --git a/entity/Classification_entity/recordcontainers/jdito/onUpdate.js b/entity/Classification_entity/recordcontainers/jdito/onUpdate.js
index 97a12f0cbc5dae32c32cb6f903e7755c3cbd878d..c8bf239281bee7a8f36461ffb7afc60ff2b1754f 100644
--- a/entity/Classification_entity/recordcontainers/jdito/onUpdate.js
+++ b/entity/Classification_entity/recordcontainers/jdito/onUpdate.js
@@ -12,13 +12,13 @@ if (vars.get("$field.CLASSIFICATIONID"))
 {
     if (vars.get("$field.CLASSIFICATIONSCORE_ID"))
     {
-         db.updateData("CLASSIFICATION", ["CLASSIFICATIONSCORE_ID"], null, [
-            vars.get("$field.CLASSIFICATIONSCORE_ID")
-        ], SqlCondition.equals("CLASSIFICATION.CLASSIFICATIONID", vars.get("$field.CLASSIFICATIONID"), "1=2"));
+        newWhere("CLASSIFICATION.CLASSIFICATIONID", vars.get("$field.CLASSIFICATIONID"))
+            .updateData(true, ["CLASSIFICATIONSCORE_ID"], null, [vars.get("$field.CLASSIFICATIONSCORE_ID")], "CLASSIFICATION");
     }
     else
     {
-        db.deleteData("CLASSIFICATION", SqlCondition.equals("CLASSIFICATION.CLASSIFICATIONID", vars.get("$field.CLASSIFICATIONID")));
+        newWhere("CLASSIFICATION.CLASSIFICATIONID", vars.get("$field.CLASSIFICATIONID"))
+            .deleteData(true, "CLASSIFICATION");
     }
 }
 else if (vars.get("$field.CLASSIFICATIONSCORE_ID"))
diff --git a/entity/CommRestriction_Entity/recordcontainers/db/conditionProcess.js b/entity/CommRestriction_Entity/recordcontainers/db/conditionProcess.js
index d760344b91a0c779413d74c31aa2b4cf74c8f355..4a714c57054e0ee4bd91998185d6157db848cb7f 100644
--- a/entity/CommRestriction_Entity/recordcontainers/db/conditionProcess.js
+++ b/entity/CommRestriction_Entity/recordcontainers/db/conditionProcess.js
@@ -2,8 +2,7 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = new SqlCondition();
-cond.andPrepareVars("COMMRESTRICTION.CONTACT_ID", "$param.ContactId_param");
+var cond = newWhereIfSet("COMMRESTRICTION.CONTACT_ID", "$param.ContactId_param");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/Communication_entity/entityfields/contactsmaincountry_param/valueProcess.js b/entity/Communication_entity/entityfields/contactsmaincountry_param/valueProcess.js
index 549bf5d33254e504c379831578ba2ecacd09bbeb..ff6c3007f10a85d69c5979f123bb40e935d40d31 100644
--- a/entity/Communication_entity/entityfields/contactsmaincountry_param/valueProcess.js
+++ b/entity/Communication_entity/entityfields/contactsmaincountry_param/valueProcess.js
@@ -2,11 +2,12 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = new SqlCondition();
+//TODO: this should happen by 1:1 links instead of manually requesting the data by a select (getRows ??)
+var country = newSelect("ADDRESS.COUNTRY")
+                .from("ADDRESS")
+                .join("CONTACT", "CONTACT.ADDRESS_ID = ADDRESS.ADDRESSID")
+                .whereIfSet("CONTACT.CONTACTID", "$param.ContactId_param")
+                .cell();
 
-cond.andPrepareVars("CONTACT.CONTACTID", "$param.ContactId_param");
-//TODO: this should happen by 1:1 links instead of manually requesting the data by a select
-var country = db.cell(cond.buildSql("select ADDRESS.COUNTRY from ADDRESS "
-            + "join CONTACT on CONTACT.ADDRESS_ID = ADDRESS.ADDRESSID ", "1 = 1"));
 if (country != "") 
     result.string(country);
\ No newline at end of file
diff --git a/entity/Communication_entity/recordcontainers/db/conditionProcess.js b/entity/Communication_entity/recordcontainers/db/conditionProcess.js
index 559ccb068f163ac4d4385046693c2e65c4cf82b9..39f447f1fe79e21b1235025d2c5859cee0a33c23 100644
--- a/entity/Communication_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Communication_entity/recordcontainers/db/conditionProcess.js
@@ -4,15 +4,14 @@ import("system.result");
 import("Sql_lib");
 import("Keyword_lib");
 
-var cond = new SqlCondition();
-cond.andPrepareVars("COMMUNICATION.CONTACT_ID", "$param.ContactId_param");
-cond.andPrepareVars("COMMUNICATION.ADDR", "$param.Address_param");
+var cond = newWhere()
+            .andIfSet("COMMUNICATION.CONTACT_ID", "$param.ContactId_param")
+            .andIfSet("COMMUNICATION.ADDR", "$param.Address_param")
 
-if (vars.exists("$param.CommMediumIds_param"))
+if (vars.getString("$param.CommMediumIds_param"))
 {
     var mediumIds = JSON.parse(vars.getString("$param.CommMediumIds_param"));
-    if(mediumIds.length > 0) 
-        cond.andIn("COMMUNICATION.MEDIUM_ID", mediumIds);
+    cond.andIfSet("COMMUNICATION.MEDIUM_ID", mediumIds, SqlBuilder.IN());
 }
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 2"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/Competition_entity/entityfields/organisations/children/excludedcontactids_param/valueProcess.js b/entity/Competition_entity/entityfields/organisations/children/excludedcontactids_param/valueProcess.js
index 440d1dc3e611f86acd3a0720a9937ffec4d18675..f828527c316b7e048674f7578851ad312dd5a58f 100644
--- a/entity/Competition_entity/entityfields/organisations/children/excludedcontactids_param/valueProcess.js
+++ b/entity/Competition_entity/entityfields/organisations/children/excludedcontactids_param/valueProcess.js
@@ -3,7 +3,8 @@ import("system.vars");
 import("system.db");
 import("Sql_lib");
 
-result.object(db.array(db.COLUMN, SqlCondition.begin()
-                                .andPrepare("COMPETITION.OBJECT_TYPE", vars.get("$field.OBJECT_TYPE"))
-                                .andPrepare("COMPETITION.OBJECT_ROWID", vars.get("$field.OBJECT_ROWID"))
-                                .buildSql("select CONTACT_ID from COMPETITION", "1=2")));
\ No newline at end of file
+result.object(newSelect("CONTACT_ID")
+                .from("COMPETITION")
+                .where("COMPETITION.OBJECT_TYPE", "$field.OBJECT_TYPE")
+                .and("COMPETITION.OBJECT_ROWID", "$field.OBJECT_ROWID")
+                .arrayColumn(true));
\ No newline at end of file
diff --git a/entity/Competition_entity/recordcontainers/db/conditionProcess.js b/entity/Competition_entity/recordcontainers/db/conditionProcess.js
index 52236b9cc27c8779af71788cfc43fd674638bc2c..7fdde447ee0c40d4ad260e0392be5c9efe6e345b 100644
--- a/entity/Competition_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Competition_entity/recordcontainers/db/conditionProcess.js
@@ -2,9 +2,9 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = new SqlCondition();
-cond.andPrepareVars("COMPETITION.OBJECT_ROWID", "$param.ObjectRowId_param"),
-cond.andPrepareVars("COMPETITION.OBJECT_TYPE", "$param.ObjectType_param");
+var cond = newWhere()
+            .andIfSet("COMPETITION.OBJECT_ROWID", "$param.ObjectRowId_param")
+            .andIfSet("COMPETITION.OBJECT_TYPE", "$param.ObjectType_param");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
diff --git a/entity/Contact_entity/entityfields/personscontactsexceptown/children/personid_param/valueProcess.js b/entity/Contact_entity/entityfields/personscontactsexceptown/children/personid_param/valueProcess.js
index b9088fd5cb96bb08a214dcc3e4b380d35795824f..1b454992c6171b39ff7c45efa2816600843af739 100644
--- a/entity/Contact_entity/entityfields/personscontactsexceptown/children/personid_param/valueProcess.js
+++ b/entity/Contact_entity/entityfields/personscontactsexceptown/children/personid_param/valueProcess.js
@@ -1,14 +1,14 @@
 import("system.result");
 import("system.vars");
-import("system.db");
 import("Sql_lib");
 
 var contactId = vars.get("$param.OwnContactId_param");
 if (contactId)
 {
-    var sql = SqlCondition.begin()
-                          .andPrepare("CONTACT.CONTACTID", contactId)
-                          .buildSql("select CONTACT.PERSON_ID from CONTACT");
-    var personId = db.cell(sql);
+    var personId = newSelect("CONTACT.PERSON_ID")
+                        .from("CONTACT")
+                        .where("CONTACT.CONTACTID", contactId)
+                        .cell();
+
     result.string(personId);
 }
\ No newline at end of file
diff --git a/entity/Contact_entity/recordcontainers/db/conditionProcess.js b/entity/Contact_entity/recordcontainers/db/conditionProcess.js
index 26fac7ff087ae3f410cdb0bff013750721ad7cc8..be0043d3ea4079d797cfdc5df4e81f5219edeff7 100644
--- a/entity/Contact_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Contact_entity/recordcontainers/db/conditionProcess.js
@@ -3,9 +3,9 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = new SqlCondition();
-cond.andPrepareVars("CONTACT.CONTACTID", "$param.OwnContactId_param", "# != ?");
-cond.andPrepareVars("CONTACT.PERSON_ID", "$param.PersonId_param");
+var cond = newWhere()
+            .andIfSet("CONTACT.CONTACTID", "$param.OwnContactId_param", "# != ?")
+            .andIfSet("CONTACT.PERSON_ID", "$param.PersonId_param");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 2"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/Contract_entity/recordcontainers/db/conditionProcess.js b/entity/Contract_entity/recordcontainers/db/conditionProcess.js
index 4557e1b43f7d3aed3b96c6834ba9868a8136282e..0fc49f960a068a0e10aa355fe661c104cb8db537 100644
--- a/entity/Contract_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Contract_entity/recordcontainers/db/conditionProcess.js
@@ -3,7 +3,7 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = SqlCondition.begin().andPrepareVars("CONTRACT.CONTACT_ID", "$param.ContactId_param");
+var cond = newWhereIfSet("CONTRACT.CONTACT_ID", "$param.ContactId_param");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1")); 
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString()); 
diff --git a/entity/DSGVOInfo_entity/recordcontainers/db/conditionProcess.js b/entity/DSGVOInfo_entity/recordcontainers/db/conditionProcess.js
index 6f0d35228e884a8086cfd94186cf1e6b0337aeee..0135f590498ce6e715386047a43ac6219af36a35 100644
--- a/entity/DSGVOInfo_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/DSGVOInfo_entity/recordcontainers/db/conditionProcess.js
@@ -2,7 +2,6 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-result.string(SqlCondition.begin()
-               .andPrepareVars("DSGVOINFO.CONTACT_ID", "$param.ContactId_param")
-               .translate("1=1"))
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(newWhere("DSGVOINFO.CONTACT_ID", "$param.ContactId_param").toString())
                
\ No newline at end of file
diff --git a/entity/DSGVO_entity/recordcontainers/jdito/contentProcess.js b/entity/DSGVO_entity/recordcontainers/jdito/contentProcess.js
index 587bba0a5e86c812eb9529457c73c1bcf08ce32f..be1eae350e9c4115306985baf9d0d7ac6429c534 100644
--- a/entity/DSGVO_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/DSGVO_entity/recordcontainers/jdito/contentProcess.js
@@ -15,7 +15,7 @@ var filterCond;
 // TODO: maybe load data directly without collect all for "$local.idvalues" -> use other function?? (performance)
 if (vars.exists("$local.idvalues") && vars.get("$local.idvalues") && vars.get("$local.idvalues").length > 0)
 {
-    filterCond = SqlCondition.begin().andIn("DSGVO.DSGVOID", vars.get("$local.idvalues"));
+    filterCond = newWhere("DSGVO.DSGVOID", vars.get("$local.idvalues"), SqlBuilder.IN());
 }
 
 var data = DataPrivacyUtils.collectAll(contactId, filterCond)
diff --git a/entity/DSGVO_entity/recordcontainers/jdito/onUpdate.js b/entity/DSGVO_entity/recordcontainers/jdito/onUpdate.js
index e93e6a8c937df1095ea120bc3ab69c5869cc554b..06252509a4c2c305dcaee79281bec36edcb4167f 100644
--- a/entity/DSGVO_entity/recordcontainers/jdito/onUpdate.js
+++ b/entity/DSGVO_entity/recordcontainers/jdito/onUpdate.js
@@ -27,5 +27,5 @@ var values = [
     vars.get("$field.VALID_TO")
 ];
 
-db.updateData("DSGVO", columns, null, values, 
-    SqlCondition.equals("DSGVO.DSGVOID", vars.get("$field.UID"), "1=2"));
\ No newline at end of file
+newWhere("DSGVO.DSGVOID", "$field.UID")
+    .updateData(true, columns, null, values, "DSGVO");
\ No newline at end of file
diff --git a/entity/DescriptionTranslation_entity/entityfields/lang/displayValueProcess.js b/entity/DescriptionTranslation_entity/entityfields/lang/displayValueProcess.js
index 471293a21aa1604884698461618f2e15e142da92..2c0eaf3fa384b6ccc1f87dd6cb4d1ef45f7d6c73 100644
--- a/entity/DescriptionTranslation_entity/entityfields/lang/displayValueProcess.js
+++ b/entity/DescriptionTranslation_entity/entityfields/lang/displayValueProcess.js
@@ -1,10 +1,8 @@
-import("system.db");
 import("system.translate");
-import("system.vars");
 import("system.result");
-import("KeywordRegistry_basic");
-import("Keyword_lib");
 import("Sql_lib");
 
-result.string(translate.text(db.cell(SqlCondition.begin().andPrepareVars("AB_LANGUAGE.ISO3", "$field.LANG")
-                                   .buildSql("select NAME_LATIN from AB_LANGUAGE", "1=2"))));
\ No newline at end of file
+result.string(translate.text(newSelect("NAME_LATIN")
+                                    .from("AB_LANGUAGE")
+                                    .whereIfSet("AB_LANGUAGE.ISO3", "$field.LANG")
+                                    .cell(true)));
\ No newline at end of file
diff --git a/entity/DescriptionTranslation_entity/entityfields/languages/children/excludedids_param/valueProcess.js b/entity/DescriptionTranslation_entity/entityfields/languages/children/excludedids_param/valueProcess.js
index 15bf867229fbf60954c4f5da8528c73dfd8ba5da..4530654cb3ab3ba974a176dc72d8aad5d037a628 100644
--- a/entity/DescriptionTranslation_entity/entityfields/languages/children/excludedids_param/valueProcess.js
+++ b/entity/DescriptionTranslation_entity/entityfields/languages/children/excludedids_param/valueProcess.js
@@ -1,9 +1,9 @@
 import("Sql_lib");
-import("system.db");
 import("system.result");
 import("system.neon");
 
-result.object(db.array(db.COLUMN, SqlCondition.begin()
-                                              .andPrepareVars("DESCRIPTIONTRANSLATION.OBJECT_TYPE", "$param.ObjectType_param")
-                                              .andPrepareVars("DESCRIPTIONTRANSLATION.OBJECT_ROWID", "$param.ObjectRowid_param")
-                                              .buildSql("select LANG from DESCRIPTIONTRANSLATION", "1=2")));
\ No newline at end of file
+result.object(newSelect("LANG")
+                .from("DESCRIPTIONTRANSLATION")
+                .whereIfSet("DESCRIPTIONTRANSLATION.OBJECT_TYPE", "$param.ObjectType_param")
+                .andIfSet("DESCRIPTIONTRANSLATION.OBJECT_ROWID", "$param.ObjectRowid_param")
+                .arrayColumn(true));
\ No newline at end of file
diff --git a/entity/DescriptionTranslation_entity/recordcontainers/db/conditionProcess.js b/entity/DescriptionTranslation_entity/recordcontainers/db/conditionProcess.js
index a3f2489e6856fc2df4add98949246935c03b7f7d..9b60a2f7aecaea90d458fba6ecff1b8f6aa41a7b 100644
--- a/entity/DescriptionTranslation_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/DescriptionTranslation_entity/recordcontainers/db/conditionProcess.js
@@ -1,10 +1,9 @@
-import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = SqlCondition.begin()
-                       .andPrepareVars("DESCRIPTIONTRANSLATION.OBJECT_TYPE", "$param.ObjectType_param")
-                       .andPrepareVars("DESCRIPTIONTRANSLATION.OBJECT_ROWID", "$param.ObjectRowid_param");
+var cond = newWhere()
+            .andIfSet("DESCRIPTIONTRANSLATION.OBJECT_TYPE", "$param.ObjectType_param")
+            .andIfSet("DESCRIPTIONTRANSLATION.OBJECT_ROWID", "$param.ObjectRowid_param");
                        
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"))
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/DocumentTemplateLink_entity/entityfields/documenttemplate_id_child/displayValueProcess.js b/entity/DocumentTemplateLink_entity/entityfields/documenttemplate_id_child/displayValueProcess.js
index fd9bb084f534e9423351506c9ddc2f185cc27162..ba5ca5ee336d50f42f2b0aa619640e31dc9acb3f 100644
--- a/entity/DocumentTemplateLink_entity/entityfields/documenttemplate_id_child/displayValueProcess.js
+++ b/entity/DocumentTemplateLink_entity/entityfields/documenttemplate_id_child/displayValueProcess.js
@@ -1,14 +1,11 @@
 import("Sql_lib");
 import("system.result");
-import("system.db");
 import("system.vars");
 import("Contact_lib");
 
-var documenttemplatename = "";
-var documenttemplateId = vars.get("$field.DOCUMENTTEMPLATE_ID_CHILD");
-
-documenttemplatename = db.cell(SqlCondition.begin()
-                                  .andPrepare("DOCUMENTTEMPLATE.DOCUMENTTEMPLATEID", documenttemplateId)
-                                  .buildSql("select DOCUMENTTEMPLATE.NAME from DOCUMENTTEMPLATE"));
-
+var documenttemplatename = newSelect("DOCUMENTTEMPLATE.NAME")
+                        .from("DOCUMENTTEMPLATE")
+                        .whereIfSet("DOCUMENTTEMPLATE.DOCUMENTTEMPLATEID", "$field.DOCUMENTTEMPLATE_ID_CHILD")
+                        .cell(true)
+                        
 result.string(documenttemplatename);
\ No newline at end of file
diff --git a/entity/DocumentTemplateLink_entity/entityfields/opendocument/onActionProcess.js b/entity/DocumentTemplateLink_entity/entityfields/opendocument/onActionProcess.js
index 2000c11bdfc242091707529e9500896f728ec98e..972dd9adee7f0f3c758589640eed69350fce1b18 100644
--- a/entity/DocumentTemplateLink_entity/entityfields/opendocument/onActionProcess.js
+++ b/entity/DocumentTemplateLink_entity/entityfields/opendocument/onActionProcess.js
@@ -3,9 +3,11 @@ import("system.db");
 import("system.vars");
 import("system.neon");
 
-var fileInformation = db.array(db.ROW, SqlCondition.begin()
-    .andPrepareVars("ASYS_BINARIES.ROW_ID", "$field.DOCUMENTTEMPLATE_ID_CHILD")
-    .buildSql("select ID, FILENAME from ASYS_BINARIES"), SqlUtils.getBinariesAlias());
+var fileInformation = newSelect("ID, FILENAME", SqlUtils.getBinariesAlias())
+                        .from("ASYS_BINARIES")
+                        .where("ASYS_BINARIES.ROW_ID", "$field.DOCUMENTTEMPLATE_ID_CHILD")
+                        .arrayRow();
+                        
 var data = db.getBinaryContent(fileInformation[0], SqlUtils.getBinariesAlias());
 neon.download(data, fileInformation[1]);
 
diff --git a/entity/DocumentTemplateLink_entity/recordcontainers/db/conditionProcess.js b/entity/DocumentTemplateLink_entity/recordcontainers/db/conditionProcess.js
index 42bd0124d8b04c8af7aa44139283277c30bb99d6..72212f07978dfd9e4d0d8b8f670a0a3e08316621 100644
--- a/entity/DocumentTemplateLink_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/DocumentTemplateLink_entity/recordcontainers/db/conditionProcess.js
@@ -2,8 +2,7 @@ import("system.result");
 import("system.db");
 import("Sql_lib");
 
-var cond = SqlCondition.begin()
-                       .andPrepareVars("DOCUMENTTEMPLATELINK.DOCUMENTTEMPLATE_ID_PARENT", "$param.DocumentId_param")
+var cond = newWhereIfSet("DOCUMENTTEMPLATELINK.DOCUMENTTEMPLATE_ID_PARENT", "$param.DocumentId_param");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1=2"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/DocumentTemplateTypeCategory_entity/recordcontainers/db/conditionProcess.js b/entity/DocumentTemplateTypeCategory_entity/recordcontainers/db/conditionProcess.js
index 005177e8142faf31e9e609defe3acc8b9de77a0f..42e83fc6e021aace37f74c3de356acc19c11a2d0 100644
--- a/entity/DocumentTemplateTypeCategory_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/DocumentTemplateTypeCategory_entity/recordcontainers/db/conditionProcess.js
@@ -5,20 +5,19 @@ import("KeywordRegistry_basic");
 import("Sql_lib");
 import("Keyword_lib");
 
-var cond = SqlCondition.begin()
-                       .andPrepare("AB_KEYWORD_ENTRY.CONTAINER", $KeywordRegistry.documentTemplateTypeCategory());
+var cond = newWhere("AB_KEYWORD_ENTRY.CONTAINER", $KeywordRegistry.documentTemplateTypeCategory());
 
 var usageFilter = vars.get("$param.usageFilter_param");
 if (usageFilter)
 {
     var keywordAttribute = new KeywordAttribute($KeywordRegistry.documentTemplateTypeCategory(), usageFilter);
-    cond.andAttachPrepared(SqlCondition.begin()
-                                       .andPrepare("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ATTRIBUTE_ID", keywordAttribute.id)
-                                       .andPrepare("AB_KEYWORD_ATTRIBUTERELATION." + keywordAttribute.dbField, "1")
-                                       .buildSql("AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID in (\n\
-                                                    select AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID \n\
-                                                    from AB_KEYWORD_ATTRIBUTERELATION ", null, ")"));
+    cond.and("AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID", 
+                newSelect("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID")
+                    .from("AB_KEYWORD_ATTRIBUTERELATION")
+                    .where("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ATTRIBUTE_ID", keywordAttribute.id)
+                    .and("AB_KEYWORD_ATTRIBUTERELATION." + keywordAttribute.dbField, "1")
+            , SqlBuilder.IN());
 }
 
-cond = cond.translate("1 = 2");
-result.string(cond);
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/DocumentTemplate_entity/entityfields/isolanguage/displayValueProcess.js b/entity/DocumentTemplate_entity/entityfields/isolanguage/displayValueProcess.js
index 0a2a0ee65d4db10c8e023e7e2849fbde9b6de533..5ebcc2d6c6b20ff5f13dba82f1108577ec1d162e 100644
--- a/entity/DocumentTemplate_entity/entityfields/isolanguage/displayValueProcess.js
+++ b/entity/DocumentTemplate_entity/entityfields/isolanguage/displayValueProcess.js
@@ -1,12 +1,11 @@
-import("system.db");
 import("system.translate");
 import("system.result");
 import("system.vars");
 import("Sql_lib");
 
-var iso3 = vars.get("$field.ISOLANGUAGE");
-var latinName = db.cell(SqlCondition.begin()
-    .andPrepare("AB_LANGUAGE.ISO3", iso3)
-    .buildSql("select NAME_LATIN from AB_LANGUAGE", "1=0"));
-latinName = translate.text(latinName);
-result.string(latinName);
+var latinName = newSelect("NAME_LATIN")
+                    .from("AB_LANGUAGE")
+                    .whereIfSet("AB_LANGUAGE.ISO3", "$field.ISOLANGUAGE")
+                    .cell(true)
+
+result.string(translate.text(latinName));
diff --git a/entity/DocumentTemplate_entity/entityfields/replacementname/onValidation.js b/entity/DocumentTemplate_entity/entityfields/replacementname/onValidation.js
index efa6426e89fed59dac4d1e3512104e425ce80cf7..3b33299e8dbf5680e9a80e313fb80affed93fd65 100644
--- a/entity/DocumentTemplate_entity/entityfields/replacementname/onValidation.js
+++ b/entity/DocumentTemplate_entity/entityfields/replacementname/onValidation.js
@@ -4,12 +4,13 @@ import("system.vars");
 import("Sql_lib");
 import("system.db");
 
-var count = parseInt(db.cell(SqlCondition.begin()
-                    .andPrepare("DOCUMENTTEMPLATE.REPLACEMENTNAME", vars.get("$local.value"))
-                    .andPrepare("DOCUMENTTEMPLATE.DOCUMENTTEMPLATEID", vars.get("$field.DOCUMENTTEMPLATEID"), "# <> ?")
-                    .buildSql("select count(*) from DOCUMENTTEMPLATE", "1=2")));
-                    
+var count = parseInt(newSelect("count(*)")
+                        .from("DOCUMENTTEMPLATE")
+                        .where("DOCUMENTTEMPLATE.REPLACEMENTNAME", vars.get("$local.value"))
+                        .and("DOCUMENTTEMPLATE.DOCUMENTTEMPLATEID", vars.get("$field.DOCUMENTTEMPLATEID"), "# <> ?")
+                        .cell());
+
 if (count > 0)
 {
     result.string(translate.text("The replacement name has to be unique."));
-}
\ No newline at end of file
+}
diff --git a/entity/DocumentTemplate_entity/recordcontainers/db/conditionProcess.js b/entity/DocumentTemplate_entity/recordcontainers/db/conditionProcess.js
index edcb27db9be3a2e3b082dd36852fba43398f3738..f00432c718e6a697f9bb7ca93bdbc6b926d59efe 100644
--- a/entity/DocumentTemplate_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/DocumentTemplate_entity/recordcontainers/db/conditionProcess.js
@@ -3,8 +3,9 @@ import("system.vars");
 import("system.db");
 import("Sql_lib");
 
-var cond = SqlCondition.begin()
-                       .andPrepareVars("DOCUMENTTEMPLATE.KIND", "$param.DocumentTemplateType_param")
-                       .andPrepareVars("DOCUMENTTEMPLATE.CLASSIFICATION", "$param.DocumentTemplateTypeClassification_param");
+var cond = newWhere()
+            .andIfSet("DOCUMENTTEMPLATE.KIND", "$param.DocumentTemplateType_param")
+            .andIfSet("DOCUMENTTEMPLATE.CLASSIFICATION", "$param.DocumentTemplateTypeClassification_param");
 
-result.string(cond.translate("1=1"));
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
diff --git a/entity/DocumentTemplate_entity/recordcontainers/db/onDBDelete.js b/entity/DocumentTemplate_entity/recordcontainers/db/onDBDelete.js
index a451edb3381eb59d71e300713010b153f846d279..a5b405bd03814af4c9bd758e5db8d0329200cf60 100644
--- a/entity/DocumentTemplate_entity/recordcontainers/db/onDBDelete.js
+++ b/entity/DocumentTemplate_entity/recordcontainers/db/onDBDelete.js
@@ -2,7 +2,9 @@ import("Sql_lib");
 import("system.vars");
 import("system.db");
 
-var binaryId = db.cell(SqlCondition.begin(SqlUtils.getBinariesAlias())
-            .andPrepareVars("ASYS_BINARIES.ROW_ID", "$field.DOCUMENTTEMPLATEID")
-            .buildSql("select ID from ASYS_BINARIES", "1=2"), SqlUtils.getBinariesAlias());
-db.deleteBinary(binaryId, SqlUtils.getBinariesAlias());
\ No newline at end of file
+var binaryId = newSelect("ID", SqlUtils.getBinariesAlias())
+                    .from("ASYS_BINARIES")
+                    .where("ASYS_BINARIES.ROW_ID", "$field.DOCUMENTTEMPLATEID")
+                    .cell();
+if (binaryId)
+    db.deleteBinary(binaryId, SqlUtils.getBinariesAlias());
\ No newline at end of file
diff --git a/entity/Employee_entity/entityfields/contact_id/onValueChange.js b/entity/Employee_entity/entityfields/contact_id/onValueChange.js
index 1d2ceda0ce1308bca68f3edef4ed47a7d0413807..d469435d5c78d77ed6371942df1cb330d36389d3 100644
--- a/entity/Employee_entity/entityfields/contact_id/onValueChange.js
+++ b/entity/Employee_entity/entityfields/contact_id/onValueChange.js
@@ -11,12 +11,12 @@ var contactId = vars.get("local.value");
 if ((vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW || vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT)
     && contactId)
 {
-    var name = db.array(
-        db.ROW, 
-        SqlCondition.begin()
-            .andPrepare("CONTACT.CONTACTID", contactId)
-            .buildSql("select FIRSTNAME, LASTNAME, (" + CommUtil.getStandardSubSqlMail() + ") from PERSON join CONTACT on CONTACT.PERSON_ID = PERSON.PERSONID")
-    );
+    var name = newSelect("FIRSTNAME, LASTNAME, (" + CommUtil.getStandardSubSqlMail() + ")")
+                    .from("PERSON")
+                    .join("CONTACT", "CONTACT.PERSON_ID = PERSON.PERSONID")
+                    .where("CONTACT.CONTACTID", contactId)
+                    .arrayRow();
+
     var username = EmployeeUtils.generateUserName(name[0], name[1], "f.l+");
     
     neon.setFieldValues({
diff --git a/entity/Employee_entity/entityfields/email_address/dropDownProcess.js b/entity/Employee_entity/entityfields/email_address/dropDownProcess.js
index 0bcb8c5ea63dcf7a9224f05f033ad5b418997eff..99e97c2dddc0cae705cdc328a215b226a386f227 100644
--- a/entity/Employee_entity/entityfields/email_address/dropDownProcess.js
+++ b/entity/Employee_entity/entityfields/email_address/dropDownProcess.js
@@ -8,13 +8,12 @@ import("Sql_lib");
 var contactId = vars.get("$field.CONTACT_ID");
 if (contactId && (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT || vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW))
 {
-    var sql = SqlCondition.begin()
-        .andPrepare("COMMUNICATION.CONTACT_ID", contactId)
-        .andIn("COMMUNICATION.MEDIUM_ID", CommUtil.getMediumIdsByCategory("EMAIL"))
-        .buildSql("select ADDR, ADDR from COMMUNICATION");
-    
-    var addresses = db.table(sql);
-    
+    var addresses = newSelect("ADDR, ADDR")
+                .from("COMMUNICATION")
+                .where("COMMUNICATION.CONTACT_ID", contactId)
+                .and("COMMUNICATION.MEDIUM_ID", CommUtil.getMediumIdsByCategory("EMAIL"), SqlBuilder.IN())
+                .table()
+        
     //include the currently set email address
     var currentAddress = vars.get("$field.EMAIL_ADDRESS");
     if (currentAddress && !addresses.some(function (row) {return row[0] == currentAddress;}))
diff --git a/entity/Employee_entity/entityfields/image/valueProcess.js b/entity/Employee_entity/entityfields/image/valueProcess.js
index d36f4b5cb45ad14fb9cb51f57ec4ba149c526468..51072a509c78c67d6967b696c4358e3a63a6da0b 100644
--- a/entity/Employee_entity/entityfields/image/valueProcess.js
+++ b/entity/Employee_entity/entityfields/image/valueProcess.js
@@ -7,9 +7,10 @@ import("Sql_lib");
 
 if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_VIEW)
 {   
-    var personId = db.cell(SqlCondition.begin()
-        .andPrepareVars("CONTACT.CONTACTID", "$field.CONTACT_ID")
-        .buildSql("select PERSON_ID from CONTACT")
-    );
-    result.string(PersUtils.getImage(personId, (vars.getString("$field.FIRSTNAME") + " " + vars.getString("$field.LASTNAME")).trim()));
+    var personId = newSelect("PERSON_ID")
+                    .from("CONTACT")
+                    .whereIfSet("CONTACT.CONTACTID", "$field.CONTACT_ID")
+                    .cell(true)
+    if (personId)
+        result.string(PersUtils.getImage(personId, (vars.getString("$field.FIRSTNAME") + " " + vars.getString("$field.LASTNAME")).trim()));
 }
diff --git a/entity/Employee_entity/recordcontainers/jdito/contentProcess.js b/entity/Employee_entity/recordcontainers/jdito/contentProcess.js
index 4d17f73bab9abfae6db2b2ec49a190b379fcabd0..048079355f477ee6f3f123b68773f324ba5df07d 100644
--- a/entity/Employee_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/Employee_entity/recordcontainers/jdito/contentProcess.js
@@ -48,15 +48,14 @@ var selectExpression = renderer.asSql();
 
 var idsPerPage = 1000;
 var names = [];
-var select = "select CONTACTID, " + selectExpression + " from CONTACT \n\
-    left join PERSON on (PERSON.PERSONID = CONTACT.PERSON_ID)";
 
 for (let begin = 0, max = contactIds.length; begin < max; begin += idsPerPage)
 {
-    names = names.concat(db.table(SqlCondition.begin()
-        .andIn("CONTACT.CONTACTID", contactIds.slice(begin, begin + idsPerPage))
-        .buildSql(select)
-    ));
+    names = names.concat(newSelect("CONTACTID, " + selectExpression)
+                            .from("CONTACT")
+                            .leftJoin("PERSON", "(PERSON.PERSONID = CONTACT.PERSON_ID)")
+                            .whereIfSet("CONTACT.CONTACTID", contactIds.slice(begin, begin + idsPerPage), SqlBuilder.IN())
+                            .table(true));
 }
 var nameMap = {};
 for (let i = 0, l = names.length; i < l; i++)
diff --git a/entity/Employee_entity/recordcontainers/jdito/onUpdate.js b/entity/Employee_entity/recordcontainers/jdito/onUpdate.js
index ac20df00f13b9101bb9c41b3e6eae675f520b315..678bac1f032ca2ae4e234735af84cce3599b4df9 100644
--- a/entity/Employee_entity/recordcontainers/jdito/onUpdate.js
+++ b/entity/Employee_entity/recordcontainers/jdito/onUpdate.js
@@ -8,10 +8,11 @@ import("Entity_lib");
 // TODO: this is a workaround for missing possibility to react on changes of fields not connected to record Contqainer #1030023
 FieldChanges.assimilateChangeAndDispose("$field.IMAGE", function (state, value)
 {
-    var personId = db.cell(SqlCondition.begin()
-        .andPrepareVars("CONTACT.CONTACTID", "$field.CONTACT_ID")
-        .buildSql("select PERSON_ID from CONTACT")
-    );
+    var personId = newSelect("PERSON_ID")
+                        .from("CONTACT")
+                        .where("CONTACT.CONTACTID", "$field.CONTACT_ID")
+                        .cell()
+
     if (state == FieldChanges.STATE_CHANGED())
         PersUtils.setImage(personId, value);
     else
diff --git a/entity/Forecast_entity/conditionProcess.js b/entity/Forecast_entity/conditionProcess.js
index 9347e425a02c272ffc6af991320481a3e8ad7ff9..3f88d5b798124f2191f5b0a39e28dc5d484e580e 100644
--- a/entity/Forecast_entity/conditionProcess.js
+++ b/entity/Forecast_entity/conditionProcess.js
@@ -2,8 +2,7 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = new SqlCondition();
-cond.andPrepareVars("FORECAST.OBJECT_ROWID", "$param.ForecastId_param");
+var cond = newWhereIfSet("FORECAST.OBJECT_ROWID", "$param.ForecastId_param");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/Forecast_entity/recordcontainers/db/conditionProcess.js b/entity/Forecast_entity/recordcontainers/db/conditionProcess.js
index 94d1422d484608c49641c9b2cd7eef12512f1874..a4ec94640015904a7560453161e2cab3a49c2320 100644
--- a/entity/Forecast_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Forecast_entity/recordcontainers/db/conditionProcess.js
@@ -3,9 +3,9 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = SqlCondition.begin()
-                       .andPrepareVars("FORECAST.OBJECT_ROWID", "$param.ObjectRowId_param")
-                       .andPrepareVars("FORECAST.OBJECT_TYPE", "$param.ObjectType_param");
+var cond = newWhere()
+            .andIfSet("FORECAST.OBJECT_ROWID", "$param.ObjectRowId_param")
+            .andIfSet("FORECAST.OBJECT_TYPE", "$param.ObjectType_param");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/KeywordAttributeRelation_entity/entityfields/ab_keyword_attribute_id/displayValueProcess.js b/entity/KeywordAttributeRelation_entity/entityfields/ab_keyword_attribute_id/displayValueProcess.js
index 2f5a5971a652b4452f302bad464d1a81c73853ec..77b42b6a05e812ca8448312e8f4afa06a28834a9 100644
--- a/entity/KeywordAttributeRelation_entity/entityfields/ab_keyword_attribute_id/displayValueProcess.js
+++ b/entity/KeywordAttributeRelation_entity/entityfields/ab_keyword_attribute_id/displayValueProcess.js
@@ -7,9 +7,9 @@ var keywordAttributeId = vars.get("$field.AB_KEYWORD_ATTRIBUTE_ID");
 var res = keywordAttributeId;
 if (keywordAttributeId)
 {
-    var sql  = SqlCondition.begin()
-                           .andPrepare("AB_KEYWORD_ATTRIBUTE.AB_KEYWORD_ATTRIBUTEID", keywordAttributeId)
-                           .buildSql("select AB_KEYWORD_ATTRIBUTE.NAME, AB_KEYWORD_ATTRIBUTE.KIND from AB_KEYWORD_ATTRIBUTE");
-    res = db.cell(sql);
+    res  = newSelect("AB_KEYWORD_ATTRIBUTE.NAME, AB_KEYWORD_ATTRIBUTE.KIND")
+                    .from("AB_KEYWORD_ATTRIBUTE")
+                    .where("AB_KEYWORD_ATTRIBUTE.AB_KEYWORD_ATTRIBUTEID", keywordAttributeId)
+                    .cell();
 }
 result.string(res);
\ No newline at end of file
diff --git a/entity/KeywordAttributeRelation_entity/entityfields/attributetype/valueProcess.js b/entity/KeywordAttributeRelation_entity/entityfields/attributetype/valueProcess.js
index cbac8d6452c9fe3a1344d497181ddf75c4d3bfe1..9cb38f0d3f6e2a03e6c42cea5e2599ccbd1092c5 100644
--- a/entity/KeywordAttributeRelation_entity/entityfields/attributetype/valueProcess.js
+++ b/entity/KeywordAttributeRelation_entity/entityfields/attributetype/valueProcess.js
@@ -10,9 +10,11 @@ var id = vars.get("$field.AB_KEYWORD_ATTRIBUTE_ID");
 var type = null;
 if (id)
 {
-    type = db.cell(SqlCondition.begin()
-                               .andPrepare("AB_KEYWORD_ATTRIBUTE.AB_KEYWORD_ATTRIBUTEID", id)
-                               .buildSql("select AB_KEYWORD_ATTRIBUTE.KIND from AB_KEYWORD_ATTRIBUTE"));
+    type = newSelect("AB_KEYWORD_ATTRIBUTE.KIND")
+                .from("AB_KEYWORD_ATTRIBUTE")
+                .where("AB_KEYWORD_ATTRIBUTE.AB_KEYWORD_ATTRIBUTEID", id)
+                .cell();
+                
     type = type.trim();
 }
 result.string(type);
\ No newline at end of file
diff --git a/entity/KeywordAttributeRelation_entity/entityfields/containername_param/valueProcess.js b/entity/KeywordAttributeRelation_entity/entityfields/containername_param/valueProcess.js
index 44f180a7780f7bf5615cdd0ecac7f8d619d732de..77a772ba0e557111e7457572056a741675682979 100644
--- a/entity/KeywordAttributeRelation_entity/entityfields/containername_param/valueProcess.js
+++ b/entity/KeywordAttributeRelation_entity/entityfields/containername_param/valueProcess.js
@@ -4,7 +4,9 @@ import("system.vars");
 import("Sql_lib");
 
 var entryId = vars.get("$param.KeywordEntryId_param");
-var containerName = db.cell(SqlCondition.begin().andPrepare("AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID", entryId)
-                                                .buildSql("select AB_KEYWORD_ENTRY.CONTAINER from AB_KEYWORD_ENTRY"));
+var containerName = newSelect("AB_KEYWORD_ENTRY.CONTAINER")
+                        .from("AB_KEYWORD_ENTRY")
+                        .where("AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID", entryId)
+                        .cell();
 
 result.string(containerName);
\ No newline at end of file
diff --git a/entity/KeywordAttributeRelation_entity/recordcontainers/db/conditionProcess.js b/entity/KeywordAttributeRelation_entity/recordcontainers/db/conditionProcess.js
index 4e5f1178f2852ef65d24f326ae0c02b72d26efb8..88a371d623036551c0e883501e7ce2fbb7467852 100644
--- a/entity/KeywordAttributeRelation_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/KeywordAttributeRelation_entity/recordcontainers/db/conditionProcess.js
@@ -4,7 +4,7 @@ import("system.vars");
 import("system.result");
 import("Sql_lib");
 
-var cond = SqlCondition.begin().andPrepareVars("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID", "$param.KeywordEntryId_param");
+var cond = newWhereIfSet("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID", "$param.KeywordEntryId_param");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/KeywordAttribute_entity/entityfields/name/onValidation.js b/entity/KeywordAttribute_entity/entityfields/name/onValidation.js
index 8711e91f305852080a4d2c2b093e33b85a04c0e9..b12c2615dc53fc1a9df233274bbf7eeae2f5caf4 100644
--- a/entity/KeywordAttribute_entity/entityfields/name/onValidation.js
+++ b/entity/KeywordAttribute_entity/entityfields/name/onValidation.js
@@ -17,9 +17,12 @@ var validation = (function(){
     if (name == "")
         return null;
     
-    var cond = SqlCondition.begin().andPrepare("AB_KEYWORD_ATTRIBUTE.CONTAINER", container)
-                                   .andPrepare("AB_KEYWORD_ATTRIBUTE.name", name);
-    var alreadyExistingCount = db.cell(cond.buildSql("select count(*) from AB_KEYWORD_ATTRIBUTE"));
+    var alreadyExistingCount = newSelect("count(*)")
+                    .from("AB_KEYWORD_ATTRIBUTE")
+                    .where("AB_KEYWORD_ATTRIBUTE.CONTAINER", container)
+                    .and("AB_KEYWORD_ATTRIBUTE.name", name)
+                    .cell()
+        
     if (alreadyExistingCount != "0")
         return translate.withArguments("Name \"%0\" already used for container \"%1\"", [name, container]);
     
diff --git a/entity/KeywordAttribute_entity/recordcontainers/db/conditionProcess.js b/entity/KeywordAttribute_entity/recordcontainers/db/conditionProcess.js
index 55cf99b5b9f3882673102fe38589cea09365bab5..823c3d4a9247760a8f02f2a715291b64e32315b4 100644
--- a/entity/KeywordAttribute_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/KeywordAttribute_entity/recordcontainers/db/conditionProcess.js
@@ -3,19 +3,18 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = SqlCondition.begin().andPrepareVars("AB_KEYWORD_ATTRIBUTE.CONTAINER", "$param.ContainerName_param");
+var cond = newWhereIfSet("AB_KEYWORD_ATTRIBUTE.CONTAINER", "$param.ContainerName_param");
 
 //filter for entries that are already used by entry_id
 var entryIdForFilter = vars.get("$param.FilterAlreadyUsedByEntryId_param");
 if (entryIdForFilter)
 {
-    var exclusiveFilterCondition = SqlCondition.begin()
-        .andPrepare("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID", entryIdForFilter)
-        .buildSql("AB_KEYWORD_ATTRIBUTE.AB_KEYWORD_ATTRIBUTEID not in (\n\
-            select AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ATTRIBUTE_ID \n\
-            from AB_KEYWORD_ATTRIBUTERELATION ", null, ")");
-    cond.andAttachPrepared(exclusiveFilterCondition);
+    cond.andIfSet("AB_KEYWORD_ATTRIBUTE.AB_KEYWORD_ATTRIBUTEID", 
+                newSelect("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ATTRIBUTE_ID")
+                    .from("AB_KEYWORD_ATTRIBUTERELATION")
+                    .whereIfSet("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID", entryIdForFilter),
+                SqlBuilder.NOT_IN())
 }
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/KeywordAttribute_entity/recordcontainers/db/onDBDelete.js b/entity/KeywordAttribute_entity/recordcontainers/db/onDBDelete.js
index 106ba3d52cf62b33fe39087d4a893ea7821b9462..4b8a8a5053fe8dfa2257ab5b6e486dfde2063566 100644
--- a/entity/KeywordAttribute_entity/recordcontainers/db/onDBDelete.js
+++ b/entity/KeywordAttribute_entity/recordcontainers/db/onDBDelete.js
@@ -1,5 +1,4 @@
 import("Sql_lib");
-import("system.db");
 
-var cond = SqlCondition.begin().andPrepareVars("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ATTRIBUTE_ID", "$field.AB_KEYWORD_ATTRIBUTEID").build("1=2");
-db.deleteData("AB_KEYWORD_ATTRIBUTERELATION", cond);
\ No newline at end of file
+newWhereIfSet("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ATTRIBUTE_ID", "$field.AB_KEYWORD_ATTRIBUTEID")
+    .deleteData(true, "AB_KEYWORD_ATTRIBUTERELATION");
\ No newline at end of file
diff --git a/entity/KeywordEntry_entity/entityfields/keyid/onValidation.js b/entity/KeywordEntry_entity/entityfields/keyid/onValidation.js
index c617b930c473204ff932028051fbe2c1faccaa75..c2f8b92dafb79b983279d246474d01b602a5330b 100644
--- a/entity/KeywordEntry_entity/entityfields/keyid/onValidation.js
+++ b/entity/KeywordEntry_entity/entityfields/keyid/onValidation.js
@@ -13,12 +13,12 @@ if (container && keyId)
 {
     var selfEntryId = vars.get("$field.AB_KEYWORD_ENTRYID");
     var sqlMasks = new SqlMaskingUtils();
-    var alreadyExistsSql = SqlCondition.begin()
-                                        .andPrepare(sqlMasks.trim("AB_KEYWORD_ENTRY.KEYID"), keyId, null, SqlUtils.getSingleColumnType("AB_KEYWORD_ENTRY", "KEYID"))
-                                        .andPrepare("AB_KEYWORD_ENTRY.CONTAINER", container)
-                                        .andPrepare("AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID", selfEntryId, "# != ?")
-                                        .buildSql("select AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID from AB_KEYWORD_ENTRY");
-    var alreadyExistantEntryId = db.cell(alreadyExistsSql);
+    var alreadyExistantEntryId = newSelect("AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID")
+                                    .from("AB_KEYWORD_ENTRY")
+                                    .where(sqlMasks.trim("AB_KEYWORD_ENTRY.KEYID"), keyId, null, SqlUtils.getSingleColumnType("AB_KEYWORD_ENTRY", "KEYID"))
+                                    .and("AB_KEYWORD_ENTRY.CONTAINER", container)
+                                    .and("AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID", selfEntryId, "# != ?")
+                                    .cell();
     
     if (alreadyExistantEntryId != "")
         result.string(translate.text("the specified key has to be unique for that container but does already exist"));
diff --git a/entity/KeywordEntry_entity/entityfields/keywordattributerelations/onValidation.js b/entity/KeywordEntry_entity/entityfields/keywordattributerelations/onValidation.js
index ff0553af7e4a904edf8807108c2c417aadd12adb..4cf093fbc85a4dabf9c0be6e386d1ad8b05804d8 100644
--- a/entity/KeywordEntry_entity/entityfields/keywordattributerelations/onValidation.js
+++ b/entity/KeywordEntry_entity/entityfields/keywordattributerelations/onValidation.js
@@ -13,10 +13,11 @@ function _areUnique ()
     var changedRows = vars.get("$field.KeywordAttributeRelations.changedRows");
     var deletedRows = vars.get("$field.KeywordAttributeRelations.deletedRows");
 
-    var storedRows = db.table(SqlCondition.begin()
-        .andPrepare("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID", vars.get("$field.AB_KEYWORD_ENTRYID"))
-        .buildSql("select AB_KEYWORD_ATTRIBUTERELATIONID, AB_KEYWORD_ATTRIBUTE_ID from AB_KEYWORD_ATTRIBUTERELATION"));
-    
+    var storedRows = newSelect("AB_KEYWORD_ATTRIBUTERELATIONID, AB_KEYWORD_ATTRIBUTE_ID")
+                        .from("AB_KEYWORD_ATTRIBUTERELATION")
+                        .where("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID", "$field.AB_KEYWORD_ENTRYID")
+                        .table();
+                        
     var attributeChanges = {};
 
     if (deletedRows)
diff --git a/entity/KeywordEntry_entity/onValidation.js b/entity/KeywordEntry_entity/onValidation.js
index f771dd784476b962438a1eafb789f0c145e5af3b..463a84f18f8bcf21fe9539ab5041c31be8a7a958 100644
--- a/entity/KeywordEntry_entity/onValidation.js
+++ b/entity/KeywordEntry_entity/onValidation.js
@@ -11,9 +11,12 @@ if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
     var keyContainer = vars.get("$field.CONTAINER");
     if (keyContainer)
     {
-        var cond = SqlCondition.begin().andPrepare("AB_KEYWORD_ENTRY.CONTAINER", keyContainer);
         var maskingHelper = new SqlMaskingUtils();
-        var newCodeNumber = db.cell(cond.buildSql("select " + maskingHelper.max("AB_KEYWORD_ENTRY.SORTING") + " from AB_KEYWORD_ENTRY", "1 = 2"));
+        var newCodeNumber = newSelect(maskingHelper.max("AB_KEYWORD_ENTRY.SORTING"))
+                                .from("AB_KEYWORD_ENTRY")
+                                .where("AB_KEYWORD_ENTRY.CONTAINER", keyContainer)
+                                .cell();
+                                
         newCodeNumber = Number(newCodeNumber);//if no number exists till no, start value will be 1 (due to: ++0)
         if (isNaN(newCodeNumber))
             throw new TypeError(translate.text("The code number is not a valid number."));
diff --git a/entity/KeywordEntry_entity/recordcontainers/db/conditionProcess.js b/entity/KeywordEntry_entity/recordcontainers/db/conditionProcess.js
index 3693ae0cb044259440c9c51b0279088cb7e0646f..ba9d5cc9a90c1fb75ef9a9c1a675d99702e56e5a 100644
--- a/entity/KeywordEntry_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/KeywordEntry_entity/recordcontainers/db/conditionProcess.js
@@ -3,18 +3,20 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = SqlCondition.begin().andPrepareVars("AB_KEYWORD_ENTRY.CONTAINER", "$param.ContainerName_param");
+var cond = newWhereIfSet("AB_KEYWORD_ENTRY.CONTAINER", "$param.ContainerName_param");
 
 if (vars.get("$param.OnlyActives_param") == "true")
 {
-    cond.andPrepare("AB_KEYWORD_ENTRY.ISACTIVE", "1");
+    cond.and("AB_KEYWORD_ENTRY.ISACTIVE", "1");
 }
 
-if (vars.exists("$param.ExcludedKeyIdsSubquery_param") && vars.get("$param.ExcludedKeyIdsSubquery_param"))
-    cond.and("AB_KEYWORD_ENTRY.KEYID not in (" + vars.get("$param.ExcludedKeyIdsSubquery_param") + ")");
+if (vars.get("$param.ExcludedKeyIdsSubquery_param"))
+{
+    cond.and("AB_KEYWORD_ENTRY.KEYID not in ( " + vars.get("$param.ExcludedKeyIdsSubquery_param") + ")");
+}
 
-if (vars.exists("$param.WhitelistIds_param") && vars.getString("$param.WhitelistIds_param"))
-    cond.andIn("AB_KEYWORD_ENTRY.KEYID", JSON.parse(vars.getString("$param.WhitelistIds_param")));
+if (vars.getString("$param.WhitelistIds_param"))
+    cond.and("AB_KEYWORD_ENTRY.KEYID", JSON.parse(vars.getString("$param.WhitelistIds_param")), SqlBuilder.IN());
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/KeywordEntry_entity/recordcontainers/db/onDBDelete.js b/entity/KeywordEntry_entity/recordcontainers/db/onDBDelete.js
index 5770e446a9d339b5e4aa822f225fa0d36bd3a4ac..b45269cdbb202703cef4c51837fb97294c634ee9 100644
--- a/entity/KeywordEntry_entity/recordcontainers/db/onDBDelete.js
+++ b/entity/KeywordEntry_entity/recordcontainers/db/onDBDelete.js
@@ -1,5 +1,5 @@
 import("Sql_lib");
 import("system.db");
 
-var cond = SqlCondition.begin().andPrepareVars("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID", "$field.AB_KEYWORD_ENTRYID").build("1=2");
-db.deleteData("AB_KEYWORD_ATTRIBUTERELATION", cond);
\ No newline at end of file
+newWhere("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID", "$field.AB_KEYWORD_ENTRYID")
+    .deleteData(true, "AB_KEYWORD_ATTRIBUTERELATION");
\ No newline at end of file
diff --git a/entity/Language_entity/recordcontainers/db/conditionProcess.js b/entity/Language_entity/recordcontainers/db/conditionProcess.js
index 7914a70b5d94ce14e00d4ad8de154e114dc839b2..9e0e3a69ce20255f94f5f90179b9dbc93ac2c006 100644
--- a/entity/Language_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Language_entity/recordcontainers/db/conditionProcess.js
@@ -2,12 +2,13 @@ import("system.vars");
 import("system.db");
 import("system.result");
 import("Sql_lib");
-var cond = SqlCondition.begin();
 
-if (vars.exists("$param.ExcludedIds_param") && vars.getString("$param.ExcludedIds_param"))
+var cond = newWhere()
+
+if (vars.getString("$param.ExcludedIds_param"))
 {
-    cond.andIn("AB_LANGUAGE.ISO3", JSON.parse(vars.getString("$param.ExcludedIds_param")), undefined, true)
+    cond.andIfSet("AB_LANGUAGE.ISO3", JSON.parse(vars.getString("$param.ExcludedIds_param")), SqlBuilder.NOT_IN())
 }
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"))
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString())
\ No newline at end of file
diff --git a/entity/LetterRecipient_entity/entityfields/recipientactions/children/removewithcommrestriction/onActionProcess.js b/entity/LetterRecipient_entity/entityfields/recipientactions/children/removewithcommrestriction/onActionProcess.js
index 80ae8387d5e95fa964747c3b538fa58927007c6b..419c184eaaff79d2a8bf7d29b6c1c718dedb2618 100644
--- a/entity/LetterRecipient_entity/entityfields/recipientactions/children/removewithcommrestriction/onActionProcess.js
+++ b/entity/LetterRecipient_entity/entityfields/recipientactions/children/removewithcommrestriction/onActionProcess.js
@@ -4,21 +4,19 @@ import("Sql_lib");
 import("KeywordRegistry_basic");
 import("system.db");
 
-var recipientIds = db.array(db.COLUMN, SqlBuilder.begin()
+var recipientIds = SqlBuilder.begin()
     .select("LETTERRECIPIENTID")
     .from("LETTERRECIPIENT")
-    .join("CONTACT", SqlCondition.begin()
-        .and("LETTERRECIPIENT.CONTACT_ID = CONTACT.CONTACTID")
-        .andSqlCondition(ContactUtils.getCommRestrictionCondition($KeywordRegistry.communicationMediumCampaign$letter())))
-    .where(SqlCondition.begin()
-        .andPrepareVars("LETTERRECIPIENT.SERIALLETTER_ID", "$param.SerialLetterId_param"))
-    .build());
+    .join("CONTACT", 
+        newWhere("LETTERRECIPIENT.CONTACT_ID = CONTACT.CONTACTID")
+        .and(ContactUtils.getCommRestrictionCondition($KeywordRegistry.communicationMediumCampaign$letter())))
+    .whereIfSet("LETTERRECIPIENT.SERIALLETTER_ID", "$param.SerialLetterId_param")
+    .array(db.COLUMN);
 
 if (recipientIds.length)
 {
-    db.deleteData("LETTERRECIPIENT", SqlCondition.begin()
-        .andIn("LETTERRECIPIENT.LETTERRECIPIENTID", recipientIds)
-        .build("1=2"));
+    newWhere("LETTERRECIPIENT.LETTERRECIPIENTID", recipientIds, SqlBuilder.IN())
+        .deleteData(true, "LETTERRECIPIENT");
 }
 
 neon.refreshAll();
\ No newline at end of file
diff --git a/entity/LogHistory_entity/recordcontainers/jdito/contentProcess.js b/entity/LogHistory_entity/recordcontainers/jdito/contentProcess.js
index 0491ec44c721775ce0918ac9ec049b0d06d6f222..3a533bb36dc76380d281f23cbbb8bd06977f7e42 100644
--- a/entity/LogHistory_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/LogHistory_entity/recordcontainers/jdito/contentProcess.js
@@ -8,7 +8,10 @@ import("Sql_lib");
 import("system.vars");
 import("system.db");
 
-var recordCond = SqlCondition.begin();
+var logSelect = newSelect("AB_LOGHISTORY.DATE_NEW, AB_LOGHISTORY.USER_NEW, AB_LOGHISTORY.DESCRIPTION")
+                    .from("AB_LOGHISTORY")
+                    .orderBy("DATE_NEW desc, USER_NEW asc")
+                    .where();
 
 //condition for only one/some selected records 
 //since this NOT (!) a unique ID we need to filter with all the other filters (via params) too
@@ -18,29 +21,25 @@ if (vars.exists("$local.idvalues"))
     if (semiId && semiId.length > 0)
     {
         var groupingInfo = JSON.parse(semiId[0]);
-        recordCond.andPrepare("AB_LOGHISTORY.USER_NEW", groupingInfo.u);
+        logSelect.and("AB_LOGHISTORY.USER_NEW", groupingInfo.u);
         var dateFilterValue = datetime.toLong(groupingInfo.d, "yyyy-MM-dd HH:mm");
-        recordCond.andPrepare("AB_LOGHISTORY.DATE_NEW", dateFilterValue, "# >= ?");
-        recordCond.andPrepare("AB_LOGHISTORY.DATE_NEW", eMath.addInt(dateFilterValue, datetime.ONE_MINUTE), "# < ?");
+        logSelect.and("AB_LOGHISTORY.DATE_NEW", dateFilterValue, "# >= ?");
+        logSelect.and("AB_LOGHISTORY.DATE_NEW", eMath.addInt(dateFilterValue, datetime.ONE_MINUTE), "# < ?");
     }
 }
 
 //condition for restricting the loghistory to some specific tables (e.g. only contact-related tables) and a specific ID
-var tableNameCond = _getTableNameCondition();
-recordCond.andSqlCondition(tableNameCond);
+logSelect.andIfSet(_getTableNameCondition());
 
 //user defined filter
 if (vars.exists("$local.filter") && vars.get("$local.filter"))
 {
     var filter = vars.get("$local.filter");
     if (filter.filter)
-    recordCond.andSqlCondition((JditoFilterUtils.getSqlCondition(filter.filter, "AB_LOGHISTORY")));
+        logSelect.andIfSet(JditoFilterUtils.getSqlCondition(filter.filter, "AB_LOGHISTORY"));
 }
 
-var dataQuery = recordCond.buildSql("select AB_LOGHISTORY.DATE_NEW, AB_LOGHISTORY.USER_NEW, AB_LOGHISTORY.DESCRIPTION \n\
-        from AB_LOGHISTORY ", "1 = 2", "order by DATE_NEW desc, USER_NEW asc");
-
-var data = db.table(dataQuery);
+var data = logSelect.table(true);
 var resultData = _groupData(data);
 result.object(resultData);
 
@@ -87,26 +86,17 @@ function _groupData(pData)
     return res;
 }
 
-//converts the very dynamic talbeName-condition to a SqlCondition
+//converts the very dynamic talbeName-condition to a SqlBuilder
 function _getTableNameCondition()
 {
-    var tableNameCond = SqlCondition.begin();
-    var tableNamesList = JSON.parse(vars.getString("$param.tablenames_param"));
     
-    //returns the condition for one entry in the tableNamesList
-    var _getCond = function(pDefinition)
-    {
-        var resCond = SqlCondition.begin();
-        pDefinition.tableNames.forEach(function(elem){
-            resCond.orPrepare("AB_LOGHISTORY.TABLENAME", elem);
-        });
+    var tableNamesList = JSON.parse(vars.getString("$param.tablenames_param"));
         
-        resCond = SqlCondition.begin().andSqlCondition(resCond).andPrepare("AB_LOGHISTORY.TABLENAMEID", pDefinition.id);
-        return resCond;
-    };
+    var tableNameCond = newWhere();
     
-    tableNamesList.forEach(function(e){
-        tableNameCond.orSqlCondition(_getCond.call(this, e));
+    tableNamesList.forEach(function(pDefinition){
+        tableNameCond.orIfSet(newWhereIfSet("AB_LOGHISTORY.TABLENAME", pDefinition.tableNames, SqlBuilder.IN())
+                                .and("AB_LOGHISTORY.TABLENAMEID", pDefinition.id));
     });
     
     return tableNameCond;
diff --git a/entity/Member_entity/entityfields/contacts/children/excludedcontactids_param/valueProcess.js b/entity/Member_entity/entityfields/contacts/children/excludedcontactids_param/valueProcess.js
index f1c9cd6147c3f4a813d79339899b4a1ba520f27b..22f69f2e8ce31389ce105f9aac485d8faaf3649f 100644
--- a/entity/Member_entity/entityfields/contacts/children/excludedcontactids_param/valueProcess.js
+++ b/entity/Member_entity/entityfields/contacts/children/excludedcontactids_param/valueProcess.js
@@ -3,7 +3,8 @@ import("system.vars");
 import("system.db");
 import("Sql_lib");
 
-result.object(db.array(db.COLUMN, SqlCondition.begin()
-                                .andPrepare("OBJECTMEMBER.OBJECT_ROWID", vars.get("$field.OBJECT_ROWID"))
-                                .buildSql("select CONTACT_ID from OBJECTMEMBER", "1=2")));
-                     
\ No newline at end of file
+result.object(newSelect("CONTACT_ID")
+                    .from("OBJECTMEMBER")
+                    .where("OBJECTMEMBER.OBJECT_ROWID", "$field.OBJECT_ROWID")
+                    .and("OBJECTMEMBER.OBJECT_TYPE", "$field.OBJECT_TYPE")
+                    .arrayColumn());
\ No newline at end of file
diff --git a/entity/Member_entity/recordcontainers/db/conditionProcess.js b/entity/Member_entity/recordcontainers/db/conditionProcess.js
index 374388b3f4aa303740bf6ff4f955b2a33e4e6e04..8ea033217e401e458c462cc899184bf4f8b24cd1 100644
--- a/entity/Member_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Member_entity/recordcontainers/db/conditionProcess.js
@@ -2,9 +2,9 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = new SqlCondition();
-cond.andPrepareVars("OBJECTMEMBER.OBJECT_ROWID", "$param.ObjectRowId_param")
-cond.andPrepareVars("OBJECTMEMBER.OBJECT_TYPE", "$param.ObjectType_param");
+var cond = newWhere()
+            .andIfSet("OBJECTMEMBER.OBJECT_ROWID", "$param.ObjectRowId_param")
+            .andIfSet("OBJECTMEMBER.OBJECT_TYPE", "$param.ObjectType_param");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/ModuleTree_entity/recordcontainers/jdito/contentProcess.js b/entity/ModuleTree_entity/recordcontainers/jdito/contentProcess.js
index 730e0e483ab0e04421d6fdecc95c8cf5a7e74080..0747bea5597f2438cff0f1a377488df9f1c140d3 100644
--- a/entity/ModuleTree_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/ModuleTree_entity/recordcontainers/jdito/contentProcess.js
@@ -9,7 +9,6 @@ var fixedID = vars.get("$param.ID_param");
 
 let resArray = [];
 
-var cond = new SqlCondition();
 // Query root element
 var root = queryRootElement(fixedContextName, fixedID, true);
 
@@ -37,22 +36,25 @@ if (root !== null) {
  */
 function queryChildrenElements (pContextName, pID) {
     
-    var taskResult = db.table(SqlCondition.begin()
-    .andPrepare("TASK.PARENT_ID", pID)
-    .andPrepare("TASK.PARENT_CONTEXT", pContextName)
-    .andPrepare("TASK.KIND", $KeywordRegistry.taskType$task())
-    .buildSql("select TASKID, PARENT_ID, PARENT_CONTEXT, SUBJECT, DESCRIPTION from TASK"));
+    var taskResult = newSelect("TASKID, PARENT_ID, PARENT_CONTEXT, SUBJECT, DESCRIPTION")
+                        .from("TASK")
+                        .where("TASK.PARENT_ID", pID)
+                        .and("TASK.PARENT_CONTEXT", pContextName)
+                        .and("TASK.KIND", $KeywordRegistry.taskType$task())
+                        .table();
     
+    var ticketResult = newSelect("TICKETID, PARENT_ID, PARENT_CONTEXT, SUBJECT, DESCRIPTION")
+                        .from("TICKET")
+                        .leftJoin("TASK", "TASK_ID = TASKID")
+                        .where("TASK.PARENT_ID", pID)
+                        .and("TASK.PARENT_CONTEXT", pContextName)
+                        .table();
     
-     var ticketResult = db.table(SqlCondition.begin()
-    .andPrepare("TASK.PARENT_ID", pID)
-    .andPrepare("TASK.PARENT_CONTEXT", pContextName)
-    .buildSql("select TICKETID, PARENT_ID, PARENT_CONTEXT, SUBJECT, DESCRIPTION from TICKET left join TASK on TASK_ID = TASKID"));
-    
-    var activityResult = db.table(SqlCondition.begin()
-    .andPrepare("ACTIVITY.PARENT_ID", pID)
-    .andPrepare("ACTIVITY.PARENT_CONTEXT", pContextName)
-    .buildSql("select ACTIVITYID, PARENT_ID, PARENT_CONTEXT, SUBJECT, INFO from ACTIVITY"));
+    var activityResult = newSelect("ACTIVITYID, PARENT_ID, PARENT_CONTEXT, SUBJECT, INFO")
+                        .from("ACTIVITY")
+                        .where("ACTIVITY.PARENT_ID", pID)
+                        .and("ACTIVITY.PARENT_CONTEXT", pContextName)
+                        .table();
     
     var res = []
   
@@ -99,9 +101,11 @@ function queryChildrenElements (pContextName, pID) {
 function queryRootElement (pContextName, pID, pGetFirst) {
     var resultArray;
     if (pContextName === "Task") {
-        resultArray = db.array(db.ROW, SqlCondition.begin()
-            .andPrepare("TASK.TASKID", pID)
-            .buildSql("select TASKID, PARENT_ID, PARENT_CONTEXT, SUBJECT, DESCRIPTION from TASK"));
+        resultArray = newSelect("TASKID, PARENT_ID, PARENT_CONTEXT, SUBJECT, DESCRIPTION")
+                        .from("TASK")
+                        .where("TASK.TASKID", pID)
+                        .arrayRow();
+                        
         if (resultArray.length === 0) {
             return null;
         }
@@ -114,9 +118,11 @@ function queryRootElement (pContextName, pID, pGetFirst) {
         }
         return augmentData(resultArray, "Task");
     } else if (pContextName === "Activity") {
-        resultArray = db.array(db.ROW, SqlCondition.begin()
-            .andPrepare("ACTIVITY.ACTIVITYID", pID)
-            .buildSql("select ACTIVITYID, PARENT_ID, PARENT_CONTEXT, SUBJECT, INFO from ACTIVITY"));
+        resultArray = newSelect("ACTIVITYID, PARENT_ID, PARENT_CONTEXT, SUBJECT, INFO")
+                        .from("ACTIVITY")
+                        .where("ACTIVITY.ACTIVITYID", pID)
+                        .arrayRow();
+            
         if (resultArray.length === 0) {
             return null;
         }
@@ -130,9 +136,12 @@ function queryRootElement (pContextName, pID, pGetFirst) {
         return augmentData(resultArray, "Activity");
     }
     else if (pContextName === "SupportTicket") {
-        resultArray = db.array(db.ROW, SqlCondition.begin()
-            .andPrepare("TICKET.TICKETID", pID)
-            .buildSql("select TICKETID, PARENT_ID, PARENT_CONTEXT, SUBJECT, DESCRIPTION from TICKET left join TASK on TASK_ID = TASKID"));
+        resultArray = newSelect("TICKETID, PARENT_ID, PARENT_CONTEXT, SUBJECT, DESCRIPTION")
+                        .from("TICKET")
+                        .leftJoin("TASK", "TASK_ID = TASKID")
+                        .where("TICKET.TICKETID", pID)
+                        .arrayRow();
+                        
         if (resultArray.length === 0) {
             return null;
         }
diff --git a/entity/ObjectRelationType_entity/ObjectRelationType_entity.aod b/entity/ObjectRelationType_entity/ObjectRelationType_entity.aod
index 6a063fff6d8fbac0eac4b1b9f3ab4191700793b1..fb534bb2230cbabc8c0b07a686721ce633bddd47 100644
--- a/entity/ObjectRelationType_entity/ObjectRelationType_entity.aod
+++ b/entity/ObjectRelationType_entity/ObjectRelationType_entity.aod
@@ -114,6 +114,7 @@
       <title>Enable relation type 2</title>
       <contentType>BOOLEAN</contentType>
       <dropDownProcess>%aditoprj%/entity/ObjectRelationType_entity/entityfields/type2enabled_proxy/dropDownProcess.js</dropDownProcess>
+      <stateProcess>%aditoprj%/entity/ObjectRelationType_entity/entityfields/type2enabled_proxy/stateProcess.js</stateProcess>
       <valueProcess>%aditoprj%/entity/ObjectRelationType_entity/entityfields/type2enabled_proxy/valueProcess.js</valueProcess>
     </entityField>
     <entityField>
diff --git a/entity/ObjectRelationType_entity/entityfields/removeactiongroup/children/removeusage/onActionProcess.js b/entity/ObjectRelationType_entity/entityfields/removeactiongroup/children/removeusage/onActionProcess.js
index 7de1f5f6cb2dc53d15d82fdf758c2dd93880f2a6..95f3d3d8c2eb9ce2a53f90ef533c0c24aa8cd1c2 100644
--- a/entity/ObjectRelationType_entity/entityfields/removeactiongroup/children/removeusage/onActionProcess.js
+++ b/entity/ObjectRelationType_entity/entityfields/removeactiongroup/children/removeusage/onActionProcess.js
@@ -6,9 +6,10 @@ import("Sql_lib");
 
 if (vars.get("$field.UID") && vars.get("$field.DEST_OBJECTRELATIONTYPEID"))
 {
-    db.deleteData("AB_OBJECTRELATION", SqlCondition.begin()
-                                   .andPrepareVars("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", "$field.UID")
-                                   .andPrepareVars("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", "$field.DEST_OBJECTRELATIONTYPEID").build("1=2"));
+    newWhere("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", "$field.UID")
+        .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", "$field.DEST_OBJECTRELATIONTYPEID")
+        .deleteData(true, "AB_OBJECTRELATION");
+    
     question.showMessage(translate.withArguments("Deleted all usages of \"%0\".", [translate.text(vars.get("$field.SOURCE_RELATION_TITLE")) + " -> " + translate.text(vars.get("$field.DEST_RELATION_TITLE"))]), question.INFORMATION, translate.text("Successful"))
 }
 
diff --git a/entity/ObjectRelationType_entity/entityfields/type2enabled_proxy/stateProcess.js b/entity/ObjectRelationType_entity/entityfields/type2enabled_proxy/stateProcess.js
new file mode 100644
index 0000000000000000000000000000000000000000..6433e03a88183a5ff939685851cbf58ca0009af4
--- /dev/null
+++ b/entity/ObjectRelationType_entity/entityfields/type2enabled_proxy/stateProcess.js
@@ -0,0 +1,12 @@
+import("system.vars");
+import("system.result");
+import("system.neon");
+
+if (vars.getString("$param.UsageCount_param") > 0)
+{
+    result.string(neon.COMPONENTSTATE_DISABLED);
+}
+else
+{
+    result.string(neon.COMPONENTSTATE_EDITABLE);
+}
\ No newline at end of file
diff --git a/entity/ObjectRelationType_entity/entityfields/usagecount_param/valueProcess.js b/entity/ObjectRelationType_entity/entityfields/usagecount_param/valueProcess.js
index 2ea7aca8980ad01e9086033002dbfb72989c1021..6887bcbe34106a82d60b2d9be6c4144b8afc7a26 100644
--- a/entity/ObjectRelationType_entity/entityfields/usagecount_param/valueProcess.js
+++ b/entity/ObjectRelationType_entity/entityfields/usagecount_param/valueProcess.js
@@ -1,8 +1,11 @@
+import("system.vars");
+import("system.logging");
 import("Sql_lib");
 import("system.db");
 import("system.result");
 
-result.object(db.cell(SqlCondition.begin()
-                                   .andPrepareVars("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", "$field.UID")
-                                   .andPrepareVars("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", "$field.DEST_OBJECTRELATIONTYPEID")
-                                   .buildSql("select count(*) from AB_OBJECTRELATION", "1=2")));
\ No newline at end of file
+result.object(newSelect("count(*)")
+                .from("AB_OBJECTRELATION")
+                .whereIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", "$field.UID")
+                .andIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", "$field.DEST_OBJECTRELATIONTYPEID")
+                .cell(true, "0"));
\ No newline at end of file
diff --git a/entity/ObjectRelationType_entity/recordcontainers/jdito/onDelete.js b/entity/ObjectRelationType_entity/recordcontainers/jdito/onDelete.js
index 19d5361663e81d977195b858044c1116cb3ae6b7..1a417b248a4d5d42e6ddd34986aefc7f1b768a94 100644
--- a/entity/ObjectRelationType_entity/recordcontainers/jdito/onDelete.js
+++ b/entity/ObjectRelationType_entity/recordcontainers/jdito/onDelete.js
@@ -4,16 +4,12 @@ import("system.translate");
 import("system.question");
 import("Sql_lib");
 
-var usageCount = db.cell(SqlCondition.begin()
-                                   .andPrepareVars("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", "$field.UID")
-                                   .andPrepareVars("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", "$field.DEST_OBJECTRELATIONTYPEID")
-                                   .buildSql("select count(*) from AB_OBJECTRELATION", "1=2"))
+var usageCount = vars.get("$param.UsageCount_param");
 
 if (usageCount <= 0)
 {
-    db.deleteData("AB_OBJECTRELATIONTYPE", SqlCondition.begin()
-                                   .andPrepareVars("AB_OBJECTRELATIONTYPE.RELATION_TYPE", "$field.RELATION_TYPE")
-                                   .build("1=2"));
+    newWhere("AB_OBJECTRELATIONTYPE.RELATION_TYPE", "$field.RELATION_TYPE")
+        .deleteData(true, "AB_OBJECTRELATIONTYPE");
 }
 else
 {
diff --git a/entity/ObjectRelationType_entity/recordcontainers/jdito/onUpdate.js b/entity/ObjectRelationType_entity/recordcontainers/jdito/onUpdate.js
index 7525fe76f2df12e405ead17d477fdfce4b3062cc..2ebed773878043f569a51a931d613bea57708b0a 100644
--- a/entity/ObjectRelationType_entity/recordcontainers/jdito/onUpdate.js
+++ b/entity/ObjectRelationType_entity/recordcontainers/jdito/onUpdate.js
@@ -4,94 +4,83 @@ import("Sql_lib");
 import("system.db");
 import("system.vars");
 
-var usageCount = db.cell(SqlCondition.begin()
-                                   .andPrepareVars("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", "$field.UID")
-                                   .andPrepareVars("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", "$field.DEST_OBJECTRELATIONTYPEID")
-                                   .buildSql("select count(*) from AB_OBJECTRELATION", "1=2"))
+var type1Fields = {};
+var type2Fields = {};
 
-if (usageCount <= 0)
+vars.get("local.changed").forEach(function(pChange)
 {
-    var type1Fields = {};
-    var type2Fields = {};
+    var fieldName = pChange.split(".")[0];
 
-    vars.get("local.changed").forEach(function(pChange)
+    switch (pChange.split("_")[0])
     {
-        var fieldName = pChange.split(".")[0];
+        case "SOURCE":
+            type1Fields[fieldName.replace("SOURCE_", "")] = vars.get("$field." + fieldName);
+            break;
+        case "DEST":
+            type2Fields[fieldName.replace("DEST_", "")] = vars.get("$field." + fieldName);
+            break;
+        case "Type2Enabled":
+            break;
+        case "ICON":
+            type1Fields[fieldName] = vars.get("$field." + fieldName);
+        default:
+            type1Fields[fieldName] = vars.get("$field." + fieldName);
+            type2Fields[fieldName] = vars.get("$field." + fieldName);
+    }
+});
 
-        switch (pChange.split("_")[0])
-        {
-            case "SOURCE":
-                type1Fields[fieldName.replace("SOURCE_", "")] = vars.get("$field." + fieldName);
-                break;
-            case "DEST":
-                type2Fields[fieldName.replace("DEST_", "")] = vars.get("$field." + fieldName);
-                break;
-            case "Type2Enabled":
-                break;
-            case "ICON":
-                type1Fields[fieldName] = vars.get("$field." + fieldName);
-            default:
-                type1Fields[fieldName] = vars.get("$field." + fieldName);
-                type2Fields[fieldName] = vars.get("$field." + fieldName);
-        }
-    });
+var updates = [];
+var type1Cond = newWhere("AB_OBJECTRELATIONTYPE.RELATION_TYPE", vars.get("$field.RELATION_TYPE"))
+                    .and("AB_OBJECTRELATIONTYPE.SIDE", "1")
+                    .build();
+                    
+var type2Cond = newWhere("AB_OBJECTRELATIONTYPE.RELATION_TYPE", vars.get("$field.RELATION_TYPE"))
+                    .and("AB_OBJECTRELATIONTYPE.SIDE", "2")
+                    .build();
 
-    var updates = [];
-    var type1Cond = SqlCondition.begin().andPrepare("AB_OBJECTRELATIONTYPE.RELATION_TYPE", vars.get("$field.RELATION_TYPE"))
-                                        .andPrepare("AB_OBJECTRELATIONTYPE.SIDE", "1").build("1=2");
-    var type2Cond = SqlCondition.begin().andPrepare("AB_OBJECTRELATIONTYPE.RELATION_TYPE", vars.get("$field.RELATION_TYPE"))
-                                        .andPrepare("AB_OBJECTRELATIONTYPE.SIDE", "2").build("1=2");
+for (let field in type1Fields) {
+    updates.push(["AB_OBJECTRELATIONTYPE", [field], null, [type1Fields[field]], type1Cond]);
+}
 
-    for (let field in type1Fields) {
-        updates.push(["AB_OBJECTRELATIONTYPE", [field], null, [type1Fields[field]], type1Cond]);
-    }
+var type2Enabled = vars.getString("$field.Type2Enabled_proxy");
 
-    var type2Enabled = vars.getString("$field.Type2Enabled_proxy");
-    
-    // delete, if type2  is empty -> convert it to a "same"-type
-    if (type2Enabled == "0" || ((vars.get("$field.SOURCE_RELATION_TITLE") == vars.get("$field.DEST_RELATION_TITLE") && vars.get("$field.SOURCE_OBJECT_TYPE") == vars.get("$field.DEST_OBJECT_TYPE"))
-        || !vars.get("$field.DEST_OBJECT_TYPE") && !vars.get("$field.DEST_RELATION_TITLE")))
-    {
-        db.deleteData("AB_OBJECTRELATIONTYPE", type2Cond);
+// delete, if type2  is empty -> convert it to a "same"-type
+if (type2Enabled == "0" || ((vars.get("$field.SOURCE_RELATION_TITLE") == vars.get("$field.DEST_RELATION_TITLE") && vars.get("$field.SOURCE_OBJECT_TYPE") == vars.get("$field.DEST_OBJECT_TYPE"))
+    || !vars.get("$field.DEST_OBJECT_TYPE") && !vars.get("$field.DEST_RELATION_TITLE")))
+{
+    db.deleteData("AB_OBJECTRELATIONTYPE", type2Cond);
+}
+else
+{   // update if already existing
+    if (vars.get("$field.DIRECTION") != "same")
+    {    
+        for (let field in type2Fields) {
+            updates.push(["AB_OBJECTRELATIONTYPE", [field], null, [type2Fields[field]], type2Cond]);
+        }
     }
     else
-    {   // update if already existing
-        if (vars.get("$field.DIRECTION") != "same")
-        {    
-            for (let field in type2Fields) {
-                updates.push(["AB_OBJECTRELATIONTYPE", [field], null, [type2Fields[field]], type2Cond]);
-            }
-        }
-        else
-        {   // insert if it was "same" before
-            if ((vars.get("$field.SOURCE_RELATION_TITLE") != vars.get("$field.DEST_RELATION_TITLE") || vars.get("$field.SOURCE_OBJECT_TYPE") != vars.get("$field.DEST_OBJECT_TYPE"))
-            && vars.get("$field.DEST_OBJECT_TYPE") && vars.get("$field.DEST_RELATION_TITLE"))
-            {
-                db.insertData("AB_OBJECTRELATIONTYPE", [
-                    "AB_OBJECTRELATIONTYPEID",
-                    "OBJECT_TYPE",
-                    "RELATION_TITLE",
-                    "RELATION_TYPE",
-                    "SIDE",
-                    "HIERARCHY"
-                ], null, [
-                    util.getNewUUID(),
-                    vars.get("$field.DEST_OBJECT_TYPE"),
-                    vars.get("$field.DEST_RELATION_TITLE"),
-                    vars.get("$field.RELATION_TYPE"),
-                    2,
-                    vars.get("$field.HIERARCHY")
-                ]);
+    {   // insert if it was "same" before
+        if ((vars.get("$field.SOURCE_RELATION_TITLE") != vars.get("$field.DEST_RELATION_TITLE") || vars.get("$field.SOURCE_OBJECT_TYPE") != vars.get("$field.DEST_OBJECT_TYPE"))
+        && vars.get("$field.DEST_OBJECT_TYPE") && vars.get("$field.DEST_RELATION_TITLE"))
+        {
+            db.insertData("AB_OBJECTRELATIONTYPE", [
+                "AB_OBJECTRELATIONTYPEID",
+                "OBJECT_TYPE",
+                "RELATION_TITLE",
+                "RELATION_TYPE",
+                "SIDE",
+                "HIERARCHY"
+            ], null, [
+                util.getNewUUID(),
+                vars.get("$field.DEST_OBJECT_TYPE"),
+                vars.get("$field.DEST_RELATION_TITLE"),
+                vars.get("$field.RELATION_TYPE"),
+                2,
+                vars.get("$field.HIERARCHY")
+            ]);
 
-            }
         }
     }
-
-    db.updates(updates);
-}
-else
-{
-    // TODO: Show message hier nicht möglich: mit Grant-Prozess ausführung komplett verhindern, wenn es diese gibt.
-    //question.showMessage(translate.withArguments("There are still %0 relations using the type %1.", [usageCount, translate.text(vars.get("$field.SOURCE_RELATION_TITLE")) + " -> " + translate.text(vars.get("$field.DEST_RELATION_TITLE"))]), question.WARNING, translate.text("Cannot remove relation type"))
 }
 
+db.updates(updates);
diff --git a/entity/ObjectTree_entity/entityfields/objects/children/excludedobjectids_param/valueProcess.js b/entity/ObjectTree_entity/entityfields/objects/children/excludedobjectids_param/valueProcess.js
index afff3a5327c89048c9bd7c6cc0d85adf78fabeaf..e5bc0159b087de4ec4e2bde77c047cad1a94f5e1 100644
--- a/entity/ObjectTree_entity/entityfields/objects/children/excludedobjectids_param/valueProcess.js
+++ b/entity/ObjectTree_entity/entityfields/objects/children/excludedobjectids_param/valueProcess.js
@@ -1,3 +1,4 @@
+import("system.logging");
 import("Sql_lib");
 import("system.vars");
 import("system.result");
@@ -6,16 +7,16 @@ import("ObjectRelation_lib");
 
 var relationTypeData = ObjectRelationUtils.getRelationType(vars.get("$field.OBJECTRELATIONTYPEID"));
 
-var sql1 = SqlUtils.translateStatementWithQuotes(SqlCondition.begin()
-                       .andPrepareVars("AB_OBJECTRELATION.OBJECT1_ROWID", "$field.PARENT_ID")
-                       .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", relationTypeData[7])
-                       .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", relationTypeData[8])
-                       .buildSql("select OBJECT2_ROWID from AB_OBJECTRELATION", "1=2"));
-
-var sql2 = SqlUtils.translateStatementWithQuotes(SqlCondition.begin()
-                       .andPrepareVars("AB_OBJECTRELATION.OBJECT2_ROWID", "$field.PARENT_ID")
-                       .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", relationTypeData[7])
-                       .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", relationTypeData[8])
-                       .buildSql("select OBJECT1_ROWID from AB_OBJECTRELATION", "1=2"));
-
-result.object([vars.get("$field.PARENT_ID")].concat(db.array(db.COLUMN, sql1 + " union " + sql2)));
\ No newline at end of file
+var ids = newSelect("OBJECT2_ROWID")
+                .from("AB_OBJECTRELATION")
+                .whereIfSet("AB_OBJECTRELATION.OBJECT1_ROWID", "$field.PARENT_ID")
+                .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", relationTypeData[7])
+                .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", relationTypeData[8])
+            .union(newSelect("OBJECT1_ROWID")
+                .from("AB_OBJECTRELATION")
+                .whereIfSet("AB_OBJECTRELATION.OBJECT2_ROWID", "$field.PARENT_ID")
+                .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", relationTypeData[7])
+                .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", relationTypeData[8]))
+            .arrayColumn();
+            
+result.object([vars.get("$field.PARENT_ID")].concat(ids));
\ No newline at end of file
diff --git a/entity/ObjectTree_entity/entityfields/parent_id/valueProcess.js b/entity/ObjectTree_entity/entityfields/parent_id/valueProcess.js
index 68a909f59961600aa80c9dcac348113b226437c3..c4e122e500a5cc7dcf9d1c068c63094014ba0fed 100644
--- a/entity/ObjectTree_entity/entityfields/parent_id/valueProcess.js
+++ b/entity/ObjectTree_entity/entityfields/parent_id/valueProcess.js
@@ -13,7 +13,7 @@ if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.exists("$par
     var targetId = "";
 
     if (myContextTypes && myObjectIds)
-    {
+    {        
         var index = myContextTypes.indexOf(targetContext);
         targetId = myObjectIds[index];
     }
diff --git a/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js b/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js
index 19ada032877628d8aab5aed38edb2e0008854eea..f916905b885a498d2592a097cde3150915baf47f 100644
--- a/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js
@@ -1,3 +1,4 @@
+import("system.logging");
 import("system.db");
 import("system.translate");
 import("system.result");
@@ -276,10 +277,10 @@ function _getEntryData(pObjectId, pDirection, pRelationType1, pRelationType2, pP
 {
     if (pRelationType1 == undefined || pRelationType2 == undefined) 
         return [];
- 
+    
     var myNum;
     var otherNum;
-        
+    
     if (pDirection == "normal") 
     {
         otherNum = 1;
@@ -291,27 +292,30 @@ function _getEntryData(pObjectId, pDirection, pRelationType1, pRelationType2, pP
         myNum = 1;
     }
         
-    var cond = SqlCondition.begin()
-                           .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", pRelationType1)
-                           .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", pRelationType2)
-                           .andPrepare("AB_OBJECTRELATION.OBJECT" + myNum + "_ROWID", pObjectId)
-                           .andPrepareIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", pObjectRelationId);
+    onConditionForRelationTypeJoin = newWhere("AB_OBJECTRELATIONTYPEID = AB_OBJECTRELATIONTYPE" + myNum)
+                                        .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", pRelationType1)
+                                        .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", pRelationType2)
+                                        .and("AB_OBJECTRELATION.OBJECT" + myNum + "_ROWID", pObjectId)
+                                                                                         // set id to null, as only null works with .andIfSet
+                                        .andIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", (pObjectRelationId ? pObjectRelationId : null));
     
     // exclude previous node
     if (!pPrevId)
-        cond.and("AB_OBJECTRELATION.OBJECT" + otherNum + "_ROWID is not null");
+        onConditionForRelationTypeJoin.and("AB_OBJECTRELATION.OBJECT" + otherNum + "_ROWID is not null");
     else
     {
-        cond.andPrepare("AB_OBJECTRELATION.OBJECT" + otherNum + "_ROWID", pPrevId, "# <> ?");
+        onConditionForRelationTypeJoin.and("AB_OBJECTRELATION.OBJECT" + otherNum + "_ROWID", pPrevId, "# <> ?");
     }
-        
+    
     // TODO: BINDATA?
     // var image = getImageObject("Beziehung");
-    var data = db.table(cond.buildSql(
-                "select OBJECT" + (pObjectRelationId ? myNum : otherNum) + "_ROWID, AB_OBJECTRELATIONID, OBJECT_TYPE, RELATION_TITLE, INFO, AB_OBJECTRELATIONTYPEID \n\
-                 from AB_OBJECTRELATION \n\
-                 join AB_OBJECTRELATIONTYPE on AB_OBJECTRELATIONTYPEID = AB_OBJECTRELATIONTYPE" + myNum + " and ","1=2", "", false));
-    
+    var data = newSelect("OBJECT" + (pObjectRelationId ? myNum : otherNum) + "_ROWID, AB_OBJECTRELATIONID, OBJECT_TYPE, RELATION_TITLE, INFO, AB_OBJECTRELATIONTYPEID")
+                        .from("AB_OBJECTRELATION")
+                        .join("AB_OBJECTRELATIONTYPE", onConditionForRelationTypeJoin)
+                        .table();
+                        
+   
+                        
     // try again with other side for "same"
     if (data.length == 0 && pDirection == "same" && !pNoRecursion || pObjectRelationId && data.length > 0 && !data[0][ENTRY_DATA.objectId])
     {
@@ -379,13 +383,14 @@ function _getRootID(pObjectId, pObjectRelationTypeData)
     {
         var rootid = sourceid;
         max--;
-        sourceid = db.cell(SqlCondition.begin()
-                                       .andPrepare("AB_OBJECTRELATION.OBJECT2_ROWID", sourceid)
-                                       .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", pObjectRelationTypeData[7])
-                                       .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", pObjectRelationTypeData[8])
-                                       .buildSql("select OBJECT1_ROWID from AB_OBJECTRELATION", "1=2"))
+        sourceid = newSelect("OBJECT1_ROWID")
+                    .from("AB_OBJECTRELATION")
+                    .where("AB_OBJECTRELATION.OBJECT2_ROWID", sourceid)
+                    .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", pObjectRelationTypeData[7])
+                    .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", pObjectRelationTypeData[8])
+                    .cell()
     }
-    while( sourceid != "" && max > 0 );
+    while(sourceid != "" && max > 0);
     return rootid; 
     return currentObjectId;
 }
\ No newline at end of file
diff --git a/entity/ObjectTree_entity/recordcontainers/jdito/onDelete.js b/entity/ObjectTree_entity/recordcontainers/jdito/onDelete.js
index fc1ca5187e5c95cc58f0d5171cb175c8e5150553..0271d85e784f61d3e758070728e0c05d169d2ca5 100644
--- a/entity/ObjectTree_entity/recordcontainers/jdito/onDelete.js
+++ b/entity/ObjectTree_entity/recordcontainers/jdito/onDelete.js
@@ -10,9 +10,8 @@ var isObjectRelationNode = typeof uid[2] == "string";
 if (isObjectRelationNode)
 {
     var objectRelationId = uid[6];
-    db.deleteData("AB_OBJECTRELATION", SqlCondition.begin()
-                                       .andPrepareIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", objectRelationId)
-                                       .build("1=2"));
+    newWhereIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", objectRelationId)
+        .deleteData(true, "AB_OBJECTRELATION");
 
     // Refresh otherwise the children of the deleted node would be moved to the root.
     neon.refresh();
diff --git a/entity/ObjectTree_entity/recordcontainers/jdito/onInsert.js b/entity/ObjectTree_entity/recordcontainers/jdito/onInsert.js
index 41e58e2067905eb172c7c00cd3002333a86fc069..5f2bbf6be771e7da12f73de9d60164445883a491 100644
--- a/entity/ObjectTree_entity/recordcontainers/jdito/onInsert.js
+++ b/entity/ObjectTree_entity/recordcontainers/jdito/onInsert.js
@@ -9,7 +9,7 @@ if (selectedObjectRelationTypeId)
 {
     relationTypeData = ObjectRelationUtils.getRelationType(selectedObjectRelationTypeId)
     if (relationTypeData[0]) 
-    {       
+    {
         var relationType1 = relationTypeData[7];
         var relationType2 = relationTypeData[8];
         var objectType1 = relationTypeData[5];
@@ -29,7 +29,7 @@ if (selectedObjectRelationTypeId)
             objectId1 = vars.get("$field.PARENT_ID");
             objectId2 = vars.get("$field.TARGET_ID");
         }
-        
+
         db.insertData("AB_OBJECTRELATION", [
             "AB_OBJECTRELATIONID",
             "OBJECT1_ROWID",
diff --git a/entity/ObjectTree_entity/recordcontainers/jdito/onUpdate.js b/entity/ObjectTree_entity/recordcontainers/jdito/onUpdate.js
index c62d01d48d36ea557c12c999c9051803d617db39..9356ec327a0c6bd2f8f533c5b6f73da3ca3c6a4f 100644
--- a/entity/ObjectTree_entity/recordcontainers/jdito/onUpdate.js
+++ b/entity/ObjectTree_entity/recordcontainers/jdito/onUpdate.js
@@ -11,8 +11,6 @@ if (isObjectRelationNode)
 {
     var objectRelationId = uid[6];
    
-    db.updateData("AB_OBJECTRELATION", ["INFO"], null, [vars.get("$field.INFO")], 
-                    SqlCondition.begin()
-                                .andPrepareIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", objectRelationId)
-                                .build("1=2"));
+    newWhereIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", objectRelationId)
+        .updateData(true, ["INFO"], null, [vars.get("$field.INFO")], "AB_OBJECTRELATION");
 }
diff --git a/entity/Offer_entity/conditionProcess.js b/entity/Offer_entity/conditionProcess.js
index 06d75b37a1d983946fb35c719230574cfc0a7a1e..1fb5c50e9a6eacdb22c14b5d5f1be4a70f87e686 100644
--- a/entity/Offer_entity/conditionProcess.js
+++ b/entity/Offer_entity/conditionProcess.js
@@ -2,8 +2,7 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = new SqlCondition();
-cond.andPrepareVars("OFFER.OBJECT_ROWID", "$param.ObjectRowId_param");
+var cond = newWhereIfSet("OFFER.OBJECT_ROWID", "$param.ObjectRowId_param");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/Offer_entity/entityfields/contact_id/onValueChange.js b/entity/Offer_entity/entityfields/contact_id/onValueChange.js
index 15006677e0cc2ec6dd0ffd120b1b14916637ec69..4d3ecbb18ee4bdbd45431fe3ea9b563c29dab08c 100644
--- a/entity/Offer_entity/entityfields/contact_id/onValueChange.js
+++ b/entity/Offer_entity/entityfields/contact_id/onValueChange.js
@@ -10,9 +10,10 @@ var contactid = vars.get("local.value");
 if(contactid != "")
 {
     //Language Preset
-    var lang = db.cell(SqlCondition.begin()
-        .andPrepare("CONTACT.CONTACTID", contactid)
-        .buildSql("select ISOLANGUAGE from CONTACT"));
+    var lang = newSelect("ISOLANGUAGE")
+                    .from("CONTACT")
+                    .where("CONTACT.CONTACTID", contactid)
+                    .cell();
     if(lang != "") 
         neon.setFieldValue("field.ISOLANGUAGE", lang);
     
diff --git a/entity/Offer_entity/entityfields/contact_id/valueProcess.js b/entity/Offer_entity/entityfields/contact_id/valueProcess.js
index de0433be9112a5780ed0971d1252f0b312b26a75..c50907d05b5a89d6a44af670474fff35f2f6c74d 100644
--- a/entity/Offer_entity/entityfields/contact_id/valueProcess.js
+++ b/entity/Offer_entity/entityfields/contact_id/valueProcess.js
@@ -20,9 +20,10 @@ if ((!vars.exists("$param.ContactId_param") || !vars.get("$param.ContactId_param
 
 if (contactId) 
 {
-    var lang = db.cell(SqlCondition.begin()
-        .andPrepare("CONTACT.CONTACTID", contactId)
-        .buildSql("select ISOLANGUAGE from CONTACT"));
+    var lang = newSelect("ISOLANGUAGE")
+                    .from("CONTACT")
+                    .where("CONTACT.CONTACTID", contactId)
+                    .cell();
 
     if(lang != "") 
         neon.setFieldValue("field.ISOLANGUAGE", lang);
diff --git a/entity/Offer_entity/entityfields/footer/valueProcess.js b/entity/Offer_entity/entityfields/footer/valueProcess.js
index 15f63197dcbb880641f74070d9bdbbd5bcd96d5d..c7d13ea380301efeadd70a5293ed03c5a06ff4bf 100644
--- a/entity/Offer_entity/entityfields/footer/valueProcess.js
+++ b/entity/Offer_entity/entityfields/footer/valueProcess.js
@@ -16,8 +16,10 @@ else if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
 
 if (vars.get("$field.ChoosenTEXFooter") != "")
 {
-    var binaryId = db.cell(SqlCondition.begin()
-        .andPrepareVars("ASYS_BINARIES.ROW_ID", "$field.ChoosenTEXFooter")
-        .buildSql("select ID from ASYS_BINARIES"), SqlUtils.getBinariesAlias());
-    result.string(util.decodeBase64String(db.getBinaryContent(binaryId, SqlUtils.getBinariesAlias())));
+    var binaryId = newSelect("ID", SqlUtils.getBinariesAlias())
+                        .from("ASYS_BINARIES")
+                        .whereIfSet("ASYS_BINARIES.ROW_ID", "$field.ChoosenTEXFooter")
+                        .cell(true);
+    if (binaryId)
+        result.string(util.decodeBase64String(db.getBinaryContent(binaryId, SqlUtils.getBinariesAlias())));
 }
\ No newline at end of file
diff --git a/entity/Offer_entity/entityfields/header/valueProcess.js b/entity/Offer_entity/entityfields/header/valueProcess.js
index a06ff095b12adab740f92f0fd31539ebc47e1a98..65ab407aa9ddd39cea13f8b8fd2ee835fa27e42a 100644
--- a/entity/Offer_entity/entityfields/header/valueProcess.js
+++ b/entity/Offer_entity/entityfields/header/valueProcess.js
@@ -16,8 +16,11 @@ else if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
 
 if (vars.get("$field.ChoosenTEXHeader") != "")
 {
-    var binaryId = db.cell(SqlCondition.begin()
-        .andPrepareVars("ASYS_BINARIES.ROW_ID", "$field.ChoosenTEXHeader")
-        .buildSql("select ID from ASYS_BINARIES"), SqlUtils.getBinariesAlias());
-    result.string(util.decodeBase64String(db.getBinaryContent(binaryId, SqlUtils.getBinariesAlias())));
+    var binaryId = newSelect("ID", SqlUtils.getBinariesAlias())
+                        .from("ASYS_BINARIES")
+                        .whereIfSet("ASYS_BINARIES.ROW_ID", "$field.ChoosenTEXHeader")
+                        .cell(true);
+                        
+    if (binaryId)
+        result.string(util.decodeBase64String(db.getBinaryContent(binaryId, SqlUtils.getBinariesAlias())));
 }
\ No newline at end of file
diff --git a/entity/Offer_entity/entityfields/isolanguage/displayValueProcess.js b/entity/Offer_entity/entityfields/isolanguage/displayValueProcess.js
index 0a2a0ee65d4db10c8e023e7e2849fbde9b6de533..bb31cb49def7b5b799a4861f325a76d4430ad3ef 100644
--- a/entity/Offer_entity/entityfields/isolanguage/displayValueProcess.js
+++ b/entity/Offer_entity/entityfields/isolanguage/displayValueProcess.js
@@ -4,9 +4,9 @@ import("system.result");
 import("system.vars");
 import("Sql_lib");
 
-var iso3 = vars.get("$field.ISOLANGUAGE");
-var latinName = db.cell(SqlCondition.begin()
-    .andPrepare("AB_LANGUAGE.ISO3", iso3)
-    .buildSql("select NAME_LATIN from AB_LANGUAGE", "1=0"));
-latinName = translate.text(latinName);
-result.string(latinName);
+var latinName = newSelect("NAME_LATIN")
+                    .from("AB_LANGUAGE")
+                    .where("AB_LANGUAGE.ISO3", "$field.ISOLANGUAGE")
+                    .cell();
+
+result.string(translate.text(latinName));
diff --git a/entity/Offer_entity/entityfields/printoffer/stateProcess.js b/entity/Offer_entity/entityfields/printoffer/stateProcess.js
index bb8a76fc6373e23f7ea9e562c2bcedad4c6b5bdb..bf47a920e1a8bc096cac555807bb97ed64aaaaf2 100644
--- a/entity/Offer_entity/entityfields/printoffer/stateProcess.js
+++ b/entity/Offer_entity/entityfields/printoffer/stateProcess.js
@@ -3,9 +3,10 @@ import("system.db");
 import("Sql_lib");
 import("system.neon");
 
-var itemcount = db.cell(SqlCondition.begin()
-                    .andPrepareVars("OFFERITEM.OFFER_ID", "$field.OFFERID")
-                    .buildSql("select count(*) from OFFERITEM", "1=2"));
+var itemcount = newSelect("count(*)")
+                    .from("OFFERITEM")
+                    .whereIfSet("OFFERITEM.OFFER_ID", "$field.OFFERID")
+                    .cell(true, "0");
                                        
 if(itemcount == "0")
     result.string(neon.COMPONENTSTATE_DISABLED);
diff --git a/entity/Offer_entity/onDBDelete.js b/entity/Offer_entity/onDBDelete.js
index 5c36082b9691235f56ae00de76af5eca4d528c14..066cc33ad00409ba655054ad2bfe48743f2d26ad 100644
--- a/entity/Offer_entity/onDBDelete.js
+++ b/entity/Offer_entity/onDBDelete.js
@@ -2,4 +2,5 @@ import("Sql_lib");
 import("system.vars");
 import("system.db");
 
-db.deleteData("OFFERITEM", SqlCondition.equals("OFFERITEM.OFFER_ID", vars.getString("$field.OFFERID"), "1=2"));
\ No newline at end of file
+newWhere("OFFERITEM.OFFER_ID", "$field.OFFERID")
+    .deleteData(true, "OFFERITEM");
\ No newline at end of file
diff --git a/entity/Offer_entity/recordcontainers/db/conditionProcess.js b/entity/Offer_entity/recordcontainers/db/conditionProcess.js
index e9466d0d8aa725a4b86afd5ed52df4c87b061179..001612ec1946c47b24fee4e07a2273b60586162e 100644
--- a/entity/Offer_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Offer_entity/recordcontainers/db/conditionProcess.js
@@ -3,16 +3,16 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = new SqlCondition();
+var cond = newWhere()
 
 if(vars.exists("$param.ContactId_param") && vars.get("$param.ContactId_param"))
-    cond.andPrepareVars("OFFER.CONTACT_ID", "$param.ContactId_param");
+    cond.andIfSet("OFFER.CONTACT_ID", "$param.ContactId_param");
 else {
-    cond.andPrepareVars("OFFER.OBJECT_ROWID", "$param.ObjectRowId_param");
-    cond.andPrepareVars("OFFER.OBJECT_TYPE", "$param.ObjectType_param");
+    cond.andIfSet("OFFER.OBJECT_ROWID", "$param.ObjectRowId_param");
+    cond.andIfSet("OFFER.OBJECT_TYPE", "$param.ObjectType_param");
 }
 
-cond.andPrepareVars("OFFER.STATUS", "$param.OfferStatus_param")
+cond.andIfSet("OFFER.STATUS", "$param.OfferStatus_param")
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/Offer_entity/recordcontainers/db/onDBDelete.js b/entity/Offer_entity/recordcontainers/db/onDBDelete.js
index 5c36082b9691235f56ae00de76af5eca4d528c14..066cc33ad00409ba655054ad2bfe48743f2d26ad 100644
--- a/entity/Offer_entity/recordcontainers/db/onDBDelete.js
+++ b/entity/Offer_entity/recordcontainers/db/onDBDelete.js
@@ -2,4 +2,5 @@ import("Sql_lib");
 import("system.vars");
 import("system.db");
 
-db.deleteData("OFFERITEM", SqlCondition.equals("OFFERITEM.OFFER_ID", vars.getString("$field.OFFERID"), "1=2"));
\ No newline at end of file
+newWhere("OFFERITEM.OFFER_ID", "$field.OFFERID")
+    .deleteData(true, "OFFERITEM");
\ No newline at end of file
diff --git a/entity/Offeritem_entity/entityfields/price/displayValueProcess.js b/entity/Offeritem_entity/entityfields/price/displayValueProcess.js
index 7937b0dc6cf9ab0750c43be49a0accec6fb27e56..e637f9b6adf09bb49a711742f90d24389c9bddfe 100644
--- a/entity/Offeritem_entity/entityfields/price/displayValueProcess.js
+++ b/entity/Offeritem_entity/entityfields/price/displayValueProcess.js
@@ -13,9 +13,10 @@ var curr = vars.get("$param.Currency_param")
 }
 
 else {
-     curr = db.cell(SqlCondition.begin()
-                    .andPrepareVars("OFFER.OFFERID", "$field.OFFER_ID")
-                    .buildSql("select CURRENCY from OFFER", "1=2"));
+     curr = newSelect("CURRENCY")
+                .from("OFFER")
+                .whereIfSet("OFFER.OFFERID", "$field.OFFER_ID")
+                .cell(true);
 }
 
 result.string(NumberUtils.formatWithCurrency(vars.get("$field.PRICE"), translate.text("#,##0.00"), curr));
\ No newline at end of file
diff --git a/entity/Offeritem_entity/entityfields/product_id/onValueChange.js b/entity/Offeritem_entity/entityfields/product_id/onValueChange.js
index 5870914adc13d6d7af1b645a873b5c9c76e89fb9..3bad73db28fa32f6f74a7faca5e8767c1e54dc3b 100644
--- a/entity/Offeritem_entity/entityfields/product_id/onValueChange.js
+++ b/entity/Offeritem_entity/entityfields/product_id/onValueChange.js
@@ -19,11 +19,12 @@ if(pid != "")
     
     //TODO: loading from db until loading from Consumer is possible.
     var ProductDetails = ProductUtils.getProductDetails(pid, PriceListFilter, 
-            [["info", SqlUtils.translateStatementWithQuotes(SqlCondition.begin()
-                                  .andPrepareVars("DESCRIPTIONTRANSLATION.OBJECT_ROWID", "local.value")
-                                  .and("DESCRIPTIONTRANSLATION.OBJECT_TYPE = 'Product'")
-                                  .andPrepareVars("DESCRIPTIONTRANSLATION.LANG", "$param.Language_param")
-                                  .buildSql("(select DESCRIPTION from DESCRIPTIONTRANSLATION", "1=2", ")"))]
+            [["info", "(" + newSelect("DESCRIPTION")
+                            .from("DESCRIPTIONTRANSLATION")
+                            .whereIfSet("DESCRIPTIONTRANSLATION.OBJECT_ROWID", "local.value")
+                            .and("DESCRIPTIONTRANSLATION.OBJECT_TYPE = 'Product'")
+                            .andIfSet("DESCRIPTIONTRANSLATION.LANG", "$param.Language_param")
+                            .toString() + ")"]
             ]);
     
     if(ProductDetails.productId != undefined)
diff --git a/entity/Offeritem_entity/entityfields/totalprice/displayValueProcess.js b/entity/Offeritem_entity/entityfields/totalprice/displayValueProcess.js
index 106a609bee58eae9b4557c2bf76288b70fa96f0d..f23c116341674384a3368d928d986d2fb04466e3 100644
--- a/entity/Offeritem_entity/entityfields/totalprice/displayValueProcess.js
+++ b/entity/Offeritem_entity/entityfields/totalprice/displayValueProcess.js
@@ -13,9 +13,10 @@ var curr = vars.get("$param.Currency_param")
 }
 
 else {
-     curr = db.cell(SqlCondition.begin()
-                    .andPrepareVars("OFFER.OFFERID", "$field.OFFER_ID")
-                    .buildSql("select CURRENCY from OFFER", "1=2"));
+     curr = newSelect("CURRENCY")
+                .from("OFFER")
+                .whereIfSet("OFFER.OFFERID", "$field.OFFER_ID")
+                .cell(true);
 }
 
 result.string(NumberUtils.formatWithCurrency(vars.get("$field.TotalPrice"), translate.text("#,##0.00"), curr));
\ No newline at end of file
diff --git a/entity/Offeritem_entity/recordcontainers/db/conditionProcess.js b/entity/Offeritem_entity/recordcontainers/db/conditionProcess.js
index 935c6d7b06f543932bafe5d2cb5cdf70d7bed013..82c536561aaac4f8a876433b2311a932cc7b50f4 100644
--- a/entity/Offeritem_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Offeritem_entity/recordcontainers/db/conditionProcess.js
@@ -3,8 +3,7 @@ import("Sql_lib");
 import("system.result");
 import("system.vars");
 
-var cond = SqlCondition.begin()
-                       .andPrepareVars("OFFERITEM.OFFER_ID", "$param.OfferId_param")
+var cond = newWhereIfSet("OFFERITEM.OFFER_ID", "$param.OfferId_param")
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1=1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/Offeritem_entity/recordcontainers/db/onDBDelete.js b/entity/Offeritem_entity/recordcontainers/db/onDBDelete.js
index 568700b215786effb8a1556df300e84cd46d1ad2..b57a000dc524159f6bb77bd4472eeb4b1b563353 100644
--- a/entity/Offeritem_entity/recordcontainers/db/onDBDelete.js
+++ b/entity/Offeritem_entity/recordcontainers/db/onDBDelete.js
@@ -16,8 +16,9 @@ if(oid != "")
     var cols = ["NET", "VAT"];
     
     var vals = oiUtils.getNetAndVat(deletedIds);
-
-    db.updateData("OFFER", cols, null, vals, SqlCondition.equals("OFFER.OFFERID", oid, "1 = 2"));
+    
+    newWhere("OFFER.OFFERID", oid)
+        .updateData(true, cols, null, vals, "OFFER")
     
     neon.refresh();
 }
\ No newline at end of file
diff --git a/entity/Offeritem_entity/recordcontainers/db/onDBInsert.js b/entity/Offeritem_entity/recordcontainers/db/onDBInsert.js
index 317fce086c92e7e36cb070594c3fb2a756b386d0..04e755228fd4771188fe9d9adb357fc02e9c3b15 100644
--- a/entity/Offeritem_entity/recordcontainers/db/onDBInsert.js
+++ b/entity/Offeritem_entity/recordcontainers/db/onDBInsert.js
@@ -22,6 +22,6 @@ if(oid != "")
     var vals = oiUtils.getNetAndVat();
     var cols = ["NET", "VAT"];
 
-    db.updateData("OFFER", cols, null, vals, SqlCondition.equals("OFFER.OFFERID", oid, "1 = 2"));
-    
+    newWhere("OFFER.OFFERID", oid)
+        .updateData(true, cols, null, vals, "OFFER");    
 }
\ No newline at end of file
diff --git a/entity/Offeritem_entity/recordcontainers/db/onDBUpdate.js b/entity/Offeritem_entity/recordcontainers/db/onDBUpdate.js
index 01bec1734b9df50f7bf027cb4fcad0251e19e8cb..604a63f14f6a2543baaea9add368f8e61fa5357a 100644
--- a/entity/Offeritem_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/Offeritem_entity/recordcontainers/db/onDBUpdate.js
@@ -10,5 +10,6 @@ if(oid != "")
     var cols = ["NET", "VAT"];    
     var oiUtils = new OfferItemUtils(oid);
     
-    db.updateData("OFFER", cols, null, oiUtils.getNetAndVat(), SqlCondition.equals("OFFER.OFFERID", oid, "1 = 2"));
+    newWhere("OFFER.OFFERID", oid)
+        .updateData(true, cols, null, oiUtils.getNetAndVat(), "OFFER");    
 }
\ No newline at end of file
diff --git a/entity/Order_entity/entityfields/cancel/onActionProcess.js b/entity/Order_entity/entityfields/cancel/onActionProcess.js
index f138c6f5779923d74ae1b3ecb9202739a28f1ad6..fa3f5510b56bb63838d642e06492f11e056b892b 100644
--- a/entity/Order_entity/entityfields/cancel/onActionProcess.js
+++ b/entity/Order_entity/entityfields/cancel/onActionProcess.js
@@ -8,9 +8,9 @@ import("KeywordRegistry_basic");
 
 var id = vars.get("$field.SALESORDERID");
 
-db.updateData("SALESORDER", ["CANCELLATION"], null, ["1"], SqlCondition.begin()
-                                                                       .andPrepareVars("SALESORDER.SALESORDERID", "$field.SALESORDERID")
-                                                                       .build("1=2"));
+newWhereIfSet("SALESORDER.SALESORDERID", "$field.SALESORDERID")
+    .updateData(true, ["CANCELLATION"], null, ["1"], "SALESORDER")
+
 neon.refreshAll();
 
 var contactId = vars.getString("$field.CONTACT_ID");
diff --git a/entity/Order_entity/entityfields/cancel/stateProcess.js b/entity/Order_entity/entityfields/cancel/stateProcess.js
index 64b25ea3d5a2cc521c892377b25790da145d9b02..ec7809f90e7917866e6dc4352b6e26c485418d28 100644
--- a/entity/Order_entity/entityfields/cancel/stateProcess.js
+++ b/entity/Order_entity/entityfields/cancel/stateProcess.js
@@ -6,9 +6,10 @@ import("system.neon");
 import("Keyword_lib");
 import("KeywordRegistry_basic");
 
-var itemcount = db.cell(SqlCondition.begin()
-                    .andPrepareVars("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID")
-                    .buildSql("select count(*) from SALESORDERITEM", "1=2"));
+var itemcount = newSelect("count(*)")
+                    .from("SALESORDERITEM")
+                    .whereIfSet("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID")
+                    .cell(true, "0");
                                        
 if(itemcount == "0")
     result.string(neon.COMPONENTSTATE_DISABLED);
diff --git a/entity/Order_entity/entityfields/footer/valueProcess.js b/entity/Order_entity/entityfields/footer/valueProcess.js
index c1f95afc6561ec8bfd0a494f291500999dd9adf6..7eebbf85ccc8c260b08ab22ce6ac784275920a03 100644
--- a/entity/Order_entity/entityfields/footer/valueProcess.js
+++ b/entity/Order_entity/entityfields/footer/valueProcess.js
@@ -20,9 +20,12 @@ if (vars.get("$this.value") == null)
 
     if (vars.get("$field.ChosenTexFooter") != "")
     {
-        var binaryId = db.cell(SqlCondition.begin()
-            .andPrepareVars("ASYS_BINARIES.ROW_ID", "$field.ChosenTexFooter")
-            .buildSql("select ID from ASYS_BINARIES"), SqlUtils.getBinariesAlias());
-        result.string(util.decodeBase64String(db.getBinaryContent(binaryId, SqlUtils.getBinariesAlias())));
+        var binaryId = newSelect("ID", SqlUtils.getBinariesAlias())
+                            .from("ASYS_BINARIES")
+                            .whereIfSet("ASYS_BINARIES.ROW_ID", "$field.ChosenTexFooter")
+                            .cell(true);
+                            
+        if (binaryId)
+            result.string(util.decodeBase64String(db.getBinaryContent(binaryId, SqlUtils.getBinariesAlias())));
     }
 }
\ No newline at end of file
diff --git a/entity/Order_entity/entityfields/header/valueProcess.js b/entity/Order_entity/entityfields/header/valueProcess.js
index 7dd541dea0949f3933bfa9e55f6c58649c643132..0adc1563dd309d78e547dd920956cfd87d85061d 100644
--- a/entity/Order_entity/entityfields/header/valueProcess.js
+++ b/entity/Order_entity/entityfields/header/valueProcess.js
@@ -18,9 +18,12 @@ if (vars.get("$this.value") == null)
 
     if (vars.get("$field.ChosenTexHeader") != "")
     {
-        var binaryId = db.cell(SqlCondition.begin()
-            .andPrepareVars("ASYS_BINARIES.ROW_ID", "$field.ChosenTexHeader")
-            .buildSql("select ID from ASYS_BINARIES"), SqlUtils.getBinariesAlias());
-        result.string(util.decodeBase64String(db.getBinaryContent(binaryId, SqlUtils.getBinariesAlias())));
+        var binaryId = newSelect("ID", SqlUtils.getBinariesAlias())
+                            .from("ASYS_BINARIES")
+                            .whereIfSet("ASYS_BINARIES.ROW_ID", "$field.ChosenTexHeader")
+                            .cell(true);
+                            
+        if (binaryId)
+            result.string(util.decodeBase64String(db.getBinaryContent(binaryId, SqlUtils.getBinariesAlias())));
     }
 }
\ No newline at end of file
diff --git a/entity/Order_entity/entityfields/isolanguage/displayValueProcess.js b/entity/Order_entity/entityfields/isolanguage/displayValueProcess.js
index d60342f7264e2cb7c41a787563070a80c827eb53..82a2b31777afebf0a66a9c841e10bc43995da5a4 100644
--- a/entity/Order_entity/entityfields/isolanguage/displayValueProcess.js
+++ b/entity/Order_entity/entityfields/isolanguage/displayValueProcess.js
@@ -6,10 +6,10 @@ import("Sql_lib");
 
 if (vars.exists("$param.OrderLanguage_param") && vars.get("$param.OrderLanguage_param")) 
 {
-    var iso3 = vars.get("$param.OrderLanguage_param");
-    var latinName = db.cell(SqlCondition.begin()
-        .andPrepare("AB_LANGUAGE.ISO3", iso3)
-        .buildSql("select NAME_LATIN from AB_LANGUAGE", "1=0"));
-    latinName = translate.text(latinName);
-    result.string(latinName);
+    var latinName = newSelect("NAME_LATIN")
+                        .from("AB_LANGUAGE")
+                        .whereIfSet("AB_LANGUAGE.ISO3", "$param.OrderLanguage_param")
+                        .cell(true);
+                        
+    result.string(translate.text(latinName));
 }
\ No newline at end of file
diff --git a/entity/Order_entity/entityfields/printorder/stateProcess.js b/entity/Order_entity/entityfields/printorder/stateProcess.js
index c4b677743bb6551495c672855030a7d3d651cc15..6c2edd66259be1edc80cabe7388cfed334c7637b 100644
--- a/entity/Order_entity/entityfields/printorder/stateProcess.js
+++ b/entity/Order_entity/entityfields/printorder/stateProcess.js
@@ -3,9 +3,10 @@ import("system.result");
 import("Sql_lib");
 import("system.db");
 
-var itemcount = db.cell(SqlCondition.begin()
-                    .andPrepareVars("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID")
-                    .buildSql("select count(*) from SALESORDERITEM", "1=2"));
+var itemcount = newSelect("count(*)")
+                    .from("SALESORDERITEM")
+                    .whereIfSet("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID")
+                    .cell(true, "0");
                                        
 if(itemcount == "0")
     result.string(neon.COMPONENTSTATE_DISABLED);
diff --git a/entity/Order_entity/entityfields/printreminder/stateProcess.js b/entity/Order_entity/entityfields/printreminder/stateProcess.js
index 50ba51671b5c75f055d93f88dd5e8cfbd4e15b3b..1deafcafaf0b8fcef07a02dd381b0f9cb620097d 100644
--- a/entity/Order_entity/entityfields/printreminder/stateProcess.js
+++ b/entity/Order_entity/entityfields/printreminder/stateProcess.js
@@ -6,9 +6,10 @@ import("system.neon");
 import("Keyword_lib");
 import("KeywordRegistry_basic");
 
-var itemcount = db.cell(SqlCondition.begin()
-                    .andPrepareVars("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID")
-                    .buildSql("select count(*) from SALESORDERITEM", "1=2"));
+var itemcount = newSelect("count(*)")
+                    .from("SALESORDERITEM")
+                    .whereIfSet("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID")
+                    .cell(true, "0");
                                        
 if(itemcount == "0")
     result.string(neon.COMPONENTSTATE_DISABLED);
diff --git a/entity/Order_entity/entityfields/setdunning/stateProcess.js b/entity/Order_entity/entityfields/setdunning/stateProcess.js
index 50ba51671b5c75f055d93f88dd5e8cfbd4e15b3b..1deafcafaf0b8fcef07a02dd381b0f9cb620097d 100644
--- a/entity/Order_entity/entityfields/setdunning/stateProcess.js
+++ b/entity/Order_entity/entityfields/setdunning/stateProcess.js
@@ -6,9 +6,10 @@ import("system.neon");
 import("Keyword_lib");
 import("KeywordRegistry_basic");
 
-var itemcount = db.cell(SqlCondition.begin()
-                    .andPrepareVars("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID")
-                    .buildSql("select count(*) from SALESORDERITEM", "1=2"));
+var itemcount = newSelect("count(*)")
+                    .from("SALESORDERITEM")
+                    .whereIfSet("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID")
+                    .cell(true, "0");
                                        
 if(itemcount == "0")
     result.string(neon.COMPONENTSTATE_DISABLED);
diff --git a/entity/Order_entity/entityfields/setpaid/stateProcess.js b/entity/Order_entity/entityfields/setpaid/stateProcess.js
index 5f9a54534115990966c267b702d1aeff3ce3f415..d6b29515b623c6629eb8d1124ed3117b7d0f0371 100644
--- a/entity/Order_entity/entityfields/setpaid/stateProcess.js
+++ b/entity/Order_entity/entityfields/setpaid/stateProcess.js
@@ -6,9 +6,10 @@ import("system.neon");
 import("Keyword_lib");
 import("KeywordRegistry_basic");
 
-var itemcount = db.cell(SqlCondition.begin()
-                    .andPrepareVars("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID")
-                    .buildSql("select count(*) from SALESORDERITEM", "1=2"));
+var itemcount = newSelect("count(*)")
+                    .from("SALESORDERITEM")
+                    .whereIfSet("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID")
+                    .cell(true, "0");
                                        
 if(itemcount == "0")
     result.string(neon.COMPONENTSTATE_DISABLED);
diff --git a/entity/Order_entity/entityfields/setsent/onActionProcess.js b/entity/Order_entity/entityfields/setsent/onActionProcess.js
index 00f7dfa911a15c3884f3361c025d2c318dca0de6..54964655b74ae154ac20b2dbce81adc85ed0750f 100644
--- a/entity/Order_entity/entityfields/setsent/onActionProcess.js
+++ b/entity/Order_entity/entityfields/setsent/onActionProcess.js
@@ -5,7 +5,7 @@ import("system.db");
 
 var id = vars.get("$field.SALESORDERID");
 
-db.updateData("SALESORDER", ["ORDERSTATUS"], null, ["1"], SqlCondition.begin()
-                                                                       .andPrepareVars("SALESORDER.SALESORDERID", "$field.SALESORDERID")
-                                                                       .build("1=2"));
+newWhere("SALESORDER.SALESORDERID", "$field.SALESORDERID")
+    .updateData(true, ["ORDERSTATUS"], null, ["1"], "SALESORDER")
+
 neon.refreshAll();
\ No newline at end of file
diff --git a/entity/Order_entity/entityfields/setsent/stateProcess.js b/entity/Order_entity/entityfields/setsent/stateProcess.js
index 58fd03d38334ab142b7449b62e3ca49bbc6f333f..3394d928fc39d70a0ac14b5d15d9dc10d02c3695 100644
--- a/entity/Order_entity/entityfields/setsent/stateProcess.js
+++ b/entity/Order_entity/entityfields/setsent/stateProcess.js
@@ -4,9 +4,10 @@ import("system.db");
 import("Sql_lib");
 import("system.neon");
 
-var itemcount = db.cell(SqlCondition.begin()
-                    .andPrepareVars("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID")
-                    .buildSql("select count(*) from SALESORDERITEM", "1=2"));
+var itemcount = newSelect("count(*)")
+                    .from("SALESORDERITEM")
+                    .whereIfSet("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID")
+                    .cell(true, "0");
                                        
 if(itemcount == "0")
     result.string(neon.COMPONENTSTATE_DISABLED);
diff --git a/entity/Order_entity/entityfields/transferdeliverynote/stateProcess.js b/entity/Order_entity/entityfields/transferdeliverynote/stateProcess.js
index 70dcb91387b497cf5b6d275f9bb4c4b73ff17f12..e470fe5777aed09073f77101657901973165665f 100644
--- a/entity/Order_entity/entityfields/transferdeliverynote/stateProcess.js
+++ b/entity/Order_entity/entityfields/transferdeliverynote/stateProcess.js
@@ -6,9 +6,10 @@ import("system.neon");
 import("Keyword_lib");
 import("KeywordRegistry_basic");
 
-var itemcount = db.cell(SqlCondition.begin()
-                    .andPrepareVars("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID")
-                    .buildSql("select count(*) from SALESORDERITEM", "1=2"));
+var itemcount = newSelect("count(*)")
+                    .from("SALESORDERITEM")
+                    .whereIfSet("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID")
+                    .cell(true, "0");
                                        
 if(itemcount == "0")
     result.string(neon.COMPONENTSTATE_DISABLED);
diff --git a/entity/Order_entity/entityfields/transferinvoice/stateProcess.js b/entity/Order_entity/entityfields/transferinvoice/stateProcess.js
index bf1ec7bf9d805b22bd5a4f7b0afa3273fae78c55..4f992e23ec1be9a7a305e63bed1de3170cc86f23 100644
--- a/entity/Order_entity/entityfields/transferinvoice/stateProcess.js
+++ b/entity/Order_entity/entityfields/transferinvoice/stateProcess.js
@@ -6,9 +6,10 @@ import("system.neon");
 import("Keyword_lib");
 import("KeywordRegistry_basic");
 
-var itemcount = db.cell(SqlCondition.begin()
-                    .andPrepareVars("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID")
-                    .buildSql("select count(*) from SALESORDERITEM", "1=2"));
+var itemcount = newSelect("count(*)")
+                    .from("SALESORDERITEM")
+                    .whereIfSet("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID")
+                    .cell(true, "0");
                                        
 if(itemcount == "0")
     result.string(neon.COMPONENTSTATE_DISABLED);
diff --git a/entity/Order_entity/recordcontainers/db/conditionProcess.js b/entity/Order_entity/recordcontainers/db/conditionProcess.js
index ce09b123fbcbffd79742ce3f79d6fa6ae7007997..8cf25e0b6012c7604600258d1df63e614e87528f 100644
--- a/entity/Order_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Order_entity/recordcontainers/db/conditionProcess.js
@@ -3,13 +3,13 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = new SqlCondition();
+var cond = newWhere();
 
 if(vars.exists("$param.ContactId_param") && vars.get("$param.ContactId_param"))
-    cond.andPrepareVars("SALESORDER.CONTACT_ID", "$param.ContactId_param");
+    cond.andIfSet("SALESORDER.CONTACT_ID", "$param.ContactId_param");
 else {
-    cond.andPrepareVars("SALESORDER.OBJECT_ROWID", "$param.ObjectRowId_param");
-    cond.andPrepareVars("SALESORDEER.OBJECT_TYPE", "$param.ObjectType_param");
+    cond.andIfSet("SALESORDER.OBJECT_ROWID", "$param.ObjectRowId_param")
+        .andIfSet("SALESORDEER.OBJECT_TYPE", "$param.ObjectType_param");
 }
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/Orderitem_entity/entityfields/price/displayValueProcess.js b/entity/Orderitem_entity/entityfields/price/displayValueProcess.js
index bc27c4c4e48d7b46cd353afb1a3220e7fb1ba2da..489768c6520532d4126779e42cc7282d49c9b7c7 100644
--- a/entity/Orderitem_entity/entityfields/price/displayValueProcess.js
+++ b/entity/Orderitem_entity/entityfields/price/displayValueProcess.js
@@ -5,17 +5,17 @@ import("system.vars");
 import("system.translate");
 import("system.result");
 
- if (vars.get("$param.Currency_param")) 
-    {
-var curr = vars.get("$param.Currency_param")
-
-
+var curr;
+if (vars.get("$param.Currency_param")) 
+{
+    curr = vars.get("$param.Currency_param");
 }
-
-else {
-     curr = db.cell(SqlCondition.begin()
-                    .andPrepareVars("SALESORDER.SALESORDERID", "$field.SALESORDER_ID")
-                    .buildSql("select CURRENCY from SALESORDER", "1=2"));
+else 
+{
+     curr = newSelect("CURRENCY")
+                .from("SALESORDER")
+                .whereIfSet("SALESORDER.SALESORDERID", "$field.SALESORDER_ID")
+                .cell(true);
 }
 
 result.string(NumberUtils.formatWithCurrency(vars.get("$field.PRICE"), translate.text("#,##0.00"), curr));
\ No newline at end of file
diff --git a/entity/Orderitem_entity/entityfields/totalprice/displayValueProcess.js b/entity/Orderitem_entity/entityfields/totalprice/displayValueProcess.js
index 5adc43216c1936a1f9f87edca3ec1eeec5b81a32..8085abfa370c8eb212417a32206a189721995b59 100644
--- a/entity/Orderitem_entity/entityfields/totalprice/displayValueProcess.js
+++ b/entity/Orderitem_entity/entityfields/totalprice/displayValueProcess.js
@@ -1,21 +1,20 @@
-import("Sql_lib");
-import("system.db");
-import("Util_lib");
-import("system.vars");
 import("system.translate");
+import("Util_lib");
 import("system.result");
+import("Sql_lib");
+import("system.vars");
 
- if (vars.get("$param.Currency_param")) 
-    {
-var curr = vars.get("$param.Currency_param")
-
-
+var curr;
+if (vars.get("$param.Currency_param")) 
+{
+    curr = vars.get("$param.Currency_param");
 }
-
-else {
-     curr = db.cell(SqlCondition.begin()
-                    .andPrepareVars("SALESORDER.SALESORDERID", "$field.SALESORDER_ID")
-                    .buildSql("select CURRENCY from SALESORDER", "1=2"));
+else 
+{
+     curr = newSelect("CURRENCY")
+                .from("SALESORDER")
+                .whereIfSet("SALESORDER.SALESORDERID", "$field.SALESORDER_ID")
+                .cell(true);
 }
 
 result.string(NumberUtils.formatWithCurrency(vars.get("$field.TotalPrice"), translate.text("#,##0.00"), curr));
\ No newline at end of file
diff --git a/entity/Orderitem_entity/grantCreateProcess.js b/entity/Orderitem_entity/grantCreateProcess.js
index afb8faec00e4b1522d7f664e6061b4e8596d7136..966985d262774df03719e82cf98d36ca1c520c4b 100644
--- a/entity/Orderitem_entity/grantCreateProcess.js
+++ b/entity/Orderitem_entity/grantCreateProcess.js
@@ -4,11 +4,10 @@ import("system.vars");
 import("system.result");
 import("Order_lib");
 
-
-
-var itemcount = db.cell(SqlCondition.begin()
-                    .andPrepareVars("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDER_ID")
-                    .buildSql("select count(*) from SALESORDERITEM", "1=2"));
+var itemcount = newSelect("count(*)")
+                    .from("SALESORDERITEM")
+                    .whereIfSet("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID")
+                    .cell(true, "0");
 
 if (vars.get("$field.OrderStatus") == undefined){
     result.string(false);
diff --git a/entity/Orderitem_entity/grantUpdateProcess.js b/entity/Orderitem_entity/grantUpdateProcess.js
index afb8faec00e4b1522d7f664e6061b4e8596d7136..966985d262774df03719e82cf98d36ca1c520c4b 100644
--- a/entity/Orderitem_entity/grantUpdateProcess.js
+++ b/entity/Orderitem_entity/grantUpdateProcess.js
@@ -4,11 +4,10 @@ import("system.vars");
 import("system.result");
 import("Order_lib");
 
-
-
-var itemcount = db.cell(SqlCondition.begin()
-                    .andPrepareVars("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDER_ID")
-                    .buildSql("select count(*) from SALESORDERITEM", "1=2"));
+var itemcount = newSelect("count(*)")
+                    .from("SALESORDERITEM")
+                    .whereIfSet("SALESORDERITEM.SALESORDER_ID", "$field.SALESORDERID")
+                    .cell(true, "0");
 
 if (vars.get("$field.OrderStatus") == undefined){
     result.string(false);
diff --git a/entity/Orderitem_entity/recordcontainers/db/conditionProcess.js b/entity/Orderitem_entity/recordcontainers/db/conditionProcess.js
index 7091cb2d3455066683b4231e649484f4b141c9bc..5957207757012e79cce2cff0ed3316c780d85fec 100644
--- a/entity/Orderitem_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Orderitem_entity/recordcontainers/db/conditionProcess.js
@@ -3,8 +3,7 @@ import("Sql_lib");
 import("system.result");
 import("system.vars");
 
-var cond = SqlCondition.begin()
-                       .andPrepareVars("SALESORDERITEM.SALESORDER_ID", "$param.OrderId_param")
+var cond = newWhereIfSet("SALESORDERITEM.SALESORDER_ID", "$param.OrderId_param")
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1=1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/Orderitem_entity/recordcontainers/db/onDBDelete.js b/entity/Orderitem_entity/recordcontainers/db/onDBDelete.js
index 1893bf1fa144173d7daa6b7d8f6145a08de46751..b0de4a07eb64f79f5f6de63d628c817b388883ac 100644
--- a/entity/Orderitem_entity/recordcontainers/db/onDBDelete.js
+++ b/entity/Orderitem_entity/recordcontainers/db/onDBDelete.js
@@ -16,7 +16,8 @@ if(oid != "")
     var cols = ["NET", "VAT"];
     var vals = oiUtils.getNetAndVat(deletedIds);
     
-    db.updateData("SALESORDER", cols, null, vals, SqlCondition.equals("SALESORDER.SALESORDERID", oid, "1 = 2"));
+    newWhere("SALESORDER.SALESORDERID", oid)
+        .updateData(true, cols, null, vals, "SALESORDER");
 
     neon.refresh();
 }
\ No newline at end of file
diff --git a/entity/Orderitem_entity/recordcontainers/db/onDBInsert.js b/entity/Orderitem_entity/recordcontainers/db/onDBInsert.js
index f640c4a569c268911c75a31eeb4456703d71a78a..3c98634e370008673bc688e45b46cc45545bdedd 100644
--- a/entity/Orderitem_entity/recordcontainers/db/onDBInsert.js
+++ b/entity/Orderitem_entity/recordcontainers/db/onDBInsert.js
@@ -23,6 +23,6 @@ if(oid != "")
     var cols = ["NET", "VAT"];
     var vals = oiUtils.getNetAndVat();
     
-    db.updateData("SALESORDER", cols, null, vals, SqlCondition.equals("SALESORDER.SALESORDERID", oid, "1 = 2"));
-    
+    newWhere("SALESORDER.SALESORDERID", oid)
+        .updateData(true, cols, null, vals, "SALESORDER");
 }
diff --git a/entity/Orderitem_entity/recordcontainers/db/onDBUpdate.js b/entity/Orderitem_entity/recordcontainers/db/onDBUpdate.js
index 0dfdf166457f26bc6d39a9250cb5043ffe157ce2..6ddfbf6145b59a4377b4c98eacd0d067c35f732a 100644
--- a/entity/Orderitem_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/Orderitem_entity/recordcontainers/db/onDBUpdate.js
@@ -11,5 +11,6 @@ if(oid != "")
     var oiUtils = new OrderItemUtils(oid);
     var vals = oiUtils.getNetAndVat();
     
-    db.updateData("SALESORDER", cols, null, vals, SqlCondition.equals("SALESORDER.SALESORDERID", oid, "1 = 2"));
+    newWhere("SALESORDER.SALESORDERID", oid)
+        .updateData(true, cols, null, vals, "SALESORDER");
 }
\ No newline at end of file
diff --git a/entity/Organisation_entity/recordcontainers/db/conditionProcess.js b/entity/Organisation_entity/recordcontainers/db/conditionProcess.js
index e8a11d8b244a578880b99e0a1f6a7469ba19eb62..d988911bd963d9fc27dee54fb9e64d071e9a81af 100644
--- a/entity/Organisation_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Organisation_entity/recordcontainers/db/conditionProcess.js
@@ -1,45 +1,43 @@
+import("system.logging");
 import("system.vars");
 import("system.db");
 import("system.result");
 import("Sql_lib");
 import("Context_lib");
 
-var cond = SqlCondition.begin();
+var cond = newWhere();
                             
 // filter privat company if it is not needed
 if (vars.getString("$param.WithPrivate_param") != "true")
-    cond.andPrepare("ORGANISATION.ORGANISATIONID", "0", "# <> ?");
+    cond.and("ORGANISATION.ORGANISATIONID", "0", "# <> ?");
 
 var excludeOrgsWithPersonId = vars.get("$param.ExcludeOrganisationsByPersonId")
 if (excludeOrgsWithPersonId)
-    cond.andAttachPrepared(SqlCondition.begin()
-                                       .andPrepare("CONTACT.PERSON_ID", excludeOrgsWithPersonId)
-                                       .buildSql("ORGANISATION.ORGANISATIONID not in (select CONTACT.ORGANISATION_ID from CONTACT", null, ")"));
-
+{
+    var excludedOrgsSelect = newSelect("CONTACT.ORGANISATION_ID")
+                                .from("CONTACT")
+                                .where("CONTACT.PERSON_ID", excludeOrgsWithPersonId);
+                                    
+    cond.and("ORGANISATION.ORGANISATIONID", excludedOrgsSelect, SqlBuilder.NOT_IN())
+}
 if (vars.exists("$param.AttributeId_param") && vars.get("$param.AttributeId_param"))
 {
-    var hasAttributeCondition = SqlCondition.begin()
-                                            .andPrepare("AB_ATTRIBUTERELATION.OBJECT_TYPE", ContextUtils.getCurrentContextId())
-                                            .andPrepare("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID", vars.get("$param.AttributeId_param"))
-                                            .andPrepareVars("AB_ATTRIBUTERELATION.ID_VALUE", "$param.AttributeKeyId_param");
-                                            
-    cond.andAttachPrepared(hasAttributeCondition.buildSql("ORGANISATION.ORGANISATIONID in (select OBJECT_ROWID from AB_ATTRIBUTERELATION", "1=2", ")"));
+    var hasAttributeOrgIdSubselect = newSelect("OBJECT_ROWID")
+                                        .from("AB_ATTRIBUTERELATION")
+                                        .where("AB_ATTRIBUTERELATION.OBJECT_TYPE", ContextUtils.getCurrentContextId())
+                                        .and("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID", "$param.AttributeId_param")
+                                        .andIfSet("AB_ATTRIBUTERELATION.ID_VALUE", "$param.AttributeKeyId_param")
+    
+    cond.and("ORGANISATION.ORGANISATIONID", hasAttributeOrgIdSubselect, SqlBuilder.IN())
 }
 
 if (vars.exists("$param.ExcludedContactIds_param") && vars.get("$param.ExcludedContactIds_param"))
 {
     var excludedContacts = JSON.parse(vars.getString("$param.ExcludedContactIds_param"));
-    var excludedCond = SqlCondition.begin();
-    
-    excludedContacts.forEach(function(pContactId)
-    {
-        excludedCond.andPrepare("CONTACT.CONTACTID", pContactId, "#<>?");
-    });
-    
-    cond.andSqlCondition(excludedCond, "1=1");
+    cond.andIfSet("CONTACT.CONTACTID", excludedContacts, SqlBuilder.NOT_IN())
 }
 
-cond.andPrepareVars("ORGANISATION.KIND", "$param.OrganisationType_param");
+cond.andIfSet("ORGANISATION.KIND", "$param.OrganisationType_param");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/PermissionDetail_entity/recordcontainers/jdito/onDelete.js b/entity/PermissionDetail_entity/recordcontainers/jdito/onDelete.js
index d061d0fd357d1b6238aacb46f7e0ffc4f6ac480d..e926aadf243b979c5ab646016379de71a5f7bea4 100644
--- a/entity/PermissionDetail_entity/recordcontainers/jdito/onDelete.js
+++ b/entity/PermissionDetail_entity/recordcontainers/jdito/onDelete.js
@@ -12,15 +12,9 @@ var parentPermSetId = PermissionUtil.getParentSet(permId);
 var linkedActions = PermissionUtil.getActions([permId]);
 var noCond = "{\"entity\":\"" + vars.get("$field.ENTITY") + "\",\"filter\":{\"type\":\"group\",\"operator\":\"AND\",\"childs\":[]}}";
 
-var sqlCondDelAction = SqlCondition.begin()
-.and("ASYS_PERMISSIONACTION.ASYS_PERMISSIONACTIONID in ('" + linkedActions.join("','") + "')")
-.build();
-var sqlCondDelPerm = SqlCondition.begin()
-.and("ASYS_PERMISSION.ASYS_PERMISSIONID = '" + permId + "'")
-.build();
-var sqlCondDelPermSet = SqlCondition.begin()
-.and("ASYS_PERMISSIONSET.ASYS_PERMISSIONSETID = '" + parentPermSetId + "'")
-.build();
+var sqlCondDelAction = newWhereIfSet("ASYS_PERMISSIONACTION.ASYS_PERMISSIONACTIONID", linkedActions, SqlBuilder.IN(), undefined, alias);
+var sqlCondDelPerm = newWhereIfSet("ASYS_PERMISSION.ASYS_PERMISSIONID", permId, "# = ?", undefined, alias);
+var sqlCondDelPermSet = newWhereIfSet("ASYS_PERMISSIONSET.ASYS_PERMISSIONSETID", parentPermSetId, "# = ?", undefined, alias);
 
 switch (accessType) {
     case "E":
@@ -29,19 +23,13 @@ switch (accessType) {
         let allPerms = PermissionUtil.getPermissions(allPermSets);
         let allPermActions = PermissionUtil.getActions(allPerms);
         
-        sqlCondDelAction = SqlCondition.begin()
-            .and("ASYS_PERMISSIONACTION.ASYS_PERMISSIONACTIONID in ('" + allPermActions.join("','") + "')")
-            .build();
-        sqlCondDelPerm = SqlCondition.begin()
-            .and("ASYS_PERMISSION.ASYS_PERMISSIONID in ('" + allPerms.join("','") + "')")
-            .build();
-        sqlCondDelPermSet = SqlCondition.begin()
-            .and("ASYS_PERMISSIONSET.ASYS_PERMISSIONSETID in ('" + allPermSets.join("','") + "')")
-            .build();
+        sqlCondDelAction = newWhereIfSet("ASYS_PERMISSIONACTION.ASYS_PERMISSIONACTIONID", allPermActions, SqlBuilder.IN(), undefined, alias);
+        sqlCondDelPerm = newWhereIfSet("ASYS_PERMISSION.ASYS_PERMISSIONID", allPerms, SqlBuilder.IN(), undefined, alias);
+        sqlCondDelPermSet = newWhereIfSet("ASYS_PERMISSIONSET.ASYS_PERMISSIONSETID", allPermSets, SqlBuilder.IN(), undefined, alias);
         
-        db.deleteData("ASYS_PERMISSIONACTION", sqlCondDelAction, alias); // delete all actions
-        db.deleteData("ASYS_PERMISSION", sqlCondDelPerm, alias); // delete all permissions
-        db.deleteData("ASYS_PERMISSIONSET", sqlCondDelPermSet, alias); // delete all permission sets
+        sqlCondDelAction.deleteData(true, "ASYS_PERMISSIONACTION"); // delete all actions
+        sqlCondDelPerm.deleteData(true, "ASYS_PERMISSION"); // delete all permissions
+        sqlCondDelPermSet.deleteData(true, "ASYS_PERMISSIONSET"); // delete all permission sets
         break;
     default:
         if (PermissionUtil.getCond(permId) == "" || PermissionUtil.getCond(permId) == noCond) { // check if permission is default or conditional permission
@@ -50,25 +38,21 @@ switch (accessType) {
             allPerms.push(permId);
             let allActions = PermissionUtil.getActions(allPerms);
             
-            sqlCondDelAction = SqlCondition.begin()
-                .and("ASYS_PERMISSIONACTION.ASYS_PERMISSIONACTIONID in ('" + allActions.join("','") + "')")
-                .build();
-            sqlCondDelPerm = SqlCondition.begin()
-                .and("ASYS_PERMISSION.ASYS_PERMISSIONID in ('" + allPerms.join("','") + "')")
-                .build();
+            sqlCondDelAction = newWhereIfSet("ASYS_PERMISSIONACTION.ASYS_PERMISSIONACTIONID", allActions, SqlBuilder.IN(), undefined, alias);
+            sqlCondDelPerm = newWhereIfSet("ASYS_PERMISSION.ASYS_PERMISSIONID", allPerms, SqlBuilder.IN(), undefined, alias);
             
-            db.deleteData("ASYS_PERMISSIONACTION", sqlCondDelAction, alias); // delete all actions of the selected permission
-            db.deleteData("ASYS_PERMISSION", sqlCondDelPerm, alias); // delete the selected permission
+            sqlCondDelAction.deleteData(true, "ASYS_PERMISSIONACTION"); // delete all actions of the selected permission
+            sqlCondDelPerm.deleteData(true, "ASYS_PERMISSION"); // delete the selected permission
         } else {
             // conditional permission -> only delete this permission
-            db.deleteData("ASYS_PERMISSIONACTION", sqlCondDelAction, alias); // delete all actions of the selected permission
-            db.deleteData("ASYS_PERMISSION", sqlCondDelPerm, alias); // delete the selected permission
+            sqlCondDelAction.deleteData(true, "ASYS_PERMISSIONACTION"); // delete all actions of the selected permission
+            sqlCondDelPerm.deleteData(true, "ASYS_PERMISSION"); // delete the selected permission
         }
         break;
 }
 
 if (PermissionUtil.setIsEmpty(parentPermSetId)) {
-    db.deleteData("ASYS_PERMISSIONSET", sqlCondDelPermSet, alias); // delete empty permissionset
+    sqlCondDelPermSet.deleteData(true, "ASYS_PERMISSIONSET"); // delete empty permissionset
 }
 
 tools.clearPermissionCache();
\ No newline at end of file
diff --git a/entity/PermissionDetail_entity/recordcontainers/jdito/onUpdate.js b/entity/PermissionDetail_entity/recordcontainers/jdito/onUpdate.js
index 105a129772bb983a78f293abf7112fdd995809ed..91704b4533134ee0926e227e4013d48f777f70a5 100644
--- a/entity/PermissionDetail_entity/recordcontainers/jdito/onUpdate.js
+++ b/entity/PermissionDetail_entity/recordcontainers/jdito/onUpdate.js
@@ -19,9 +19,10 @@ var diff = PermissionUtil.getActionDiff(permissionid, actionNew);
 if (diff.length > 0) {
     // delete all linked permission actions
     table = "ASYS_PERMISSIONACTION";
-    cond = SqlCondition.begin().and("ASYS_PERMISSION_ID = '" + permissionid + "'").build();
-    var dbDeletes = db.deleteData(table, cond, alias);
     
+    newWhere("ASYS_PERMISSIONACTION.ASYS_PERMISSION_ID", permissionid, "# = ?", undefined, alias)
+        .deleteData(true, table);
+
     // insert the different actions
     cols = db.getColumns(table, alias);
     for each (var action in actionNew) {
diff --git a/entity/PermissionOverview_entity/recordcontainers/jdito/contentProcess.js b/entity/PermissionOverview_entity/recordcontainers/jdito/contentProcess.js
index 3e15f2cfb644d46d4d4177578c9542d5614fb3ab..ed60fbfacd3853fbe22d62773d0960f1c8075922 100644
--- a/entity/PermissionOverview_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/PermissionOverview_entity/recordcontainers/jdito/contentProcess.js
@@ -1,3 +1,4 @@
+import("system.logging");
 import("Sql_lib");
 import("system.project");
 import("system.vars");
@@ -8,8 +9,6 @@ import("Permission_lib");
 var res = [];
 var roleTitle = "";
 var entityTitle = "";
-var sqlCond = "";
-var sqlStr = "";
 let alias = SqlUtils.getSystemAlias();
 var roleInternalEveryone = "INTERNAL_EVERYONE";
 
@@ -28,40 +27,61 @@ for each (let entityMetaData in entitiesMetaData) {
     }
 }
 
-var sqlCondEntityUsePermFlagSet = " and ENTITY_ID in ('" + entitiesUsePermFlagSet.join("','") + "')";
-
-if (vars.exists("$param.RoleTitle_param") && vars.get("$param.RoleTitle_param")) {
-    roleTitle = vars.getString("$param.RoleTitle_param");
-    sqlCond = " where ROLE_ID = '" + roleTitle + "'";
-    sqlStr = "select distinct ENTITY_ID from ASYS_PERMISSIONSET" + sqlCond + sqlCondEntityUsePermFlagSet;
-} else if (vars.exists("$param.EntityTitle_param") && vars.get("$param.EntityTitle_param")) {
-    entityTitle = vars.getString("$param.EntityTitle_param");
-    sqlCond = " where ENTITY_ID = '" + entityTitle + "'";
-    sqlStr = "select distinct ROLE_ID from ASYS_PERMISSIONSET" + sqlCond + sqlCondEntityUsePermFlagSet;
+var rolesOrEntitiesSelect = new SqlBuilder(alias);
+var rolesOrEntities = [];
+// select nothing if no entities have the perm flag set
+if (entitiesUsePermFlagSet.length > 0)
+{
+    if (vars.exists("$param.RoleTitle_param") && vars.get("$param.RoleTitle_param")) {
+        roleTitle = vars.getString("$param.RoleTitle_param");
+        rolesOrEntitiesSelect.select("distinct ENTITY_ID")
+                            .from("ASYS_PERMISSIONSET")
+                            .where("ASYS_PERMISSIONSET.ROLE_ID", roleTitle)
+    } 
+    else if (vars.exists("$param.EntityTitle_param") && vars.get("$param.EntityTitle_param")) 
+    {
+        entityTitle = vars.getString("$param.EntityTitle_param");
+        rolesOrEntitiesSelect.select("distinct ROLE_ID")
+                            .from("ASYS_PERMISSIONSET")
+                            .where("ASYS_PERMISSIONSET.ENTITY_ID", entityTitle)
+    }
+    
+    rolesOrEntities = rolesOrEntitiesSelect
+                           .and("ASYS_PERMISSIONSET.ENTITY_ID", entitiesUsePermFlagSet, SqlBuilder.IN())
+                           .arrayColumn();
 }
 
-var rolesOrEntities = db.array(db.COLUMN, sqlStr);
-var entityPermSetId = "";
+
+
 for each (var entry in rolesOrEntities) { // entry contains either a role or an entity, depending on which param exists
     if (vars.exists("$param.RoleTitle_param") && vars.get("$param.RoleTitle_param")) {
         entityPermSetId = PermissionUtil.getSetRoot(roleTitle, entry);
     } else if (vars.exists("$param.EntityTitle_param") && vars.get("$param.EntityTitle_param")) {
         entityPermSetId = PermissionUtil.getSetRoot(entry, entityTitle);
     }
-    var recordPermSetId = db.array(db.COLUMN, SqlCondition.begin().and("ASYS_PERMISSIONSET_ID = '" + entityPermSetId + "'").and("ACCESSTYPE = 'R'")
-        .buildSql("select ASYS_PERMISSIONSETID from ASYS_PERMISSIONSET"), alias);
-    var currOverview = [entityPermSetId, entry, "VAADIN:CLOSE", "VAADIN:CLOSE", "VAADIN:CLOSE", "VAADIN:CLOSE", "VAADIN:CLOSE"];
 
-    // default entity permissions
-    currOverview = prepareOverview(entityPermSetId, currOverview, "default");
+    if (entityPermSetId)
+    {
+        var recordPermSetId = new SqlBuilder(alias)
+                                .select("ASYS_PERMISSIONSETID")
+                                .from("ASYS_PERMISSIONSET")
+                                .where("ASYS_PERMISSIONSET.ASYS_PERMISSIONSET_ID", entityPermSetId)
+                                .and("ACCESSTYPE = 'R'")
+                                .arrayColumn();
+
+        var currOverview = [entityPermSetId, entry, "VAADIN:CLOSE", "VAADIN:CLOSE", "VAADIN:CLOSE", "VAADIN:CLOSE", "VAADIN:CLOSE"];
 
-    // conditional record permissions
-    currOverview = prepareOverview(recordPermSetId, currOverview, "conditional");
+        // default entity permissions
+        currOverview = prepareOverview(entityPermSetId, currOverview, "default");
 
-    // default record permissions
-    currOverview = prepareOverview(recordPermSetId, currOverview, "default");
+        // conditional record permissions
+        currOverview = prepareOverview(recordPermSetId, currOverview, "conditional");
 
-    res.push(currOverview);
+        // default record permissions
+        currOverview = prepareOverview(recordPermSetId, currOverview, "default");
+
+        res.push(currOverview);
+    }
 }
 result.object(res);
 
diff --git a/entity/Person_entity/conditionProcess.js b/entity/Person_entity/conditionProcess.js
index 61b7bebcb9305f94c832bf03fbdff1445f846b0b..788e9d568184651faaeafd86739f620cb5e7d224 100644
--- a/entity/Person_entity/conditionProcess.js
+++ b/entity/Person_entity/conditionProcess.js
@@ -1,11 +1,10 @@
-import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = new SqlCondition();
-cond.andPrepareVars("CONTACT.ORGANISATION_ID", "$param.OrgId_param");
-cond.andPrepareVars("PERSON.CONTACT_ID", "$param.ContactId_param");
+var cond = newWhere()
+            .andIfSet("CONTACT.ORGANISATION_ID", "$param.OrgId_param")
+            .andIfSet("PERSON.CONTACT_ID", "$param.ContactId_param");
 
 //TODO; add OBJECT_ID (probably another param)
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/Person_entity/entityfields/gender/displayValueProcess.js b/entity/Person_entity/entityfields/gender/displayValueProcess.js
index d2680b57571d016a5045bf9751a05eb05d4a93bb..734a0b1410de96958c342202f8aad49b52ed096e 100644
--- a/entity/Person_entity/entityfields/gender/displayValueProcess.js
+++ b/entity/Person_entity/entityfields/gender/displayValueProcess.js
@@ -1,16 +1,10 @@
 import("system.vars");
-import("Keyword_lib");
-import("system.result");
-import("system.db");
-import("system.vars");
-import("system.neon");
-import("Sql_lib");
 import("KeywordRegistry_basic");
+import("system.result");
 import("Keyword_lib");
+import("Sql_lib");
 
-
-var cond = SqlCondition.begin()
-var sex = db.cell(cond.andPrepareVars("SALUTATION.SALUTATION", "$field.SALUTATION").buildSql("select SEX from SALUTATION", "1=2"))
+var sex = vars.get("$field.GENDER");
     
 if (sex)
 {
diff --git a/entity/Person_entity/entityfields/gender/valueProcess.js b/entity/Person_entity/entityfields/gender/valueProcess.js
index 9d763fea86f10f390de8a5fd38d6398bc827d677..503d28b8f3585e6dd83457d7bc629c0c0199e87c 100644
--- a/entity/Person_entity/entityfields/gender/valueProcess.js
+++ b/entity/Person_entity/entityfields/gender/valueProcess.js
@@ -1,11 +1,9 @@
 import("system.result");
-import("system.db");
-import("system.vars");
-import("system.neon");
 import("Sql_lib");
 
-var cond = SqlCondition.begin()
-
-var sex = db.cell(cond.andPrepareVars("SALUTATION.SALUTATION", "$field.SALUTATION").buildSql("select SEX from SALUTATION", "1=2"))
-
-result.string(sex)
\ No newline at end of file
+var sex = newSelect("SEX")
+                .from("SALUTATION")
+                .whereIfSet("SALUTATION.SALUTATION", "$field.SALUTATION")
+                .cell(true);
+if (sex)
+    result.string(sex);
\ No newline at end of file
diff --git a/entity/Person_entity/entityfields/orgaddresses/children/contactid_param/valueProcess.js b/entity/Person_entity/entityfields/orgaddresses/children/contactid_param/valueProcess.js
index 0af516898e01741a99fc1b9e4daed65a6de7c3cd..86fcb7fe92249b1abc81ea4447d4415e27ef5721 100644
--- a/entity/Person_entity/entityfields/orgaddresses/children/contactid_param/valueProcess.js
+++ b/entity/Person_entity/entityfields/orgaddresses/children/contactid_param/valueProcess.js
@@ -6,7 +6,11 @@ import("Sql_lib");
 var orgId = vars.get("$field.ORGANISATION_ID");
 if (orgId)
 {
-    var cond = SqlCondition.begin().and("CONTACT.PERSON_ID is null").andPrepare("CONTACT.ORGANISATION_ID", orgId);
-    var orgRelId = db.cell(cond.buildSql("select CONTACT.CONTACTID from CONTACT", "1 = 1"));
+    var orgRelId = newSelect("CONTACT.CONTACTID")
+                        .from("CONTACT")
+                        .where("CONTACT.PERSON_ID is null")
+                        .and("CONTACT.ORGANISATION_ID", orgId)
+                        .cell();
+        
     result.string(orgRelId);
 }
\ No newline at end of file
diff --git a/entity/Person_entity/recordcontainers/db/conditionProcess.js b/entity/Person_entity/recordcontainers/db/conditionProcess.js
index 15b9975dc380f240b7055c7e39a0af796217e0f1..8bd62f913cf07ee09acb292913f226ad852bf9bf 100644
--- a/entity/Person_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Person_entity/recordcontainers/db/conditionProcess.js
@@ -3,15 +3,14 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = new SqlCondition();
-cond.andPrepareVars("CONTACT.ORGANISATION_ID", "$param.OrgId_param")
-    .andPrepareVars("PERSON.CONTACT_ID", "$param.ContactId_param");
+var cond = newWhereIfSet("CONTACT.ORGANISATION_ID", "$param.OrgId_param")
+                .andIfSet("PERSON.CONTACT_ID", "$param.ContactId_param");
 
 if (vars.exists("$param.ExcludedContactIds_param") && vars.get("$param.ExcludedContactIds_param"))
 {
     var excludedContacts = JSON.parse(vars.getString("$param.ExcludedContactIds_param"));
-    cond.andIn("CONTACT.CONTACTID", excludedContacts, undefined, true);
+    cond.andIfSet("CONTACT.CONTACTID", excludedContacts, SqlBuilder.NOT_IN());
 }
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/PrivatePerson_entity/recordcontainers/db/conditionProcess.js b/entity/PrivatePerson_entity/recordcontainers/db/conditionProcess.js
index 9164618bf9b1cd954eef4d8407ddb00f65593a88..d7230024504ab503e79b5b4c306b41c2a4c3d35e 100644
--- a/entity/PrivatePerson_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/PrivatePerson_entity/recordcontainers/db/conditionProcess.js
@@ -3,13 +3,13 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = new SqlCondition();
+var cond = newWhere();
 
 if (vars.get("$param.ExcludedPersonIds_param"))
 {
     var excludedPersons = JSON.parse(vars.getString("$param.ExcludedPersonIds_param"));
-    cond.andIn("PERSON.PERSONID", excludedPersons, undefined, true);
+    cond.andIfSet("PERSON.PERSONID", excludedPersons, SqlBuilder.NOT_IN());
 }
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/Prod2prod_entity/Prod2prod_entity.aod b/entity/Prod2prod_entity/Prod2prod_entity.aod
index f580faaec9590c336e26a55b0c7f43129405b0d7..ca9cbd99dd94363c344a818384739a7e01fc25b7 100644
--- a/entity/Prod2prod_entity/Prod2prod_entity.aod
+++ b/entity/Prod2prod_entity/Prod2prod_entity.aod
@@ -128,6 +128,7 @@
     <jDitoRecordContainer>
       <name>jdito</name>
       <jDitoRecordAlias>Data_alias</jDitoRecordAlias>
+      <isRequireContainerFiltering v="true" />
       <contentProcess>%aditoprj%/entity/Prod2prod_entity/recordcontainers/jdito/contentProcess.js</contentProcess>
       <onInsert>%aditoprj%/entity/Prod2prod_entity/recordcontainers/jdito/onInsert.js</onInsert>
       <onUpdate>%aditoprj%/entity/Prod2prod_entity/recordcontainers/jdito/onUpdate.js</onUpdate>
diff --git a/entity/Prod2prod_entity/entityfields/alter/children/insert/onActionProcess.js b/entity/Prod2prod_entity/entityfields/alter/children/insert/onActionProcess.js
index 9ab774bcf4868b4a23a6c0ff1b2ea7f55184b8e4..7119a964dc6512ad374f8aa17b917d126a27e1fd 100644
--- a/entity/Prod2prod_entity/entityfields/alter/children/insert/onActionProcess.js
+++ b/entity/Prod2prod_entity/entityfields/alter/children/insert/onActionProcess.js
@@ -15,6 +15,4 @@ if (vars.exists("$local.rows") && vars.get("$local.rows"))
 
         neon.openContext("Prod2prod", "Prod2ProdEdit_view", null, neon.OPERATINGSTATE_NEW, params);
     }
-    
-    
 }
\ No newline at end of file
diff --git a/entity/Prod2prod_entity/entityfields/products/children/excludedproducts_param/valueProcess.js b/entity/Prod2prod_entity/entityfields/products/children/excludedproducts_param/valueProcess.js
index cc6b35783c6a05dc9deebfb83e491f8ca092bba1..61d089f5dbb0ce3bdb487cd54971966dcb4db26d 100644
--- a/entity/Prod2prod_entity/entityfields/products/children/excludedproducts_param/valueProcess.js
+++ b/entity/Prod2prod_entity/entityfields/products/children/excludedproducts_param/valueProcess.js
@@ -30,7 +30,7 @@ else
 
 result.object(excludeIDs);
 
-// TODO: remove code duplication, better param naming and using SqlCondition
+// TODO: remove code duplication, better param naming and using SqlBuilder
 function _getParentID(pID, pIDs)
 {
     //Ermitteln welche Produkte ausgeschlossen werden müssen.
diff --git a/entity/Prod2prod_entity/entityfields/uid/valueProcess.js b/entity/Prod2prod_entity/entityfields/uid/valueProcess.js
index 86ef789e064a4016f2d12c432498dc23474807aa..884a038bbce84aa5a3bc93ac65bc962fd93f468d 100644
--- a/entity/Prod2prod_entity/entityfields/uid/valueProcess.js
+++ b/entity/Prod2prod_entity/entityfields/uid/valueProcess.js
@@ -4,4 +4,4 @@ import("system.result");
 import("system.neon");
 
 if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
-    result.string(util.getNewUUID());
\ No newline at end of file
+    result.object([util.getNewUUID(), vars.get("$field.PROD2PRODID")]); // 1. is some random uid for uniqueness 2. is the prod2ProdID
\ No newline at end of file
diff --git a/entity/Prod2prod_entity/recordcontainers/jdito/contentProcess.js b/entity/Prod2prod_entity/recordcontainers/jdito/contentProcess.js
index 8bb7ef210a16a0ec02600971d745d6ce9b6db042..468aab3158406abdeb1858ec6a58d34f48810536 100644
--- a/entity/Prod2prod_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/Prod2prod_entity/recordcontainers/jdito/contentProcess.js
@@ -1,3 +1,5 @@
+import("Sql_lib");
+import("system.logging");
 import("system.neon");
 import("system.result");
 import("system.vars");
@@ -81,7 +83,7 @@ function buildGraph (elementID, parentElementID, mappingStructure, prod2prodIdMa
     var virtualProd2ProdId = util.getNewUUID();
     
     // Override actual PROD2PROD_ID with new ID.
-    elementData[0] = virtualProd2ProdId;
+    elementData[0] = JSON.stringify([virtualProd2ProdId, elementData[0]]);
  
     // Override parent id to match overriden prod2prodId of parent
     if (parentElementID === null || parentElementID === undefined)
@@ -119,25 +121,47 @@ function buildGraph (elementID, parentElementID, mappingStructure, prod2prodIdMa
  * So *IF* you need that check for the state, you should check if this error is thrown 
  * + add a comment why the check is needed here instead of this current comment
  */
-var prodid = vars.exists("$param.ProductId_param") 
-             && vars.get("$param.ProductId_param") != null ? vars.get("$param.ProductId_param") : "";
-if(prodid != "")
+
+if (vars.get("$local.idvalues") && vars.get("$local.idvalues").length > 0)
+{
+    var prod2prodId = JSON.parse(vars.get("$local.idvalues")[0])[1];
+    if (prod2prodId)
+    {
+        logging.log(JSON.stringify([vars.get("$local.idvalues")], null, "\t"))
+        var prodData = newSelect("PROD2PRODID, SOURCE_ID, DEST_ID, QUANTITY, PRODUCTCODE, PRODUCTID, PROD2PRODID, OPTIONAL, TAKEPRICE, PRODUCTNAME")
+                        .from("PROD2PROD")
+                        .join("PRODUCT", "PROD2PROD.SOURCE_ID = PRODUCTID")
+                        .where("PROD2PROD.PROD2PRODID", prod2prodId)
+                        .arrayRow();
+                        
+        prodData[0] = vars.get("$local.idvalues")[0];
+        result.object([prodData]);
+    }
+    
+    
+}
+else
 {
-    // First 3 columns are crucial, the rest is optional.
-    var data = db.table("select PROD2PRODID, SOURCE_ID, DEST_ID, QUANTITY, PRODUCTCODE, PRODUCTID, PROD2PRODID, OPTIONAL, TAKEPRICE, PRODUCTNAME "
-                + "from PROD2PROD join PRODUCT on PROD2PROD.SOURCE_ID = PRODUCTID "
-                + "order by PRODUCTCODE");
+    var prodid = vars.exists("$param.ProductId_param") 
+             && vars.get("$param.ProductId_param") != null ? vars.get("$param.ProductId_param") : "";
+    if(prodid != "")
+    {
+        // First 3 columns are crucial, the rest is optional.
+        var data = db.table("select PROD2PRODID, SOURCE_ID, DEST_ID, QUANTITY, PRODUCTCODE, PRODUCTID, PROD2PRODID, OPTIONAL, TAKEPRICE, PRODUCTNAME "
+                    + "from PROD2PROD join PRODUCT on PROD2PROD.SOURCE_ID = PRODUCTID "
+                    + "order by PRODUCTCODE");
 
-    var prod2prodIdMapping = buildProd2ProdIDMapping(data);
-    var childrenMapping = buildChildrenMapping(data);
-    var rootElements = calculateRootElements(prodid, data);
+        var prod2prodIdMapping = buildProd2ProdIDMapping(data);
+        var childrenMapping = buildChildrenMapping(data);
+        var rootElements = calculateRootElements(prodid, data);
 
-    var allData = []
+        var allData = []
 
-    rootElements.forEach(function(rg) {
-        var graphData = buildGraph(rg, null, childrenMapping, prod2prodIdMapping)
-        graphData.forEach(function (gd) { allData.push(gd); })
-    })
+        rootElements.forEach(function(rg) {
+            var graphData = buildGraph(rg, null, childrenMapping, prod2prodIdMapping)
+            graphData.forEach(function (gd) { allData.push(gd); })
+        })
 
-    result.object(allData);
+        result.object(allData);
+    }
 }
\ No newline at end of file
diff --git a/entity/Prod2prod_entity/recordcontainers/jdito/onDelete.js b/entity/Prod2prod_entity/recordcontainers/jdito/onDelete.js
index 3f5b37d8a09c58c04eb400f106a90a33be140cdd..39e2bbe547e511298d7dc3a86b90258e0356288f 100644
--- a/entity/Prod2prod_entity/recordcontainers/jdito/onDelete.js
+++ b/entity/Prod2prod_entity/recordcontainers/jdito/onDelete.js
@@ -3,9 +3,9 @@ import("system.neon");
 import("system.db");
 import("Sql_lib");
 
-db.deleteData("PROD2PROD", SqlCondition.begin()
-                                       .andPrepareVars("PROD2PROD.PROD2PRODID", "$field.PROD2PRODID")
-                                       .build("1=2"));
+newWhereIfSet("PROD2PROD.PROD2PRODID", "$field.PROD2PRODID")
+    .deleteData(true, "PROD2PROD");
 
 // Refresh otherwise the children of the deleted node would be moved to the root.
-neon.refresh();
\ No newline at end of file
+//TODO: refresh throwss error
+//neon.refresh();
\ No newline at end of file
diff --git a/entity/Prod2prod_entity/recordcontainers/jdito/onInsert.js b/entity/Prod2prod_entity/recordcontainers/jdito/onInsert.js
index 1d75fead1790876b501debdb8b83e25f66bda3c0..44ad498731f8787b5a3144ad55f64c180f25df0d 100644
--- a/entity/Prod2prod_entity/recordcontainers/jdito/onInsert.js
+++ b/entity/Prod2prod_entity/recordcontainers/jdito/onInsert.js
@@ -1,3 +1,4 @@
+import("system.neon");
 import("system.datetime");
 import("system.vars");
 import("system.db");
@@ -16,4 +17,5 @@ var vals = [ vars.get("$field.PROD2PRODID")
            , vars.get("$field.OPTIONAL")
            , vars.get("$field.TAKEPRICE") ];
 
-db.insertData("PROD2PROD", cols, null, vals);
\ No newline at end of file
+db.insertData("PROD2PROD", cols, null, vals);
+neon.refreshAll()
\ No newline at end of file
diff --git a/entity/Product_entity/recordcontainers/db/conditionProcess.js b/entity/Product_entity/recordcontainers/db/conditionProcess.js
index b0cb4c15622232ab8d2da5ffe1e238affea98485..3602fca8eb08a457b21fdd77bfd58ab4f43be1d3 100644
--- a/entity/Product_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Product_entity/recordcontainers/db/conditionProcess.js
@@ -3,17 +3,13 @@ import("system.vars");
 import("system.db");
 import("Sql_lib");
 
-var productCond = SqlCondition.begin()
+var productCond = newWhere();
 
 if (vars.exists("$param.ExcludedProducts_param") && vars.get("$param.ExcludedProducts_param"))
 {
     var excludedIds = JSON.parse(vars.getString("$param.ExcludedProducts_param"));
-
-    excludedIds.forEach(function(pId) 
-    {
-        this.andPrepare("PRODUCT.PRODUCTID", pId, "# <> ?");
-    }, productCond);
+    productCond.andIfSet("PRODUCT.PRODUCTID", excludedIds, SqlBuilder.NOT_IN());
 }
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(productCond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(productCond.toString());
\ No newline at end of file
diff --git a/entity/Productprice_entity/entityfields/pricelist/displayValueProcess.js b/entity/Productprice_entity/entityfields/pricelist/displayValueProcess.js
index 7a3a89b39d202c168a9daa1ec7cfeced91144ce3..e54cffa4492fb80eb8563f5d25a0e6aee709ae84 100644
--- a/entity/Productprice_entity/entityfields/pricelist/displayValueProcess.js
+++ b/entity/Productprice_entity/entityfields/pricelist/displayValueProcess.js
@@ -10,9 +10,12 @@ import("KeywordRegistry_basic");
 var pricelistname = vars.get("$field.PRICELIST");
 if (!pricelistname)
 {
-    var preparedStatement = SqlCondition.begin().andPrepare("CONTACT.CONTACTID", vars.get("$field.CONTACT_ID"));
-    var dbresult = preparedStatement.buildSql("select ORGANISATION.NAME from CONTACT inner join ORGANISATION on CONTACT.ORGANISATION_ID=ORGANISATION.ORGANISATIONID", "1=2", "order by NAME");
-    var orgname = db.cell(dbresult);
+    var orgname = newSelect("ORGANISATION.NAME")
+                    .from("CONTACT")
+                    .join("ORGANISATION", "CONTACT.ORGANISATION_ID = ORGANISATION.ORGANISATIONID", undefined, "inner")
+                    .orderBy("NAME")
+                    .whereIfSet("CONTACT.CONTACTID", "$field.CONTACT_ID")
+                    .cell(true);
     
     result.string(orgname);
 }
diff --git a/entity/Productprice_entity/entityfields/product_id/displayValueProcess.js b/entity/Productprice_entity/entityfields/product_id/displayValueProcess.js
index 02c9bf53af00f0336b3a614e36ac3d4ad2f9858b..902d8b81e59a1cebe37203456662652334a07411 100644
--- a/entity/Productprice_entity/entityfields/product_id/displayValueProcess.js
+++ b/entity/Productprice_entity/entityfields/product_id/displayValueProcess.js
@@ -8,7 +8,8 @@ import("Sql_lib");
 if((vars.exists("$param.ProductId_param") && vars.get("$param.ProductId_param") && vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
     || vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT || vars.get("$sys.recordstate") == neon.OPERATINGSTATE_VIEW)
 {
-    result.string(db.cell(SqlCondition.begin()
-                                  .andPrepareVars("PRODUCT.PRODUCTID", "$field.PRODUCT_ID")
-                                  .buildSql("select PRODUCTNAME from PRODUCT", "1=2")));
+    result.string(newSelect("PRODUCTNAME")
+                    .from("PRODUCT")
+                    .whereIfSet("$field.PRODUCT_ID")
+                    .cell(true));
 }
\ No newline at end of file
diff --git a/entity/Productprice_entity/recordcontainers/db/conditionProcess.js b/entity/Productprice_entity/recordcontainers/db/conditionProcess.js
index 5fce6b87cf721a8dfe88f5d13f5c75cb35f0b767..a68cf9891b46dc2d7e584e8f64da30aa40bf8543 100644
--- a/entity/Productprice_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Productprice_entity/recordcontainers/db/conditionProcess.js
@@ -1,11 +1,9 @@
-import("system.db");
 import("system.result");
-import("system.vars");
 import("Sql_lib");
 
-var cond = SqlCondition.begin()
-                       .andPrepareVars("PRODUCTPRICE.PRODUCT_ID", "$param.ProductId_param")
-                       .andPrepareVars("PRODUCTPRICE.CONTACT_ID", "$param.ContactId_param");
+var cond = newWhere()
+                .andIfSet("PRODUCTPRICE.PRODUCT_ID", "$param.ProductId_param")
+                .andIfSet("PRODUCTPRICE.CONTACT_ID", "$param.ContactId_param");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/QuickEntry_entity/recordcontainers/jdito/onInsert.js b/entity/QuickEntry_entity/recordcontainers/jdito/onInsert.js
index 15b53f0df14c70a6013ab4200594571ad1834b8a..e0891f1fe607eda473e4993d2e8b8cf1d9e5a513 100644
--- a/entity/QuickEntry_entity/recordcontainers/jdito/onInsert.js
+++ b/entity/QuickEntry_entity/recordcontainers/jdito/onInsert.js
@@ -67,9 +67,10 @@ if (rowdata["LASTNAME.value"])
         "USER_NEW",
         "DATE_NEW"
     ];
-    var gender = db.cell(SqlCondition.begin()
-        .andPrepareIfSet("SALUTATION.SALUTATION", rowdata["PERSON_SALUTATION.value"])
-        .buildSql("select SEX from SALUTATION", "1=2"));
+    var gender = newSelect("SEX")
+                    .from("SALUTATION")
+                    .whereIfSet("SALUTATION.SALUTATION", rowdata["PERSON_SALUTATION.value"])
+                    .cell(true);
 
     var personVals = [
         rowdata["PERSON_ID.value"],
diff --git a/entity/SalesprojectAnalyses_entity/entityfields/my_forecast/valueProcess.js b/entity/SalesprojectAnalyses_entity/entityfields/my_forecast/valueProcess.js
index 3c50ff040b61415400542117cabae20fc0c81ef5..b42db4e92b2f1cd8d5c2c26e12119155191db777 100644
--- a/entity/SalesprojectAnalyses_entity/entityfields/my_forecast/valueProcess.js
+++ b/entity/SalesprojectAnalyses_entity/entityfields/my_forecast/valueProcess.js
@@ -1,19 +1,18 @@
-import("Employee_lib");
-import("system.datetime");
-import("system.db");
 import("system.result");
+import("system.SQLTYPES");
 import("system.vars");
-import("Date_lib");
+import("system.datetime");
 import("Sql_lib");
-import("system.SQLTYPES")
+import("Employee_lib");
 
 var myContactId = EmployeeUtils.getCurrentContactId();
 
-var forecast = db.cell(SqlCondition.begin()
-                                    .andPrepare("FORECAST.DATE_START", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER)
-                                    .andPrepare("OBJECTMEMBER.OBJECT_TYPE", 'Salesproject')
-                                    .andPrepare("OBJECTMEMBER.CONTACT_ID", myContactId)
-                                    .buildSql("select SUM(VOLUME) from OBJECTMEMBER \n\
-                                    left join FORECAST on FORECAST.OBJECT_TYPE = OBJECTMEMBER.OBJECT_TYPE and FORECAST.OBJECT_ROWID = OBJECTMEMBER.OBJECT_ROWID", "1=2"));
+var forecast = newSelect("SUM(VOLUME)")
+                    .from("OBJECTMEMBER")
+                    .leftJoin("FORECAST", "FORECAST.OBJECT_TYPE = OBJECTMEMBER.OBJECT_TYPE and FORECAST.OBJECT_ROWID = OBJECTMEMBER.OBJECT_ROWID")
+                    .where("FORECAST.DATE_START", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER)
+                    .and("OBJECTMEMBER.OBJECT_TYPE", 'Salesproject')
+                    .and("OBJECTMEMBER.CONTACT_ID", myContactId)
+                    .cell();
                                   
 result.string(forecast);
\ No newline at end of file
diff --git a/entity/SalesprojectAnalyses_entity/entityfields/my_turnover/valueProcess.js b/entity/SalesprojectAnalyses_entity/entityfields/my_turnover/valueProcess.js
index a3c62683acd37a7cd2b87024bc8217b5b8e59980..46cd9ba9e681d3d5a0883823562e2110d8d286f0 100644
--- a/entity/SalesprojectAnalyses_entity/entityfields/my_turnover/valueProcess.js
+++ b/entity/SalesprojectAnalyses_entity/entityfields/my_turnover/valueProcess.js
@@ -11,12 +11,13 @@ import("system.SQLTYPES")
 
 var myContactId = EmployeeUtils.getCurrentContactId();
 
-var turnover = db.cell(SqlCondition.begin()
-                                   .andPrepare("SALESORDER.SALESORDERDATE", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER)
-                                   .andPrepare("SALESORDER.ORDERTYPE", "ORDTYPEINVO")
-                                   .andPrepare("OBJECTMEMBER.OBJECT_TYPE", 'Salesproject')
-                                   .andPrepare("OBJECTMEMBER.CONTACT_ID", myContactId)
-                                   .buildSql("select sum(NET + VAT) from OBJECTMEMBER \n\
-                                   left join SALESORDER on SALESORDER.OBJECT_TYPE = OBJECTMEMBER.OBJECT_TYPE and SALESORDER.OBJECT_ROWID = OBJECTMEMBER.OBJECT_ROWID", "1=2"));
+var turnover = newSelect("sum(NET + VAT)")
+                    .from("OBJECTMEMBER")
+                    .leftJoin("SALESORDER", "SALESORDER.OBJECT_TYPE = OBJECTMEMBER.OBJECT_TYPE and SALESORDER.OBJECT_ROWID = OBJECTMEMBER.OBJECT_ROWID")
+                    .where("SALESORDER.SALESORDERDATE", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER)
+                    .and("SALESORDER.ORDERTYPE", "ORDTYPEINVO")
+                    .and("OBJECTMEMBER.OBJECT_TYPE", 'Salesproject')
+                    .and("OBJECTMEMBER.CONTACT_ID", myContactId)
+                    .cell();
                                   
 result.string(turnover);
\ No newline at end of file
diff --git a/entity/SalesprojectAnalyses_entity/entityfields/overall_forecast/valueProcess.js b/entity/SalesprojectAnalyses_entity/entityfields/overall_forecast/valueProcess.js
index d6f89d038debab8b78a11020bdcc2b989341414d..11bf47828e54c9717e4be2002742fd632e42f3e7 100644
--- a/entity/SalesprojectAnalyses_entity/entityfields/overall_forecast/valueProcess.js
+++ b/entity/SalesprojectAnalyses_entity/entityfields/overall_forecast/valueProcess.js
@@ -6,8 +6,9 @@ import("Date_lib");
 import("Sql_lib");
 import("system.SQLTYPES")
 
-var forecast = db.cell(SqlCondition.begin()
-                                    .andPrepare("FORECAST.DATE_START", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER)
-                                    .buildSql("select sum(VOLUME) from FORECAST", "1=2"));
+var forecast = newSelect("sum(VOLUME)")
+                    .from("FORECAST")
+                    .where("FORECAST.DATE_START", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER)
+                    .cell();
                                   
 result.string(forecast);
\ No newline at end of file
diff --git a/entity/SalesprojectAnalyses_entity/entityfields/overall_turnover/valueProcess.js b/entity/SalesprojectAnalyses_entity/entityfields/overall_turnover/valueProcess.js
index 9c8e5ea68dc50dc8a1b7f3ddb63eeffa651d316f..fb9181d479ded05d017fa498a37642d570c9e70f 100644
--- a/entity/SalesprojectAnalyses_entity/entityfields/overall_turnover/valueProcess.js
+++ b/entity/SalesprojectAnalyses_entity/entityfields/overall_turnover/valueProcess.js
@@ -1,13 +1,12 @@
-import("system.datetime");
-import("system.db");
 import("system.result");
+import("system.SQLTYPES");
 import("system.vars");
-import("Date_lib");
+import("system.datetime");
 import("Sql_lib");
-import("system.SQLTYPES")
 
-var turnover = db.cell(SqlCondition.begin()
-                                   .andPrepare("SALESORDER.SALESORDERDATE", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER)
-                                   .buildSql("select sum(NET + VAT) from SALESORDER", "1=2"));
+var turnover = newSelect("sum(NET + VAT)")
+                    .from("SALESORDER")
+                    .where("SALESORDER.SALESORDERDATE", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER)
+                    .cell();
                                   
 result.string(turnover);
\ No newline at end of file
diff --git a/entity/SalesprojectMilestone_entity/conditionProcess.js b/entity/SalesprojectMilestone_entity/conditionProcess.js
index 1d1cfabadaf9282142752e33bf7f3febc7eb0fc6..300b91638bc8b36ce14988109c1826b68a3054de 100644
--- a/entity/SalesprojectMilestone_entity/conditionProcess.js
+++ b/entity/SalesprojectMilestone_entity/conditionProcess.js
@@ -1,10 +1,7 @@
-import("system.db");
 import("system.result");
-import("system.vars");
 import("Sql_lib");
 
-var cond = new SqlCondition();
-cond.andPrepareVars("SALESPROJECT_MILESTONE.SALESPROJECT_ID", "$param.SalesprojectId_param");
+var cond = newWhereIfSet("SALESPROJECT_MILESTONE.SALESPROJECT_ID", "$param.SalesprojectId_param")
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/SalesprojectMilestone_entity/recordcontainers/db/conditionProcess.js b/entity/SalesprojectMilestone_entity/recordcontainers/db/conditionProcess.js
index 66767400e5dc295ce57df3e358f051094872b725..9a21e39ea75ecfa1a1d8989379141d381f361144 100644
--- a/entity/SalesprojectMilestone_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/SalesprojectMilestone_entity/recordcontainers/db/conditionProcess.js
@@ -1,11 +1,9 @@
-import("system.db");
 import("system.result");
-import("system.vars");
 import("Sql_lib");
 
-var cond = SqlCondition.begin()
-                       .andPrepareVars("SALESPROJECT_MILESTONE.SALESPROJECT_ID", "$param.SalesprojectId_param")
-                       .andPrepareVars("SALESPROJECT_MILESTONE.KIND", "$param.Kind_param");
+var cond = newWhere()
+            .andIfSet("SALESPROJECT_MILESTONE.SALESPROJECT_ID", "$param.SalesprojectId_param")
+            .andIfSet("SALESPROJECT_MILESTONE.KIND", "$param.Kind_param");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/SalesprojectSource_entity/conditionProcess.js b/entity/SalesprojectSource_entity/conditionProcess.js
index 51b6dcc323e8e6e57e2dc182f55ad5c0d2eed219..679d08965b06a59685ccaa6341679110f8f953b7 100644
--- a/entity/SalesprojectSource_entity/conditionProcess.js
+++ b/entity/SalesprojectSource_entity/conditionProcess.js
@@ -1,9 +1,7 @@
-import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = new SqlCondition();
-cond.andPrepareVars("SALESPROJECT_TOUCHPOINT.SALESPROJECT_ID", "$param.SalesprojectId_param");
+var cond = newWhereIfSet("SALESPROJECT_TOUCHPOINT.SALESPROJECT_ID", "$param.SalesprojectId_param");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/SalesprojectSource_entity/recordcontainers/db/conditionProcess.js b/entity/SalesprojectSource_entity/recordcontainers/db/conditionProcess.js
index 51b6dcc323e8e6e57e2dc182f55ad5c0d2eed219..bad867525a17aebb0ecc286db4afeadc7f846b7f 100644
--- a/entity/SalesprojectSource_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/SalesprojectSource_entity/recordcontainers/db/conditionProcess.js
@@ -2,8 +2,7 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = new SqlCondition();
-cond.andPrepareVars("SALESPROJECT_TOUCHPOINT.SALESPROJECT_ID", "$param.SalesprojectId_param");
+var cond = newWhereIfSet("SALESPROJECT_TOUCHPOINT.SALESPROJECT_ID", "$param.SalesprojectId_param");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/Salesproject_entity/entityfields/status/onValueChange.js b/entity/Salesproject_entity/entityfields/status/onValueChange.js
index 28c14cc18d4f2db77119a72ef8d4023eeca4d851..732eca9b0e28287bfab9cd6ab846c1cb771ef212 100644
--- a/entity/Salesproject_entity/entityfields/status/onValueChange.js
+++ b/entity/Salesproject_entity/entityfields/status/onValueChange.js
@@ -5,7 +5,8 @@ import("system.db");
 
 if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT)
 {
-    vars.set("$context.statusBefore", db.cell(SqlCondition.begin()
-                                                      .andPrepareVars("SALESPROJECT.SALESPROJECTID", "$field.SALESPROJECTID")
-                                                      .buildSql("select STATUS from SALESPROJECT", "1=2")));
+    vars.set("$context.statusBefore", newSelect("STATUS")
+                                            .from("SALESPROJECT")
+                                            .whereIfSet("SALESPROJECT.SALESPROJECTID", "$field.SALESPROJECTID")
+                                            .cell(true));
 }
diff --git a/entity/Salesproject_entity/recordcontainers/db/conditionProcess.js b/entity/Salesproject_entity/recordcontainers/db/conditionProcess.js
index 758fb672773c76beeac60ca6721d398505f50f93..507cd54e83ac2facada8bc80dae5fd6d8cbc9237 100644
--- a/entity/Salesproject_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Salesproject_entity/recordcontainers/db/conditionProcess.js
@@ -3,8 +3,7 @@ import("system.result");
 import("system.vars");
 import("Sql_lib");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(SqlCondition.begin()
-                        .andPrepareVars("SALESPROJECT.CONTACT_ID", "$param.ContactId_param")
-                        .andPrepareVars("SALESPROJECT.STATUS", "$param.Status_param")
-                        .translate("1 = 1"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(newWhereIfSet("SALESPROJECT.CONTACT_ID", "$param.ContactId_param")
+                .andIfSet("SALESPROJECT.STATUS", "$param.Status_param")
+                .toString());
\ No newline at end of file
diff --git a/entity/Salesproject_entity/recordcontainers/db/onDBDelete.js b/entity/Salesproject_entity/recordcontainers/db/onDBDelete.js
index 805d98d50d962a373d80080c279a10a9a2b34938..081b794d83a6d1cebc4f0e4b52abd1d58ff4ae28 100644
--- a/entity/Salesproject_entity/recordcontainers/db/onDBDelete.js
+++ b/entity/Salesproject_entity/recordcontainers/db/onDBDelete.js
@@ -12,10 +12,10 @@ if (currentId)
     "SALESPROJECT_TOUCHPOINT"
     ];
     
-        
     toDelete = toDelete.map(function(pTable)
     {
-        return [pTable, SqlCondition.equals(pTable + ".SALESPROJECT_ID", currentId, "1=2")];
+        var cond = newWhere(pTable + ".SALESPROJECT_ID", currentId)
+        return [pTable, cond.build()];
     });
     
     
@@ -29,10 +29,10 @@ if (currentId)
 
     toDelete = toDelete.concat(modulesToDelete.map(function(pTableComp)
     {
-        return [pTableComp, SqlCondition.begin()
-        .andPrepare(pTableComp + ".OBJECT_TYPE", ContextUtils.getCurrentContextId())
-        .andPrepare(pTableComp + ".OBJECT_ROWID", currentId)
-        .build("1=2")];
+        var cond = newWhere(pTableComp + ".OBJECT_TYPE", ContextUtils.getCurrentContextId())
+                       .and(pTableComp + ".OBJECT_ROWID", currentId)
+        
+        return [pTableComp, cond.build()];
     }));
     
     
diff --git a/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js b/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js
index 5cd8bb054ee172abdad725e8cd98e9a21da17d7f..062568e3106661d23230d469e0ee74c03b6a41c5 100644
--- a/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js
@@ -32,10 +32,10 @@ vars.get("$local.changed").forEach(function(fieldName) {
             if (state == $KeywordRegistry.salesprojectState$lost())
             {
                 // set all offers of the salesproject to lost
-                db.updateData("OFFER", ["STATUS"], null, [$KeywordRegistry.offerStatus$lost()], SqlCondition.begin()
-                                                                                                            .andPrepare("OFFER.OBJECT_ROWID", vars.getString("$local.uid"))
-                                                                                                            .andPrepare("OFFER.OBJECT_TYPE", ContextUtils.getCurrentContextId())
-                                                                                                            .build("1=2"));
+                newWhere("OFFER.OBJECT_ROWID", "$local.uid")
+                    .and("OFFER.OBJECT_TYPE", ContextUtils.getCurrentContextId())
+                    .updateData(true, ["STATUS"], null, [$KeywordRegistry.offerStatus$lost()], "OFFER");
+                    
                 _updateReasons();
                 clearReason = false;
             }
@@ -43,10 +43,10 @@ vars.get("$local.changed").forEach(function(fieldName) {
             else if (state == $KeywordRegistry.salesprojectState$order())
             {
                 // set all competitions of the salesproject to lost
-                db.updateData("COMPETITION", ["STATUS"], null, [$KeywordRegistry.competitionState$lost()], SqlCondition.begin()
-                                                                                                            .andPrepare("COMPETITION.OBJECT_ROWID", vars.getString("$local.uid"))
-                                                                                                            .andPrepare("COMPETITION.OBJECT_TYPE", ContextUtils.getCurrentContextId())
-                                                                                                            .build("1=2"));
+                newWhere("OFFER.OBJECT_ROWID", "$local.uid")
+                    .and("OFFER.OBJECT_TYPE", ContextUtils.getCurrentContextId())
+                    .updateData(true, ["STATUS"], null, [$KeywordRegistry.competitionState$lost()], "COMPETITION");
+                    
                 _updateReasons();
                 clearReason = false;
             }
@@ -60,13 +60,16 @@ vars.get("$local.changed").forEach(function(fieldName) {
                 if (!clearForecast)
                 {
                     // reset to value from db
-                    db.updateData("SALESPROJECT", ["STATUS"], null, [vars.get("$context.statusBefore")], SqlCondition.begin()
-                                                                                                            .andPrepare("SALESPROJECT.SALESPROJECTID", vars.getString("$local.uid"))
-                                                                                                            .build("1=2"));
-                } else {
+                    newWhere("SALESPROJECT.SALESPROJECTID", vars.getString("$local.uid"))
+                        .updateData(true, ["STATUS"], null, [vars.get("$context.statusBefore")], "SALESPROJECT");
+                }
+                else 
+                {
                     // do not notify as the user just got a question, if he really would like to clear the forecast
+                    newWhere("FORECAST.OBJECT_ROWID", vars.getString("$local.uid"))
+                        .deleteData(true, "FORECAST");
+                        
                     needToUpdateForecast = false;
-                    db.deleteData("FORECAST", SqlCondition.equals("FORECAST.OBJECT_ROWID", vars.getString("$local.uid"), "1=2"));
                 }                
             }
             // if state changed, but not to one of the above states
@@ -102,11 +105,17 @@ function _updateReasons()
 {
     var reasons = rowdata["SALESPROJECT.REASONS"];
     if(reasons)
-        db.updateData("SALESPROJECT", ["REASONS"], null, [reasons], SqlCondition.equals("SALESPROJECT.SALESPROJECTID", vars.getString("$local.uid"), "1=2"));
+    {
+        newWhere("SALESPROJECT.SALESPROJECTID", vars.getString("$local.uid"))
+                        .updateData(true, ["REASONS"], null, [reasons], "SALESPROJECT");
+    }
 }
 
 function _clearReasons(pReallyClear)
 {
     if (pReallyClear)
-        db.updateData("SALESPROJECT", ["REASONS"], null, [""], SqlCondition.equals("SALESPROJECT.SALESPROJECTID", vars.getString("$local.uid"), "1=2"));
+    {
+        newWhere("SALESPROJECT.SALESPROJECTID", vars.getString("$local.uid"))
+                        .updateData(true, ["REASONS"], null, [""], "SALESPROJECT");
+    }
 }
\ No newline at end of file
diff --git a/entity/SalutationDistinct_entity/recordcontainers/jdito/contentProcess.js b/entity/SalutationDistinct_entity/recordcontainers/jdito/contentProcess.js
index 2f0c02c1d198af20950d8b5d3395cd35a5af1684..74bdbab553dada557722c07088fcb3459591a14c 100644
--- a/entity/SalutationDistinct_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/SalutationDistinct_entity/recordcontainers/jdito/contentProcess.js
@@ -1,9 +1,8 @@
-import("system.vars");
 import("system.result");
-import("system.db");
 import("Sql_lib");
 
-result.object(db.table(SqlCondition.begin()
-                        .and("SALUTATION is not NULL")
-                        .andPrepareVars("SALUTATION.ISOLANGUAGE", "$param.Language_param")
-                        .buildSql("select distinct SALUTATION from SALUTATION", "1=1")));
\ No newline at end of file
+result.object(newSelect("distinct SALUTATION")
+                    .from("SALUTATION")
+                    .whereIfSet("SALUTATION.ISOLANGUAGE", "$param.Language_param")
+                    .and("SALUTATION is not NULL")
+                    .table());
\ No newline at end of file
diff --git a/entity/SalutationTitleDistinct_entity/recordcontainers/jdito/contentProcess.js b/entity/SalutationTitleDistinct_entity/recordcontainers/jdito/contentProcess.js
index 7ed68ef0baacbb096994ba8b7a84e07db2630aea..4ed5169cb77a9f055f0ec251ad4697ce625e2443 100644
--- a/entity/SalutationTitleDistinct_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/SalutationTitleDistinct_entity/recordcontainers/jdito/contentProcess.js
@@ -1,10 +1,9 @@
-import("system.vars");
 import("system.result");
-import("system.db");
 import("Sql_lib");
 
-result.object(db.table(SqlCondition.begin()
+result.object(newSelect("distinct TITLE")
+                    .from("SALUTATION")
+                    .whereIfSet("SALUTATION.SALUTATION", "$param.Salutation_param")
+                    .andIfSet("SALUTATION.ISOLANGUAGE", "$param.Language_param")
                     .and("TITLE is not NULL")
-                    .andPrepareVars("SALUTATION.SALUTATION", "$param.Salutation_param")
-                    .andPrepareVars("SALUTATION.ISOLANGUAGE", "$param.Language_param")
-                    .buildSql("select distinct TITLE from SALUTATION", "1=1")));
\ No newline at end of file
+                    .table());
\ No newline at end of file
diff --git a/entity/SerialLetterAddRecipients_entity/entityfields/recipientcontactids/valueProcess.js b/entity/SerialLetterAddRecipients_entity/entityfields/recipientcontactids/valueProcess.js
index 24da2511d991a4ba74841744f7fb3df7e07a0821..2c46f4a9539e0e7af98a6bf22b74c2a205b2722e 100644
--- a/entity/SerialLetterAddRecipients_entity/entityfields/recipientcontactids/valueProcess.js
+++ b/entity/SerialLetterAddRecipients_entity/entityfields/recipientcontactids/valueProcess.js
@@ -11,11 +11,12 @@ var contactIds = JSON.parse(vars.getString("$param.ContactIds_param"));
 var letterId = vars.get("$field.SERIALLETTER_ID");
 
 var existsQuery = "not exists(select LETTERRECIPIENTID from LETTERRECIPIENT where LETTERRECIPIENT.CONTACT_ID = CONTACT.CONTACTID and # = ?)";
-var query = SqlCondition.begin()
-    .andIn("CONTACT.CONTACTID", contactIds)
-    .andPrepare("LETTERRECIPIENT.SERIALLETTER_ID", letterId, existsQuery) //only add contacts that aren't already recipients
-    .andSqlCondition(ContactUtils.getCommRestrictionCondition($KeywordRegistry.communicationMediumCampaign$letter(), true))  //check if there's a commrestriction
-    .buildSql("select CONTACTID from CONTACT");
 
-contactIds = db.array(db.COLUMN, query); 
+contactIds = newSelect("CONTACTID")
+                .from("CONTACT")
+                .and("CONTACT.CONTACTID", contactIds, SqlBuilder.IN())
+                .and("LETTERRECIPIENT.SERIALLETTER_ID", letterId, existsQuery) //only add contacts that aren't already recipients
+                .and(ContactUtils.getCommRestrictionCondition($KeywordRegistry.communicationMediumCampaign$letter(), true)) //check if there's a commrestriction
+                .array(db.COLUMN)
+
 result.string(JSON.stringify(contactIds));
diff --git a/entity/SerialLetterAddRecipients_entity/entityfields/serialletter_id/displayValueProcess.js b/entity/SerialLetterAddRecipients_entity/entityfields/serialletter_id/displayValueProcess.js
index 5e4cef21d24f9dd3b9ba81e081ed34d5b4fc4b3c..a173e1fb24c502791a383f1680f473b6c2ce43f5 100644
--- a/entity/SerialLetterAddRecipients_entity/entityfields/serialletter_id/displayValueProcess.js
+++ b/entity/SerialLetterAddRecipients_entity/entityfields/serialletter_id/displayValueProcess.js
@@ -1,9 +1,14 @@
+import("system.result");
+import("system.result");
 import("system.vars");
 import("Sql_lib");
-import("system.db");
-import("system.result");
 
 if (vars.get("$this.value"))
-    result.string(db.cell(SqlCondition.begin().andPrepare("SERIALLETTER.SERIALLETTERID", vars.get("$this.value")).buildSql("select TITLE from SERIALLETTER")));
+{
+    result.string(newSelect("TITLE")
+        .from("SERIALLETTER")
+        .where("SERIALLETTER.SERIALLETTERID", "$this.value")
+        .cell());
+}
 else
     result.string("");
\ No newline at end of file
diff --git a/entity/SerialLetter_entity/recordcontainers/db/onDBDelete.js b/entity/SerialLetter_entity/recordcontainers/db/onDBDelete.js
index d2afc219ad55ac7beed3d3e821721af994ae6a24..f9dfc05aaee823554467d651e1076deecca49e1f 100644
--- a/entity/SerialLetter_entity/recordcontainers/db/onDBDelete.js
+++ b/entity/SerialLetter_entity/recordcontainers/db/onDBDelete.js
@@ -2,11 +2,14 @@ import("system.vars");
 import("Sql_lib");
 import("system.db");
 
-db.deleteData("LETTERRECIPIENT", SqlCondition.equals("LETTERRECIPIENT.SERIALLETTER_ID", vars.get("$local.uid"), "1=2"));
+newWhere("LETTERRECIPIENT.SERIALLETTER_ID", vars.get("$local.uid"))
+    .deleteData(true, "LETTERRECIPIENT");
+
 var SYSALIAS = SqlUtils.getBinariesAlias();
-var binaryId = db.cell(SqlCondition.begin(SYSALIAS)
-    .andPrepareVars("ASYS_BINARIES.ROW_ID", "$local.uid")
-    .buildSql("select ID from ASYS_BINARIES"), SYSALIAS);
+var binaryId = newSelect("ID", SYSALIAS)
+                    .from("ASYS_BINARIES")
+                    .where("ASYS_BINARIES.ROW_ID", "$local.uid")
+                    .cell(true);
 
 if (binaryId)
     db.deleteBinary(binaryId, SYSALIAS);
\ No newline at end of file
diff --git a/entity/SerialLetter_entity/recordcontainers/db/onDBUpdate.js b/entity/SerialLetter_entity/recordcontainers/db/onDBUpdate.js
index ca3f5562f8a4128a0347b9d5d012d82a6bf3ba14..ea6925733792cc6f299a30b0d8a39e5d3067c8ec 100644
--- a/entity/SerialLetter_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/SerialLetter_entity/recordcontainers/db/onDBUpdate.js
@@ -16,9 +16,10 @@ var template = DocumentTemplate.fromUpload(bindata);
 if (template.content)
 {
     let sysAlias = SqlUtils.getBinariesAlias();
-    var binaryId = db.cell(SqlCondition.begin(sysAlias)
-        .andPrepareVars("ASYS_BINARIES.ROW_ID", "$local.uid")
-        .buildSql("select ID from ASYS_BINARIES", "1=2"), sysAlias);
+    var binaryId = newSelect("ID", sysAlias)
+                        .from("ASYS_BINARIES")
+                        .where("ASYS_BINARIES.ROW_ID", "$local.uid")
+                        .cell(true);
         
     if (binaryId)
         db.updateBinary(binaryId, "", template.content, template.filename, "", "", sysAlias);
diff --git a/entity/Stock_entity/recordcontainers/db/conditionProcess.js b/entity/Stock_entity/recordcontainers/db/conditionProcess.js
index c14c6b016babe5709bc7a06349f3a99bd8346143..eb881a660fe9112a6d7756fe734491ad20d45165 100644
--- a/entity/Stock_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Stock_entity/recordcontainers/db/conditionProcess.js
@@ -1,9 +1,6 @@
 import("system.result");
-import("system.vars");
-import("system.db");
 import("Sql_lib");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(SqlCondition.begin()
-                          .andPrepareVars("STOCK.PRODUCT_ID", "$param.ProductId_param")
-                          .translate("1 = 0"));
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(newWhereIfSet("STOCK.PRODUCT_ID", "$param.ProductId_param")
+                .toString());
\ No newline at end of file
diff --git a/entity/SupportTicket_entity/recordcontainers/db/conditionProcess.js b/entity/SupportTicket_entity/recordcontainers/db/conditionProcess.js
index 01cc59b4278534bee4115ffaf2c41394bdc98bd0..05d2e05eca452c8c0739c7c39eaae157f6e37576 100644
--- a/entity/SupportTicket_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/SupportTicket_entity/recordcontainers/db/conditionProcess.js
@@ -5,9 +5,9 @@ import("system.result");
 import("Sql_lib");
 import("KeywordRegistry_basic");
 
-var cond = new SqlCondition();
-cond.andPrepare("TASK.KIND", $KeywordRegistry.taskType$ticket())
-    .andPrepareVars("TICKET.TICKETTYPE", "$param.TicketType_param")
+var cond = newWhere()
+            .and("TASK.KIND", $KeywordRegistry.taskType$ticket())
+            .andIfSet("TICKET.TICKETTYPE", "$param.TicketType_param")
 
 var loadNothing = false;
 
@@ -15,18 +15,19 @@ if (vars.getString("$param.FilterOnlyOwnTicket_param") == "true")
 {
     var ownContactId = EmployeeUtils.getCurrentContactId();
     if (ownContactId)
-        cond.andPrepareIfSet("TASK.EDITOR_CONTACT_ID", ownContactId);
+        cond.andIfSet("TASK.EDITOR_CONTACT_ID", ownContactId);
     else
         loadNothing = true;
 }
 
-if (vars.exists("$param.RowId_param") && vars.get("$param.RowId_param") && vars.exists("$param.ObjectId_param") && vars.get("$param.ObjectId_param"))
+if (vars.get("$param.RowId_param") && vars.get("$param.ObjectId_param"))
 {
-    var taskLinkCond = SqlCondition.begin().andPrepareVars("TASKLINK.OBJECT_ROWID", "$param.RowId_param")
-                                               .andPrepareVars("TASKLINK.OBJECT_TYPE", "$param.ObjectId_param");
-
-                                                            // TODO: more performant way than IN. Maybe a join?
-    cond.and(SqlUtils.translateStatementWithQuotes(taskLinkCond.buildSql("TASK.TASKID in (select TASKLINK.TASK_ID from TASKLINK", "1=2", ")")))
+    // TODO: more performant way than IN. Maybe a join?
+    cond.and("TASK.TASKID", newSelect("TASKLINK.TASK_ID")
+                                .from("TASKLINK")
+                                .where("TASKLINK.OBJECT_ROWID", "$param.RowId_param")
+                                .and("TASKLINK.OBJECT_TYPE", "$param.ObjectId_param")
+                            , SqlBuilder.IN());
 }
 
 if (loadNothing) 
@@ -35,6 +36,6 @@ if (loadNothing)
 }
 else
 {
-    //TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-    result.string(cond.translate("1=1"));
+    //TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+    result.string(cond.toString());
 }
\ No newline at end of file
diff --git a/entity/SupportTicket_entity/recordcontainers/db/onDBDelete.js b/entity/SupportTicket_entity/recordcontainers/db/onDBDelete.js
index 0245f4ad4d081303f5d24769a09a9ef11b745ed6..4365c0bbb83b9f5c294ef7e33e66d7374c3a3bd7 100644
--- a/entity/SupportTicket_entity/recordcontainers/db/onDBDelete.js
+++ b/entity/SupportTicket_entity/recordcontainers/db/onDBDelete.js
@@ -2,6 +2,5 @@ import("system.vars");
 import("system.db");
 import("Sql_lib");
 
-var condition = SqlCondition.begin()
-    .andPrepareVars("TASKLINK.TASK_ID", "$field.TASK_TASKID");
-db.deleteData("TASKLINK", condition.build("1=2"));
\ No newline at end of file
+newWhereIfSet("TASKLINK.TASK_ID", "$field.TASK_TASKID")
+    .deleteData(true, "TASKLINK");
\ No newline at end of file
diff --git a/entity/TaskLink_entity/recordcontainers/db/conditionProcess.js b/entity/TaskLink_entity/recordcontainers/db/conditionProcess.js
index 4e718f44637410bf704964b8fb0de5ef11f7ea05..1b4535c9556a37f6e69084f7570ea2fde14e7e6d 100644
--- a/entity/TaskLink_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/TaskLink_entity/recordcontainers/db/conditionProcess.js
@@ -1,10 +1,7 @@
-import("system.vars");
-import("system.db");
 import("system.result");
 import("Sql_lib");
 
-var cond = SqlCondition.begin()
-                       .andPrepareVars("TASKLINK.TASK_ID", "$param.TaskId_param");
+var cond = newWhereIfSet("TASKLINK.TASK_ID", "$param.TaskId_param");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(cond.translate("1 = 0"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/Task_entity/recordcontainers/db/conditionProcess.js b/entity/Task_entity/recordcontainers/db/conditionProcess.js
index d19dececad6cf1fa2361aa88a1622782fc7fc523..53cd0f2efc974ca5f2c81914c7c653ccaf83198b 100644
--- a/entity/Task_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Task_entity/recordcontainers/db/conditionProcess.js
@@ -5,8 +5,7 @@ import("system.result");
 import("Sql_lib");
 import("KeywordRegistry_basic");
 
-var cond = new SqlCondition();
-cond.andPrepare("TASK.KIND", $KeywordRegistry.taskType$task())
+var cond = newWhere("TASK.KIND", $KeywordRegistry.taskType$task())
 
 var loadNothing = false;
 
@@ -14,17 +13,18 @@ if (vars.getString("$param.FilterOnlyOwnTask_param") == "true")
 {
     var ownContactId = EmployeeUtils.getCurrentContactId();
     if (ownContactId)
-        cond.andPrepareIfSet("TASK.EDITOR_CONTACT_ID", ownContactId);
+        cond.andIfSet("TASK.EDITOR_CONTACT_ID", ownContactId);
     else
         loadNothing = true;
 }
 if (vars.exists("$param.RowId_param") && vars.get("$param.RowId_param") && vars.exists("$param.ObjectId_param") && vars.get("$param.ObjectId_param"))
 {
-    var activityLinkCond = SqlCondition.begin().andPrepareVars("TASKLINK.OBJECT_ROWID", "$param.RowId_param")
-                                               .andPrepareVars("TASKLINK.OBJECT_TYPE", "$param.ObjectId_param");
-
-                                                            // TODO: more performant way than IN. Maybe a join?
-    cond.and(SqlUtils.translateStatementWithQuotes(activityLinkCond.buildSql("TASK.TASKID in (select TASKLINK.TASK_ID from TASKLINK", "1=2", ")")))
+    // TODO: more performant way than IN. Maybe a join?
+    cond.and("TASK.TASKID", newSelect("TASKLINK.TASK_ID")
+                                .from("TASKLINK")
+                                .where("TASKLINK.OBJECT_ROWID", "$param.RowId_param")
+                                .and("TASKLINK.OBJECT_TYPE", "$param.ObjectId_param")
+                            , SqlBuilder.IN());
 }
 
 if (loadNothing)
@@ -33,7 +33,6 @@ if (loadNothing)
 }
 else
 {
-    //TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-    var resCond = cond.translate("1=1");
-    result.string(resCond);
+    //TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+    result.string(cond.toString());
 }
\ No newline at end of file
diff --git a/entity/Task_entity/recordcontainers/db/onDBDelete.js b/entity/Task_entity/recordcontainers/db/onDBDelete.js
index d19d38f6e972d7759782100f4a94d41fd3dd7944..84e02e77b17de59d0091cebe34d9e069b0b9d73d 100644
--- a/entity/Task_entity/recordcontainers/db/onDBDelete.js
+++ b/entity/Task_entity/recordcontainers/db/onDBDelete.js
@@ -2,7 +2,5 @@ import("system.vars");
 import("system.db");
 import("Sql_lib");
 
-var condition = SqlCondition.begin()
-    .andPrepareVars("TASKLINK.TASK_ID", "$field.TASKID");
-
-db.deleteData("TASKLINK", condition.build("1=2"));
\ No newline at end of file
+newWhere("TASKLINK.TASK_ID", "$field.TASKID")
+    .deleteData(true, "TASKLINK");
\ No newline at end of file
diff --git a/entity/Timetracking_entity/recordcontainers/db/conditionProcess.js b/entity/Timetracking_entity/recordcontainers/db/conditionProcess.js
index 79f47c2f3e18c79390f619a1458eedcd473da7f8..187f4a3f604b09f1b1ab3e0c0d4166865cfd5d8e 100644
--- a/entity/Timetracking_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Timetracking_entity/recordcontainers/db/conditionProcess.js
@@ -3,8 +3,7 @@ import("system.db");
 import("system.result");
 import("Sql_lib");
 
-//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-result.string(SqlCondition.begin()
-            .andPrepareVars("TIMETRACKING.OBJECT_ID", "$param.ObjectId_param")
-            .andPrepareVars("TIMETRACKING.ROW_ID", "$param.RowId_param")
-            .translate("1 = 2"));
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
+result.string(newWhereIfSet("TIMETRACKING.OBJECT_ID", "$param.ObjectId_param")
+                .andIfSet("TIMETRACKING.ROW_ID", "$param.RowId_param")
+                .toString());
\ No newline at end of file
diff --git a/entity/UnlinkedMailMappingWrapper_entity/entityfields/mailastext_param/valueProcess.js b/entity/UnlinkedMailMappingWrapper_entity/entityfields/mailastext_param/valueProcess.js
index 036eb71d8f5787718937584df763395322889b3c..1e60e708982b401e856fe5856b8031c8ec1e70c5 100644
--- a/entity/UnlinkedMailMappingWrapper_entity/entityfields/mailastext_param/valueProcess.js
+++ b/entity/UnlinkedMailMappingWrapper_entity/entityfields/mailastext_param/valueProcess.js
@@ -7,9 +7,9 @@ var res = "";
 var unlinkedMailId = vars.get("$param.UnlinkedMailId_param");
 if (unlinkedMailId)
 {
-    var mailDataSql = SqlCondition.begin()
-                                  .andPrepare("AB_UNLINKEDMAIL.AB_UNLINKEDMAILID", unlinkedMailId)
-                                  .buildSql("select AB_UNLINKEDMAIL.MAIL from AB_UNLINKEDMAIL");
-    res = db.cell(mailDataSql);
+    res = newSelect("AB_UNLINKEDMAIL.MAIL")
+                            .from("AB_UNLINKEDMAIL")
+                            .and("AB_UNLINKEDMAIL.AB_UNLINKEDMAILID", unlinkedMailId)
+                            .cell();
 }
 result.string(res);
\ No newline at end of file
diff --git a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
index 252f4f9d7679caa955f9d10b9c2607036cef6ef8..50c3cf2b3506ba026a6b09e245caf67fef07d176 100644
--- a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
+++ b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
@@ -5133,6 +5133,9 @@
     <entry>
       <key>Either or both a contact and a company must be specified</key>
     </entry>
+    <entry>
+      <key>Attribute groups can't be selected</key>
+    </entry>
   </keyValueMap>
   <font name="Dialog" style="0" size="11" />
   <sqlModels>
diff --git a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
index d834509c11a40ffde29002657ce349d5c4fc5851..77be6535b8af9354a1c7cadbfee6ab0f2d570abb 100644
--- a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
+++ b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
@@ -6445,6 +6445,7 @@
     </entry>
     <entry>
       <key>${CONTRACT_STATUS}</key>
+      <value>Vertragsstatus</value>
     </entry>
     <entry>
       <key>Time in minutes</key>
diff --git a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
index 3a8d684a03bd628054756d11bd42d184e89cabc1..135724535ae50441d2ef279762383c065e05f0e3 100644
--- a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
+++ b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
@@ -5183,6 +5183,9 @@
     <entry>
       <key>Either or both a contact and a company must be specified</key>
     </entry>
+    <entry>
+      <key>Attribute groups can't be selected</key>
+    </entry>
   </keyValueMap>
   <font name="Dialog" style="0" size="11" />
 </language>
diff --git a/neonView/PrivatePersonPreview_view/PrivatePersonPreview_view.aod b/neonView/PrivatePersonPreview_view/PrivatePersonPreview_view.aod
index b67748cb35b616d8a60f720923fcc50719292474..df872e3533f38b7c649ae69c37a292ebeb558374 100644
--- a/neonView/PrivatePersonPreview_view/PrivatePersonPreview_view.aod
+++ b/neonView/PrivatePersonPreview_view/PrivatePersonPreview_view.aod
@@ -10,7 +10,7 @@
   <children>
     <neonViewReference>
       <name>0a66aea5-bf81-47e4-941d-9158ff8f4f51</name>
-      <entityField>Contacts</entityField>
+      <entityField>Persons</entityField>
       <view>ContactTitledList_view</view>
     </neonViewReference>
   </children>
diff --git a/process/ActivityTask_lib/process.js b/process/ActivityTask_lib/process.js
index 1f427eaa2de6c226344ea2dd81108bb4e174e805..03479693220e9baa036176867baba53f2580b487 100644
--- a/process/ActivityTask_lib/process.js
+++ b/process/ActivityTask_lib/process.js
@@ -163,14 +163,14 @@ ActivityUtils.getLastActivityDate = function(pRowId)
 {
     var context = ContextUtils.getCurrentContextId();
     var sqlUtil = new SqlMaskingUtils();
-    var activitySql = "select " + sqlUtil.max("ENTRYDATE") + " from ACTIVITY "
-        + " join ACTIVITYLINK on ACTIVITY.ACTIVITYID = ACTIVITYLINK.ACTIVITY_ID";
-    activitySql = SqlCondition.begin()
-        .andPrepare("ACTIVITYLINK.OBJECT_TYPE", context)
-        .andPrepare("ACTIVITYLINK.OBJECT_ROWID", pRowId)
-        .buildSql(activitySql);
-    
-    var entryDate = db.cell(activitySql);
+
+    var entryDate = newSelect(sqlUtil.max("ENTRYDATE"))
+                        .from("ACTIVITY")
+                        .join("ACTIVITYLINK", "ACTIVITY.ACTIVITYID = ACTIVITYLINK.ACTIVITY_ID")
+                        .where("ACTIVITYLINK.OBJECT_TYPE", context)
+                        .and("ACTIVITYLINK.OBJECT_ROWID", pRowId)
+                        .cell();
+
     if (entryDate != "")
         return parseInt(entryDate);
     return null;
@@ -192,9 +192,11 @@ ActivityUtils.hasActivities = function (pRowId, pObjectType)
 {
     if (pRowId && pObjectType)
     {
-        var cond = SqlCondition.begin().andPrepare("ACTIVITYLINK.OBJECT_TYPE", pObjectType)
-                                       .andPrepare("ACTIVITYLINK.OBJECT_ROWID", pRowId);
-        var taskCount = db.cell(cond.buildSql("select count(*) from ACTIVITYLINK"));
+        var taskCount = newSelect("count(*)")
+                            .from("ACTIVITYLINK")
+                            .where("ACTIVITYLINK.OBJECT_TYPE", pObjectType)
+                            .and("ACTIVITYLINK.OBJECT_ROWID", pRowId)
+                            .cell();
         if (taskCount != "0")
             return true;
         return false;
@@ -250,9 +252,12 @@ TaskUtils.hasTasks = function(pRowId, pObjectType)
 {
     if (pRowId != "" && pObjectType != "")
     {
-        var cond = SqlCondition.begin().andPrepare("TASKLINK.OBJECT_TYPE", pObjectType)
-                                       .andPrepare("TASKLINK.OBJECT_ROWID", pRowId);
-        var taskCount = db.cell(cond.buildSql("select count(*) from TASKLINK"));
+        var taskCount = newSelect("count(*)")
+                            .from("TASKLINK")
+                            .where("TASKLINK.OBJECT_TYPE", pObjectType)
+                            .and("TASKLINK.OBJECT_ROWID", pRowId)
+                            .cell();
+                            
         if (taskCount != "0")
             return true;
         else 
@@ -281,15 +286,25 @@ TaskUtils.addLinkRecords= function(pObjectIdField, pRowIdField, pAdditionalLinks
 
 TaskUtils.getOpenTaskCount = function(pRowId, pObjectType)
 {
-    var cond = SqlCondition.begin()
-        .andPrepare("TASKLINK.OBJECT_TYPE", pObjectType)
-        .andPrepare("TASKLINK.OBJECT_ROWID", pRowId)
-        .andPrepare("TASK.STATUS", $KeywordRegistry.taskStatus$ended(), "# != ?")
-    var taskCount = db.cell(cond.buildSql("select count(*) from TASKLINK join TASK on TASKLINK.TASK_ID = TASK.TASKID"));
+    var taskCount = newSelect("count(*)")
+                        .from("TASKLINK")
+                        .join("TASK", "TASKLINK.TASK_ID = TASK.TASKID")
+                        .where("TASKLINK.OBJECT_TYPE", pObjectType)
+                        .and("TASKLINK.OBJECT_ROWID", pRowId)
+                        .and("TASK.STATUS", $KeywordRegistry.taskStatus$ended(), "# <> ?")
+                        .cell();
     
     return parseInt(taskCount);
 }
 
+/**
+ * @return all status keyIds which indicate a ended task
+ */
+TaskUtils.getEndedStatuses = function()
+{
+    return [$KeywordRegistry.taskStatus$ended(), $KeywordRegistry.taskStatus$endedDone(), $KeywordRegistry.taskStatus$endedAbandoned()]
+}
+
 /**
  * Methods used by for tasks.
  * Do not create an instance of this!
@@ -359,19 +374,23 @@ _ActivityTaskUtils._addLinkRecords = function(pObjectIdField, pRowIdField, pAddi
         switch (vars.get(pParentContextField))
         {
             case "Activity":
-                presetLinks = presetLinks.concat(db.table(SqlCondition.begin()
-                             .andPrepare("ACTIVITYLINK.ACTIVITY_ID", vars.get(pParentIdField))
-                             .buildSql("select OBJECT_TYPE, OBJECT_ROWID from ACTIVITYLINK", "1=2")));
+                presetLinks = presetLinks.concat(newSelect("OBJECT_TYPE, OBJECT_ROWID")
+                                                    .from("ACTIVITYLINK")
+                                                    .where("ACTIVITYLINK.ACTIVITY_ID", vars.get(pParentIdField))
+                                                    .table());
                 break;
             case "Task":
-                presetLinks = presetLinks.concat(db.table(SqlCondition.begin()
-                             .andPrepare("TASKLINK.TASK_ID", vars.get(pParentIdField))
-                             .buildSql("select OBJECT_TYPE, OBJECT_ROWID from TASKLINK", "1=2")));
+                presetLinks = presetLinks.concat(newSelect("OBJECT_TYPE, OBJECT_ROWID")
+                                                    .from("TASKLINK")
+                                                    .where("TASKLINK.TASK_ID", vars.get(pParentIdField))
+                                                    .table());
                 break;
             case "SupportTicket":
-                presetLinks = presetLinks.concat(db.table(SqlCondition.begin()
-                             .andPrepare("TICKET.TICKETID", vars.get(pParentIdField))
-                             .buildSql("select OBJECT_TYPE, OBJECT_ROWID from TICKET join TASKLINK on TASKLINK.TASK_ID = TICKET.TASK_ID", "1=2")));
+                presetLinks = presetLinks.concat(newSelect("OBJECT_TYPE, OBJECT_ROWID")
+                                                    .from("TICKET")
+                                                    .join("TASKLINK", "TASKLINK.TASK_ID = TICKET.TASK_ID")
+                                                    .where("TICKET.TICKETID", vars.get(pParentIdField))
+                                                    .table());
                 break;
         }
         
diff --git a/process/Attribute_lib/process.js b/process/Attribute_lib/process.js
index 73a5f9a4ac9b1085510626d84184e98e3b629a4b..78498993cd51d6210fef007ecc08ce7d31000eab 100644
--- a/process/Attribute_lib/process.js
+++ b/process/Attribute_lib/process.js
@@ -1,3 +1,4 @@
+import("system.logging");
 import("Employee_lib");
 import("KeywordData_lib");
 import("Context_lib");
@@ -58,42 +59,37 @@ AttributeUtil.getPossibleAttributes = function (pObjectType, pIncludeGroups, pFi
     if (pObjectType == null || (pFilteredAttributeIds && pFilteredAttributeIds.length == 0))
         return [];
     
-    var attrSql = "select AB_ATTRIBUTEID, ATTRIBUTE_PARENT_ID, ATTRIBUTE_TYPE from AB_ATTRIBUTE"
-        + " join AB_ATTRIBUTEUSAGE  on AB_ATTRIBUTEID = AB_ATTRIBUTE_ID";
-    var attrCond = SqlCondition.begin()
-        .andPrepare("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", pObjectType)
-        .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE, "# != ?")
-        .and("ATTRIBUTE_ACTIVE = 1");
-    
+    var attrSelect = newSelect("AB_ATTRIBUTEID, ATTRIBUTE_PARENT_ID, ATTRIBUTE_TYPE")
+                        .from("AB_ATTRIBUTE")
+                        .join("AB_ATTRIBUTEUSAGE", "AB_ATTRIBUTEID = AB_ATTRIBUTE_ID")
+                        .where("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", pObjectType)
+                        .and("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE, "# != ?")
+                        .and("ATTRIBUTE_ACTIVE = 1");
+
     if (pAttributeCount)
     {
         for (let attributeId in pAttributeCount)
         {
-            attrCond.andSqlCondition(
-                SqlCondition.begin()
-                    .orPrepare("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", attributeId, "# != ?")
-                    .orPrepare("AB_ATTRIBUTEUSAGE.MAX_COUNT", pAttributeCount[attributeId], "# > ?")
-                    .or("AB_ATTRIBUTEUSAGE.MAX_COUNT is null")
+            attrSelect.and(newWhere()
+                            .or("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", attributeId, "# != ?")
+                            .or("AB_ATTRIBUTEUSAGE.MAX_COUNT", pAttributeCount[attributeId], "# > ?")
+                            .or("AB_ATTRIBUTEUSAGE.MAX_COUNT is null")
             );
         }
     }
         
     if (pFilteredAttributeIds)
     {
-        var filteredIdsCondition = new SqlCondition();
         var filteredIdChildren = AttributeUtil.getAllChildren(pFilteredAttributeIds);
-        pFilteredAttributeIds.concat(filteredIdChildren).forEach(function(id) 
-        {
-            this.orPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", id);
-        }, filteredIdsCondition);
-
-        attrCond.andSqlCondition(filteredIdsCondition);
+        var allFilteredIds = pFilteredAttributeIds.concat(filteredIdChildren);
+        
+        attrSelect.andIfSet("AB_ATTRIBUTE.AB_ATTRIBUTEID", allFilteredIds, SqlBuilder.IN())
     }
 
     if (!pIncludeGroups)
-        attrCond.andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.GROUP, "# != ?");
+        attrSelect.and("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.GROUP, "# != ?");
     
-    var attributes = db.table(attrCond.buildSql(attrSql));
+    var attributes = attrSelect.table();
     
     //filter out groups without usable children
     if (pIncludeGroups && pAttributeCount)
@@ -134,15 +130,17 @@ AttributeUtil.getPossibleListValues = function (pAttributeId, pAttributeType, pI
     var onlyActives = (pIncludeInactives == undefined ? false : pIncludeInactives);
     if (attrType == $AttributeTypes.COMBO.toString())
     {
-        var valueSql = SqlCondition.begin()
-            .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", attributeId)
-            .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE);
-        
+        var valuesSelect = newSelect("AB_ATTRIBUTEID, ATTRIBUTE_NAME")
+                                .from("AB_ATTRIBUTE")
+                                .where("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", attributeId)
+                                .and("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE);
+                                
         if (onlyActives)
-            valueSql.andPrepare("AB_ATTRIBUTE.ATTRIBUTE_ACTIVE", "1");
+            valuesSelect.and("AB_ATTRIBUTE.ATTRIBUTE_ACTIVE", "1");
         
-        valueSql = valueSql.buildSql("select AB_ATTRIBUTEID, ATTRIBUTE_NAME from AB_ATTRIBUTE", "1=2", "order by SORTING asc");
-        var valueList = db.table(valueSql);
+        var valueList = valuesSelect.orderBy("SORTING asc")
+                                    .table();
+            
         for (let i = 0; i < valueList.length; i++)
         {
             valueList[i][1] = translate.text(valueList[i][1]);
@@ -158,20 +156,20 @@ AttributeUtil.getPossibleListValues = function (pAttributeId, pAttributeType, pI
     }
     else if (attrType == $AttributeTypes.KEYWORD.toString())
     {
-        var attrKeywordSelect = "select DROPDOWNDEFINITION from AB_ATTRIBUTE";
-        attrKeywordSelect = SqlCondition.begin()
-            .andPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", attributeId)
-            .buildSql(attrKeywordSelect);
-        var attrKeyword = db.cell(attrKeywordSelect);
+        var attrKeyword = newSelect("DROPDOWNDEFINITION")
+                                .from("AB_ATTRIBUTE")
+                                .where("AB_ATTRIBUTE.AB_ATTRIBUTEID", attributeId)
+                                .cell();
+            
         var keywords = KeywordData.getSimpleData(attrKeyword, null, onlyActives);
         return keywords;
     }
     else if (attrType == $AttributeTypes.OBJECTSELECTION)
     {
-        var [module, filter] = db.array(db.ROW, SqlCondition.begin()
-            .andPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", attributeId)
-            .buildSql("select DROPDOWNDEFINITION, DROPDOWNFILTER from AB_ATTRIBUTE")
-            );
+        var [module, filter] = newSelect("DROPDOWNDEFINITION, DROPDOWNFILTER")
+                                    .from("AB_ATTRIBUTE")
+                                    .where("AB_ATTRIBUTE.AB_ATTRIBUTEID", attributeId)
+                                    .arrayRow();
         var objects = [];
         if (module)
         {
@@ -222,13 +220,12 @@ AttributeUtil.getFullAttributeName = function (pAttributeId, pSimpleName, pTrans
     var attributeNames = [];
     var attribute;
     do {
-        attribute = db.array(db.ROW, SqlCondition.begin()
-            .andPrepare(["AB_ATTRIBUTE", "AB_ATTRIBUTEID", "ATTRIBUTE"], pAttributeId)
-            .buildSql("select ATTRIBUTE.ATTRIBUTE_NAME, PARENT1.ATTRIBUTE_NAME, PARENT2.ATTRIBUTE_NAME, PARENT2.ATTRIBUTE_PARENT_ID \n\
-                from AB_ATTRIBUTE ATTRIBUTE \n\
-                left join AB_ATTRIBUTE PARENT1 on ATTRIBUTE.ATTRIBUTE_PARENT_ID = PARENT1.AB_ATTRIBUTEID \n\
-                left join AB_ATTRIBUTE PARENT2 on PARENT1.ATTRIBUTE_PARENT_ID = PARENT2.AB_ATTRIBUTEID")
-        );
+        attribute = newSelect("ATTRIBUTE.ATTRIBUTE_NAME, PARENT1.ATTRIBUTE_NAME, PARENT2.ATTRIBUTE_NAME, PARENT2.ATTRIBUTE_PARENT_ID")
+                        .from("AB_ATTRIBUTE ATTRIBUTE")
+                        .leftJoin("AB_ATTRIBUTE PARENT1", "ATTRIBUTE.ATTRIBUTE_PARENT_ID = PARENT1.AB_ATTRIBUTEID")
+                        .leftJoin("AB_ATTRIBUTE PARENT2", "PARENT1.ATTRIBUTE_PARENT_ID = PARENT2.AB_ATTRIBUTEID")
+                        .where(["AB_ATTRIBUTE", "AB_ATTRIBUTEID", "ATTRIBUTE"], pAttributeId)
+
         if (attribute.length > 0)
         {
             attributeNames.push(attribute[0]);
@@ -262,10 +259,10 @@ AttributeUtil.getFullAttributeName = function (pAttributeId, pSimpleName, pTrans
  */
 AttributeUtil.getSimpleAttributeName = function (pAttributeId, pTranslate) 
 {
-    var attributeName = db.cell(SqlCondition.begin()
-        .andPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", pAttributeId)
-        .buildSql("select ATTRIBUTE_NAME from AB_ATTRIBUTE")
-    );
+    var attributeName = newSelect("ATTRIBUTE_NAME")
+                            .from("AB_ATTRIBUTE")
+                            .whereIfSet("AB_ATTRIBUTE.AB_ATTRIBUTEID", pAttributeId)
+                            .cell(true, "");
     if (pTranslate)
         attributeName = translate.text(attributeName);
     return attributeName;
@@ -286,10 +283,11 @@ AttributeUtil.getAllChildren = function (pAttributeIds)
         
     while (pAttributeIds.length > 0)
     {
-        pAttributeIds = db.array(db.COLUMN, SqlCondition.begin()
-            .andIn("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", pAttributeIds)
-            .buildSql("select AB_ATTRIBUTEID from AB_ATTRIBUTE")
-        );
+        pAttributeIds = newSelect("AB_ATTRIBUTEID")
+                            .from("AB_ATTRIBUTE")
+                            .where("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", pAttributeIds, SqlBuilder.IN())
+                            .arrayColumn();
+
         if (pAttributeIds.length > 0)
             childIds = childIds.concat(pAttributeIds);
     }
@@ -307,12 +305,10 @@ AttributeUtil.hasRelations = function (pAttributeId)
 {
     if (!pAttributeId)
         return false;
-    return db.cell(SqlCondition.begin()
-        .andPrepare("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID", pAttributeId)
-        .buildSql(
-            "select count(*) from AB_ATTRIBUTERELATION", "1=2" //TODO: is there a way exists could be used?
-        )
-    ) != "0";
+    return newSelect("count(*)")
+                .from("AB_ATTRIBUTERELATION")
+                .where("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID", pAttributeId)
+                .cell() != "0"; //TODO: is there a way exists could be used?
 }
 
 /**
@@ -326,27 +322,26 @@ AttributeUtil.getAttributeType = function (pAttributeId)
 {
     if (!pAttributeId)
         return "";
-    var attrTypeSelect = "select ATTRIBUTE_TYPE from AB_ATTRIBUTE";
-    attrTypeSelect = SqlCondition.begin()
-        .andPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", pAttributeId)
-        .buildSql(attrTypeSelect);
-    return db.cell(attrTypeSelect).trim();
+
+    return newSelect("ATTRIBUTE_TYPE")
+                .from("AB_ATTRIBUTE")
+                .where("AB_ATTRIBUTE.AB_ATTRIBUTEID", pAttributeId)
+                .cell()
+                .trim();
 }
 
 AttributeUtil.hasAttributes = function (pObjectType)
 {
     if (!pObjectType)
         return false;
-    return db.cell(SqlCondition.begin()
-        .andPrepare("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", pObjectType)
-        .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_ACTIVE", "1")
-        .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE, "# != ?")
-        .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.GROUP, "# != ?")
-        .buildSql(
-            "select count(*) from AB_ATTRIBUTEUSAGE \n\
-            join AB_ATTRIBUTE on AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID", "1=2"
-        )
-    ) != "0"; //TODO: is there a way exists could be used?
+    return newSelect("count(*)")
+                .from("AB_ATTRIBUTEUSAGE")
+                .join("AB_ATTRIBUTE", "AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID")
+                .where("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", pObjectType)
+                .and("AB_ATTRIBUTE.ATTRIBUTE_ACTIVE", "1")
+                .and("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE, "# != ?")
+                .and("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.GROUP, "# != ?")
+                .cell() != "0"; //TODO: is there a way exists could be used?
 }
 
 /*********************************************************************************************************************/
@@ -372,12 +367,6 @@ function AttributeRelationUtils () {}
  */
 AttributeRelationUtils.getAttribute = function (pAttributeId, pObjectRowId, pObjectType, pGetViewValue, pGetAttrname)
 {
-    var attrCond = SqlCondition.begin()
-        .andPrepare("AB_ATTRIBUTERELATION.OBJECT_ROWID", pObjectRowId)
-        .andPrepare("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID", pAttributeId);
-    if (pObjectType != null)
-        attrCond.andPrepare("AB_ATTRIBUTERELATION.OBJECT_TYPE", pObjectType);
-    
     var defaultFields = [
         "AB_ATTRIBUTE.ATTRIBUTE_TYPE", 
         "AB_ATTRIBUTE.DROPDOWNDEFINITION", 
@@ -388,11 +377,11 @@ AttributeRelationUtils.getAttribute = function (pAttributeId, pObjectRowId, pObj
         defaultFields.push("AB_ATTRIBUTE.ATTRIBUTE_NAME");    
     
     var valueFields = AttributeTypeUtil.getAllDatabaseFields();
-    var attributeSql = attrCond.buildSql("select " + defaultFields.join(", ") + ", " + valueFields.join(", ")
-        + " from AB_ATTRIBUTERELATION join AB_ATTRIBUTE on AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID"
-        + " left join AB_ATTRIBUTE COMBOVAL on " + $AttributeTypes.COMBO.databaseField + " = COMBOVAL.AB_ATTRIBUTEID");
-    
-    var attributeValues = db.array(db.ROW, attributeSql);
+
+    var attributeValues = AttributeRelationUtils.getAttributeSqlBuilder(defaultFields.concat(valueFields), pObjectRowId, pObjectType)
+                                                .and("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID", pAttributeId)
+                                                .arrayRow();
+        
     if (!attributeValues.length)
         return null;
     
@@ -408,6 +397,24 @@ AttributeRelationUtils.getAttribute = function (pAttributeId, pObjectRowId, pObj
     return value;
 }
 
+/**
+ * Get a SqlBuilder already containing the full select for attributes.
+ * @param {String[]} pFields array of all fields which should be selected
+ * @param {String} pObjectRowId object rowid
+ * @param {String} [pObjectType=null] object-type
+ * 
+ * @return {SqlBuilder} a already filled SqlBuilder
+ */
+AttributeRelationUtils.getAttributeSqlBuilder = function (pFields, pObjectRowId, pObjectType)
+{
+    return newSelect(pFields)
+                .from("AB_ATTRIBUTERELATION")
+                .join("AB_ATTRIBUTE", "AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID")
+                .leftJoin("AB_ATTRIBUTE COMBOVAL", $AttributeTypes.COMBO.databaseField + " = COMBOVAL.AB_ATTRIBUTEID")
+                .where("AB_ATTRIBUTERELATION.OBJECT_ROWID", pObjectRowId)
+                .andIfSet("AB_ATTRIBUTERELATION.OBJECT_TYPE", pObjectType);
+}
+
 /**
  * gets all attributes for a dataset
  * 
@@ -421,12 +428,7 @@ AttributeRelationUtils.getAttribute = function (pAttributeId, pObjectRowId, pObj
  * @return {String[][]} two-dimensional array a row is [attributeId|attributeName, value] (or [attributeId, attributeName, value])
  */
 AttributeRelationUtils.getAllAttributes = function (pObjectRowId, pObjectType, pUseAttributeIds, pUseIdValues)
-{
-    var attrCond = SqlCondition.begin()
-        .andPrepare("AB_ATTRIBUTERELATION.OBJECT_ROWID", pObjectRowId);
-    if (pObjectType != null)
-        attrCond.andPrepare("AB_ATTRIBUTERELATION.OBJECT_TYPE", pObjectType);
-    
+{    
     var defaultFields = [
         "AB_ATTRIBUTE_ID", 
         "AB_ATTRIBUTE.ATTRIBUTE_TYPE", 
@@ -434,12 +436,13 @@ AttributeRelationUtils.getAllAttributes = function (pObjectRowId, pObjectType, p
         "COMBOVAL.ATTRIBUTE_NAME"
     ];
     var valueFields = AttributeTypeUtil.getAllDatabaseFields();
-    var attributeSql = attrCond.buildSql("select " + defaultFields.join(", ") + ", " + valueFields.join(", ")
-        + " from AB_ATTRIBUTERELATION join AB_ATTRIBUTE on AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID"
-        + " left join AB_ATTRIBUTE COMBOVAL on " + $AttributeTypes.COMBO.databaseField + " = COMBOVAL.AB_ATTRIBUTEID");
     
     var attributeNameMap = {};
-    var attributeValues = db.table(attributeSql).map(function (row) 
+    
+    var attributeValues = AttributeRelationUtils.getAttributeSqlBuilder(defaultFields.concat(valueFields), pObjectRowId, pObjectType)
+                                                .arrayRow();
+    
+    attributeValues = attributeValues.map(function (row) 
     {
         let attribute = row[0];
         let attrname;
@@ -490,11 +493,11 @@ AttributeRelationUtils.getAllAttributes = function (pObjectRowId, pObjectType, p
  */
 AttributeRelationUtils.selectAttributeValue = function (pAttributeId, pValueMap, pGetViewValue)
 {
-    var sqlSelect = "select ATTRIBUTE_TYPE, DROPDOWNDEFINITION from AB_ATTRIBUTE";
-    var type = db.array(db.ROW, SqlCondition.begin()
-        .andPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", pAttributeId)
-        .buildSql(sqlSelect)
-    );
+    var type = newSelect("ATTRIBUTE_TYPE, DROPDOWNDEFINITION")
+                    .from("AB_ATTRIBUTE")
+                    .where("AB_ATTRIBUTE.AB_ATTRIBUTEID", pAttributeId)
+                    .arrayRow();
+                    
     if (!type.length)
         return null;
     
@@ -503,10 +506,10 @@ AttributeRelationUtils.selectAttributeValue = function (pAttributeId, pValueMap,
     var value = pValueMap[field];
     if (pGetViewValue && type[0] == $AttributeTypes.COMBO)
     {
-        value = db.cell(SqlCondition.begin()
-            .andPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", value)
-            .buildSql("select ATTRIBUTE_NAME from AB_ATTRIBUTE")
-        );
+        value = newSelect("ATTRIBUTE_NAME")
+                    .from("AB_ATTRIBUTE")
+                    .where("AB_ATTRIBUTE.AB_ATTRIBUTEID", value)
+                    .cell();
     }
     else if (pGetViewValue)
         value = AttributeTypeUtil.getAttributeViewValue(type[0], value, type[1]);
@@ -555,16 +558,16 @@ AttributeRelationUtils.insertAttribute = function (pRowId, pObjectType, pAttribu
  */
 AttributeRelationUtils.presetMandatoryAttributes = function (pObjectType, pConsumer)
 {
-    var mandatoryAttributes = db.table(
-        SqlCondition.begin()
-            .andPrepare("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", pObjectType)
-            .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE, "# <> ?")
-            .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.GROUP, "# <> ?")
-            .and("ATTRIBUTE_ACTIVE = 1")
-            .and("MIN_COUNT > 0")
-            .buildSql("select AB_ATTRIBUTE_ID, MIN_COUNT from AB_ATTRIBUTEUSAGE "
-                + "join AB_ATTRIBUTE on AB_ATTRIBUTE_ID = AB_ATTRIBUTEID")
-    );
+    var mandatoryAttributes = newSelect("AB_ATTRIBUTE_ID, MIN_COUNT")
+                                    .from("AB_ATTRIBUTEUSAGE")
+                                    .join("AB_ATTRIBUTE", "AB_ATTRIBUTE_ID = AB_ATTRIBUTEID")
+                                    .where("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", pObjectType)
+                                    .and("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE, "# <> ?")
+                                    .and("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.GROUP, "# <> ?")
+                                    .and("ATTRIBUTE_ACTIVE = 1")
+                                    .and("MIN_COUNT > 0")
+                                    .table();
+                                    
     mandatoryAttributes.forEach(function (usage)
     {
         //adding an attribute more than 20 times would be too much (having a min_count > 20 is very unlikely)
@@ -620,21 +623,21 @@ AttributeRelationUtils.validateAttributeCount = function (pRowId, pObjectType, p
             this[row.AB_ATTRIBUTE_ID] = (this[row.AB_ATTRIBUTE_ID] || 0) + 1;
         }, countObj);
     }
-    var attributeCondition = SqlCondition.begin();
-    AttributeUtil.getPossibleAttributes(pObjectType, undefined, pFilteredAttributeIds).forEach(function (attributeId)
-    {
-        this.orPrepare("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", attributeId);
-    }, attributeCondition);
     
-    var usageCondition = SqlCondition.begin()
-        .andPrepare("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", pObjectType)
-        .andSqlCondition(attributeCondition, "1=2");
+    var possibleAttributes = AttributeUtil.getPossibleAttributes(pObjectType, undefined, pFilteredAttributeIds);
+    var minMaxCounts = [];
     
-    //retrieve all min/max counts of the possible attributes
-    var minMaxCounts = db.table(usageCondition.buildSql(
-          "select AB_ATTRIBUTEID, ATTRIBUTE_NAME, MIN_COUNT, MAX_COUNT from AB_ATTRIBUTEUSAGE \
-           join AB_ATTRIBUTE on AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID", "1=2"
-    ));
+    if (possibleAttributes.length > 0)
+    {
+        var minMaxCountsSelect = newSelect("AB_ATTRIBUTEID, ATTRIBUTE_NAME, MIN_COUNT, MAX_COUNT")
+                                    .from("AB_ATTRIBUTEUSAGE")
+                                    .join("AB_ATTRIBUTE", "AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID")
+                                    .where("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", possibleAttributes, SqlBuilder.IN())
+                                    .and("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", pObjectType)
+
+        //retrieve all min/max counts of the possible attributes
+        minMaxCounts = minMaxCountsSelect.table();
+    }
         
     var validationMessage = [];
     minMaxCounts.forEach(function ([attributeId, name, minCount, maxCount])
@@ -678,15 +681,12 @@ AttributeRelationUtils.countAttributeRelations = function (pRowId, pObjectType,
     //unchanged (already stored) row ==> increase count 
     var countObj = {};
 
-    var condition = SqlCondition.begin()
-        .andPrepare("AB_ATTRIBUTERELATION.OBJECT_ROWID", pRowId)
-        .andPrepareIfSet("AB_ATTRIBUTERELATION.OBJECT_TYPE", pObjectType);
-
-    var storedAttributeRelations = db.table(condition.buildSql(
-        "select AB_ATTRIBUTERELATIONID, AB_ATTRIBUTE_ID from AB_ATTRIBUTERELATION",
-        "1=2"
-    ));
-
+    var storedAttributeRelations = newSelect("AB_ATTRIBUTERELATIONID, AB_ATTRIBUTE_ID")
+                                        .from("AB_ATTRIBUTERELATION")
+                                        .where("AB_ATTRIBUTERELATION.OBJECT_ROWID", pRowId)
+                                        .andIfSet("AB_ATTRIBUTERELATION.OBJECT_TYPE", pObjectType)
+                                        .table();
+                        
     storedAttributeRelations.forEach(function ([storedAttrRelationId, storedAttributeId]) {
         var currentAttributeId = storedAttributeId;
         //merging the data that is stored in the DB and the provided changes
@@ -1031,21 +1031,20 @@ AttributeUsageUtil.insertChildrenUsages = function (pAttributeId, pObjectType)
     var columns = ["AB_ATTRIBUTEUSAGEID", "AB_ATTRIBUTE_ID", "OBJECT_TYPE"];
     var types = db.getColumnTypes(table, columns);
     
-    var sqlSelect = "select AB_ATTRIBUTEID, "
-            + " (select count(*) from AB_ATTRIBUTEUSAGE where AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID and OBJECT_TYPE = '" 
-            + pObjectType + "') = 0 from AB_ATTRIBUTE";
-    
     var inserts = [];
     _addInserts(pAttributeId, pObjectType);
     db.inserts(inserts);
     
     function _addInserts (pAttributeId, pObjectType)
     {
-        var condition = SqlCondition.begin()
-            .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE, "# != ?")
-            .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", pAttributeId);
-        var attributes = db.table(condition.buildSql(sqlSelect));
-        
+        var attributes = newSelect("AB_ATTRIBUTEID, "
+                                + " (select count(*) from AB_ATTRIBUTEUSAGE where AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID and OBJECT_TYPE = '" 
+                                + pObjectType + "') = 0")
+                            .from("AB_ATTRIBUTE")
+                            .where("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE, "# != ?")
+                            .and("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", pAttributeId)
+                            .table();
+
         attributes.forEach(function (row)
         {
             if (row[1] == "true")
@@ -1073,45 +1072,41 @@ AttributeUsageUtil.updateChildrenUsages = function (pAttributeId, pOldObjectType
     
     var table = "AB_ATTRIBUTEUSAGE";
     
-    var countSubQuery = SqlCondition.begin()
-        .andPrepare("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", pNewObjectType)
-        .and("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID")
-        .buildSql("select count(*) from AB_ATTRIBUTEUSAGE");
+    var countSubQuery = newSelect("count(*)")
+                            .from("AB_ATTRIBUTEUSAGE")
+                            .where("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", pNewObjectType)
+                            .and("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID");
     
-    var sqlSelect = SqlBuilder.begin()
-        .select(["AB_ATTRIBUTEID", "AB_ATTRIBUTEUSAGEID", countSubQuery])
-        .from("AB_ATTRIBUTE")
-        .leftJoin("AB_ATTRIBUTEUSAGE", SqlCondition.begin()
-            .andPrepare("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", pOldObjectType)
-            .and("AB_ATTRIBUTEID = AB_ATTRIBUTE_ID"));
+    var sqlSelect = newSelect((["AB_ATTRIBUTEID", "AB_ATTRIBUTEUSAGEID", countSubQuery])
+                        .from("AB_ATTRIBUTE")
+                        .leftJoin("AB_ATTRIBUTEUSAGE", newWhere()
+                                .and("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", pOldObjectType)
+                                .and("AB_ATTRIBUTEID = AB_ATTRIBUTE_ID")));
     
-    var updateCond = SqlCondition.begin();
+    var updateCond = newWhere();
     
     //it is possible that the new objectType is already in a subordinate attribute 
     //and an update could cause a duplicate entry so one has to be deleted
-    var deleteCond = SqlCondition.begin();
+    var deleteCond = newWhere();
     
     _addUpdateIds(pAttributeId, pOldObjectType);
         
-    if (updateCond.isSet())
-        db.updateData(table, ["OBJECT_TYPE"], null, [pNewObjectType], updateCond.build("1=2"));
-    if (deleteCond.isSet())
-        db.deleteData(table, deleteCond.build("1=2"));
+    updateCond.updateData(true, ["OBJECT_TYPE"], null, [pNewObjectType], table);
+    deleteCond.deleteData(true, table);
     
     function _addUpdateIds (pAttributeId)
     {
-        var condition = SqlCondition.begin()
-            .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE, "# != ?")
-            .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", pAttributeId);
-        var query = sqlSelect.where(condition);
-        var attributes = db.table(query.build());
+        sqlSelect.and("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE, "# != ?")
+                 .and("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", pAttributeId);
+
+        var attributes = sqlSelect.table();
         
         attributes.forEach(function (row)
         {
             if (row[1] && row[2] != "0")
-                deleteCond.orPrepare("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTEUSAGEID", row[1]);
+                deleteCond.or("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTEUSAGEID", row[1]);
             else if (row[1])
-                updateCond.orPrepare("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTEUSAGEID", row[1]);
+                updateCond.or("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTEUSAGEID", row[1]);
             _addUpdateIds(row[0]);
         });
     }
@@ -1128,25 +1123,26 @@ AttributeUsageUtil.deleteChildrenUsages = function (pAttributeId, pObjectType)
 {
     var table = "AB_ATTRIBUTEUSAGE";
     
-    var sqlSelect = "select AB_ATTRIBUTEID, AB_ATTRIBUTEUSAGEID "
-        + " from AB_ATTRIBUTE left join AB_ATTRIBUTEUSAGE on AB_ATTRIBUTEID = AB_ATTRIBUTE_ID and OBJECT_TYPE = '" + pObjectType + "'";
+    var attributeSelect = newSelect("AB_ATTRIBUTE")
+                            .from("AB_ATTRIBUTEID, AB_ATTRIBUTEUSAGEID")
+                            .leftJoin("AB_ATTRIBUTEUSAGE", newWhere("AB_ATTRIBUTEID = AB_ATTRIBUTE_ID")
+                                                                .and("OBJECT_TYPE", pObjectType));
     
-    var deleteCond = SqlCondition.begin();
+    var deleteCond = newWhere;
     _addDeleteIds(pAttributeId, pObjectType);
-    if (deleteCond.isSet())
-        db.deleteData(table, deleteCond.build("1=2"));
+    
+    deleteCond.deleteData(true, table)
     
     function _addDeleteIds (pAttributeId)
     {
-        var condition = SqlCondition.begin()
-            .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE, "# != ?")
-            .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", pAttributeId);
-        var attributes = db.table(condition.buildSql(sqlSelect));
+        attributeSelect.where("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE, "# != ?")
+                       .and("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", pAttributeId);
+        var attributes = attributeSelect.table();
         
         attributes.forEach(function (row)
         {
             if (row[1])
-                deleteCond.orPrepare("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTEUSAGEID", row[1])
+                deleteCond.or("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTEUSAGEID", row[1])
             _addDeleteIds(row[0]);
         });
     }
@@ -1159,24 +1155,31 @@ AttributeUsageUtil.deleteChildrenUsages = function (pAttributeId, pObjectType)
  */
 AttributeUsageUtil.removeDuplicates = function (pAttributeId)
 {
-    var condition = SqlCondition.begin()
-        .and("exists (select AB_ATTRIBUTEUSAGEID from AB_ATTRIBUTEUSAGE AU where AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AU.AB_ATTRIBUTE_ID "
-            + "and AB_ATTRIBUTEUSAGE.OBJECT_TYPE = AU.OBJECT_TYPE and AB_ATTRIBUTEUSAGE.AB_ATTRIBUTEUSAGEID != AU.AB_ATTRIBUTEUSAGEID)");
-    if (pAttributeId)
-        condition.andPrepare("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", pAttributeId);
     
-    var duplicates = db.table(condition.buildSql("select AB_ATTRIBUTEUSAGEID, AB_ATTRIBUTE_ID, OBJECT_TYPE from AB_ATTRIBUTEUSAGE"));
+    
+    var attributeSelect = newSelect("AB_ATTRIBUTEUSAGEID, AB_ATTRIBUTE_ID, OBJECT_TYPE")
+                                .from("AB_ATTRIBUTEUSAGE")
+                                .and(null, newSelect("AB_ATTRIBUTEUSAGEID")
+                                                .from("AB_ATTRIBUTEUSAGE AU")
+                                                .where("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AU.AB_ATTRIBUTE_ID")
+                                                .and("AB_ATTRIBUTEUSAGE.OBJECT_TYPE = AU.OBJECT_TYPE")
+                                                .and("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTEUSAGEID != AU.AB_ATTRIBUTEUSAGEID"), 
+                                        SqlBuilder.EXISTS());
+                                        
+    attributeSelect.andIfSet("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", pAttributeId);
+    
+    var duplicates = attributeSelect.table();
     var usageObj = {};
-    var deleteCond = SqlCondition.begin();
+    var deleteCond = newWhere();
     
     duplicates.forEach(function (row)
     {
         if (!(row[1] in this))
             this[row[1]] = {};
         if (row[2] in this[row[1]])
-            deleteCond.orPrepare("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTEUSAGEID", row[0]);
+            deleteCond.or("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTEUSAGEID", row[0]);
         this[row[1]][row[2]] = true;
     }, usageObj);
-    if (deleteCond.isSet())
-        db.deleteData("AB_ATTRIBUTEUSAGE", deleteCond.build("1=2"));
+    
+    deleteCond.deleteData(true, "AB_ATTRIBUTEUSAGE");
 }
\ No newline at end of file
diff --git a/process/Bulkmail_lib/process.js b/process/Bulkmail_lib/process.js
index 6e7bd8c181d526bde88f611a6c960f26011858be..3e2240ee2dd14aa7d2590d3c174469b89b6818ec 100644
--- a/process/Bulkmail_lib/process.js
+++ b/process/Bulkmail_lib/process.js
@@ -52,10 +52,12 @@ BulkMailUtils.sendBulkMailOnServer = function (pBulkMailId, pTestRecipients, pUs
  */
 BulkMailUtils.sendBulkMail = function (pBulkMailId, pTestRecipients)
 {
-    var [templateId, subject, emailSender, createActivity, bulkMailName, useTemplateAttachments] = db.array(db.ROW, SqlCondition.begin()
-        .andPrepare("BULKMAIL.BULKMAILID", pBulkMailId)
-        .buildSql("select DOCUMENTTEMPLATE_ID, SUBJECT, SENDER, CREATEACTIVITIES, NAME, USE_TEMPLATE_ATTACHMENTS from BULKMAIL", "1=2")
-    );
+    var [templateId, subject, emailSender, createActivity, bulkMailName, useTemplateAttachments] = 
+                newSelect("DOCUMENTTEMPLATE_ID, SUBJECT, SENDER, CREATEACTIVITIES, NAME, USE_TEMPLATE_ATTACHMENTS")
+                    .from("BULKMAIL")
+                    .where("BULKMAIL.BULKMAILID", pBulkMailId)
+                    .arrayRow();
+
     useTemplateAttachments = useTemplateAttachments == "1";
         
     var template = BulkMailUtils.getBulkMailTemplate(pBulkMailId, templateId, true, useTemplateAttachments);
@@ -70,16 +72,13 @@ BulkMailUtils.sendBulkMail = function (pBulkMailId, pTestRecipients)
     }
     else
     {
-        recipientData = db.table(SqlBuilder.begin()
-            .select("BULKMAILRECIPIENTID, BULKMAILRECIPIENT.CONTACT_ID, BULKMAILRECIPIENT.EMAIL_ADDRESS, PERSON_ID, ORGANISATION_ID")
+        recipientData = newSelect("BULKMAILRECIPIENTID, BULKMAILRECIPIENT.CONTACT_ID, BULKMAILRECIPIENT.EMAIL_ADDRESS, PERSON_ID, ORGANISATION_ID")
             .from("CONTACT")
             .join("BULKMAILRECIPIENT", "BULKMAILRECIPIENT.CONTACT_ID = CONTACT.CONTACTID")
-            .where(SqlCondition.begin()
-                .andPrepare("BULKMAILRECIPIENT.BULKMAIL_ID", pBulkMailId)
-                .andPrepare("BULKMAILRECIPIENT.STATUS", $KeywordRegistry.bulkMailRecipientStatus$sent(), "# != ?")
-                .andSqlCondition(ContactUtils.getCommRestrictionCondition($KeywordRegistry.communicationMediumCampaign$mail(), true)))
-            .build()
-        );
+            .where("BULKMAILRECIPIENT.BULKMAIL_ID", pBulkMailId)
+            .and("BULKMAILRECIPIENT.STATUS", $KeywordRegistry.bulkMailRecipientStatus$sent(), "# != ?")
+            .and(ContactUtils.getCommRestrictionCondition($KeywordRegistry.communicationMediumCampaign$mail(), true))
+            .table();
     }
     var contactIds = recipientData.map(function (e) {return e[1];});
     var successIds = [];
@@ -122,22 +121,19 @@ BulkMailUtils.sendBulkMail = function (pBulkMailId, pTestRecipients)
             }
         }
     }
-    if (successIds.length > 0)
-        db.updateData("BULKMAILRECIPIENT", ["STATUS", "SENTDATE"], null, [$KeywordRegistry.bulkMailRecipientStatus$sent(), sentDate], 
-            SqlCondition.begin()
-                .andIn("BULKMAILRECIPIENT.BULKMAILRECIPIENTID", successIds)
-                .build("1=2")
-        );
-    if (failedIds.length > 0)
-        db.updateData("BULKMAILRECIPIENT", ["STATUS", "SENTDATE"], null, [$KeywordRegistry.bulkMailRecipientStatus$failed(), sentDate], 
-            SqlCondition.begin()
-                .andIn("BULKMAILRECIPIENT.BULKMAILRECIPIENTID", failedIds)
-                .build("1=2")
-        );
+    
+    newWhereIfSet("BULKMAILRECIPIENT.BULKMAILRECIPIENTID", successIds, SqlBuilder.In())
+        .updateData(true, ["STATUS", "SENTDATE"], null, [$KeywordRegistry.bulkMailRecipientStatus$sent(), sentDate], "BULKMAILRECIPIENT");
+    
+    
+    newWhereIfSet("BULKMAILRECIPIENT.BULKMAILRECIPIENTID", failedIds, SqlBuilder.In())
+        .updateData(true, ["STATUS", "SENTDATE"], null, [$KeywordRegistry.bulkMailRecipientStatus$failed(), sentDate], "BULKMAILRECIPIENT");
     
     if (!pTestRecipients) //if its just a test run, don't set the status to sent
-        db.updateData("BULKMAIL", ["STATUS"], null, [$KeywordRegistry.bulkMailStatus$sent()], 
-            SqlCondition.equals("BULKMAIL.BULKMAILID", pBulkMailId, "1=2"));
+    {
+        newWhere("BULKMAIL.BULKMAILID", pBulkMailId)
+            .updateData(true, ["STATUS"], null, [$KeywordRegistry.bulkMailStatus$sent()], "BULKMAIL");
+    }
         
     return {
         sucessful : successIds.length,
@@ -165,22 +161,16 @@ BulkMailUtils.openAddRecipientView = function (pContactIds)
  */
 BulkMailUtils.removeCommRestrictionRecipients = function (pBulkMailId)
 {
-    var recipientIds = db.array(db.COLUMN, SqlBuilder.begin()
-        .select("BULKMAILRECIPIENTID")
+    var recipientIds = newSelect("BULKMAILRECIPIENTID")
         .from("BULKMAILRECIPIENT")
-        .join("CONTACT", SqlCondition.begin()
-            .and("BULKMAILRECIPIENT.CONTACT_ID = CONTACT.CONTACTID")
-            .andSqlCondition(ContactUtils.getCommRestrictionCondition($KeywordRegistry.communicationMediumCampaign$mail())))
-        .where(SqlCondition.begin()
-            .andPrepare("BULKMAILRECIPIENT.BULKMAIL_ID", pBulkMailId))
-        .build());
+        .join("CONTACT", newWhere()
+                .and("BULKMAILRECIPIENT.CONTACT_ID = CONTACT.CONTACTID")
+                .and(ContactUtils.getCommRestrictionCondition($KeywordRegistry.communicationMediumCampaign$mail())))
+        .where("BULKMAILRECIPIENT.BULKMAIL_ID", pBulkMailId)
+        .arrayColumn();
 
-    if (recipientIds.length)
-    {
-        db.deleteData("BULKMAILRECIPIENT", SqlCondition.begin()
-            .andIn("BULKMAILRECIPIENT.BULKMAILRECIPIENTID", recipientIds)
-            .build("1=2"));
-    }
+    newWhereIfSet("BULKMAILRECIPIENT.BULKMAILRECIPIENTID", recipientIds, SqlBuilder.In())
+        .deleteData(true, "BULKMAILRECIPIENT");
 }
 
 /**
@@ -198,19 +188,21 @@ BulkMailUtils.addRecipients = function (pBulkMailId, pContactIds)
         "STATUS",
         "EMAIL_ADDRESS"
     ];
-    var contactData = db.table(SqlBuilder.begin()
-        .select(["CONTACTID", "(" + CommUtil.getStandardSubSqlMail(SqlCondition.begin().and("COMMUNICATION.CONTACT_ID = CONTACTID")) + ")"])
-        .from("CONTACT")
-        .where(SqlCondition.begin()
-            .andIn("CONTACT.CONTACTID", pContactIds)
-            .build("1=2"))
-        .build());
-    var inserts = [];
-    for (let i = 0, l = contactData.length; i < l; i++)
+    
+    if(pContactIds.length > 0)
     {
-        inserts.push(["BULKMAILRECIPIENT", columns, null, [util.getNewUUID(), pBulkMailId, contactData[i][0], $KeywordRegistry.bulkMailRecipientStatus$pending(), contactData[i][1]]]);
+        var contactData = newSelect(["CONTACTID", "(" + CommUtil.getStandardSubSqlMail(newWhere("COMMUNICATION.CONTACT_ID = CONTACTID")) + ")"])
+            .from("CONTACT")
+            .where("CONTACT.CONTACTID", pContactIds, SqlBuilder.IN())
+            .table();
+        
+        var inserts = contactData.map(function(pContact)
+        {
+            return ["BULKMAILRECIPIENT", columns, null, [util.getNewUUID(), pBulkMailId, pContact[0], $KeywordRegistry.bulkMailRecipientStatus$pending(), pContact[1]]];
+        });
+        
+        db.inserts(inserts);
     }
-    db.inserts(inserts);
 }
 
 /**
@@ -252,12 +244,12 @@ BulkMailUtils.getBulkMailTemplate = function (pBulkMailId, pDocumentTemplateId,
  */
 BulkMailUtils.isRecipient = function (pBulkMailId, pContactId, pRecipientId)
 {
-    return db.cell(SqlCondition.begin()
-        .andPrepare("BULKMAILRECIPIENT.CONTACT_ID", pContactId)
-        .andPrepare("BULKMAILRECIPIENT.BULKMAIL_ID", pBulkMailId)
-        .andPrepareIfSet("BULKMAILRECIPIENT.BULKMAILRECIPIENTID", pRecipientId, "# != ?")
-        .buildSql("select count(*) from BULKMAILRECIPIENT") //TODO: is there a way exists could be used?
-    ) != "0";
+    return newSelect("count(*)")
+                .from("BULKMAILRECIPIENT")
+                .where("BULKMAILRECIPIENT.CONTACT_ID", pContactId)
+                .and("BULKMAILRECIPIENT.BULKMAIL_ID", pBulkMailId)
+                .andIfSet("BULKMAILRECIPIENT.BULKMAILRECIPIENTID", pRecipientId, "# != ?")
+                .cell() != "0"; //TODO: is there a way exists could be used?
 }
 
 /**
@@ -283,14 +275,18 @@ BulkMailUtils.newBulkMail = function (pRecipients)
  */
 BulkMailUtils.filterNewRecipients = function (pBulkMailId, pContactIds)
 {
-    var existsQuery = "not exists(select BULKMAILRECIPIENTID from BULKMAILRECIPIENT where BULKMAILRECIPIENT.CONTACT_ID = CONTACT.CONTACTID and # = ?)";
-    var query = SqlCondition.begin()
-        .andIn("CONTACT.CONTACTID", pContactIds)
-        .andPrepare("BULKMAILRECIPIENT.BULKMAIL_ID", pBulkMailId, existsQuery) //only add contacts that aren't already recipients
-        .andSqlCondition(ContactUtils.getCommRestrictionCondition($KeywordRegistry.communicationMediumCampaign$mail(), true))  //check if there's a commrestriction
-        .buildSql("select CONTACTID from CONTACT");
-
-    return db.array(db.COLUMN, query); 
+    return newSelect("CONTACTID")
+                .from("CONTACT")
+                .whereIfSet("CONTACT.CONTACTID", pContactIds, SqlBuilder.IN())
+                // only add contacts that aren't already recipients
+                .and(null, newSelect("BULKMAILRECIPIENTID")
+                                .from("BULKMAILRECIPIENT")
+                                .where("BULKMAILRECIPIENT.CONTACT_ID = CONTACT.CONTACTID")
+                                .and("BULKMAILRECIPIENT.BULKMAIL_ID", pBulkMailId)
+                        , SqlBuilder.NOT_EXISTS())
+                // check if there's a commrestriction
+                .and(ContactUtils.getCommRestrictionCondition($KeywordRegistry.communicationMediumCampaign$mail(), true))  
+                .arrayColumn();
 }
 
 /**
@@ -410,12 +406,12 @@ SerialLetterUtils.buildSerialLetter = function (pSerialLetterId, pRecipientIds)
  */
 SerialLetterUtils.isRecipient = function (pSerialLetterId, pContactId, pRecipientId)
 {
-    return db.cell(SqlCondition.begin()
-        .andPrepare("LETTERRECIPIENT.CONTACT_ID", pContactId)
-        .andPrepare("LETTERRECIPIENT.SERIALLETTER_ID", pSerialLetterId)
-        .andPrepareIfSet("LETTERRECIPIENT.LETTERRECIPIENTID", pRecipientId, "# != ?")
-        .buildSql("select count(*) from LETTERRECIPIENT") //TODO: is there a way exists could be used?
-    ) != "0";
+    return newSelect("count(*)")
+                .from("LETTERRECIPIENT")
+                .where("LETTERRECIPIENT.CONTACT_ID", pContactId)
+                .and("LETTERRECIPIENT.SERIALLETTER_ID", pSerialLetterId)
+                .andIfSet("LETTERRECIPIENT.LETTERRECIPIENTID", pRecipientId, "# != ?")
+                .cell() != "0"; // TODO: is there a way exists could be used?
 }
 
 SerialLetterUtils.openSerialLetter = function (pSerialLetterId)
diff --git a/process/Campaign_lib/process.js b/process/Campaign_lib/process.js
index 48bc233b1aae6ec7cc7b8cb5945f0c5d4ac38f5f..9aca38dfa39b62d1044613f5a3ea2e92f97121cd 100644
--- a/process/Campaign_lib/process.js
+++ b/process/Campaign_lib/process.js
@@ -55,11 +55,10 @@ CampaignUtils.addParticipantsByCondition = function(pCondition, pSourceTableName
  */
 CampaignUtils.getCampaignNameById = function(pCampaignId)
 {
-    let selectQuery = "select CAMPAIGN.NAME from CAMPAIGN";
-    let conditionField = "CAMPAIGN.CAMPAIGNID";
-    let defaultValue = "";
-    
-    return _CampaignUtils._loadSingleValueFromDb(selectQuery, conditionField, pCampaignId, defaultValue);
+    return newSelect("CAMPAIGN.NAME")
+        .from("CAMPAIGN")
+        .whereIfSet("CAMPAIGN.CAMPAIGNID", pCampaignId)
+        .cell(true);
 }
 
 /**
@@ -68,11 +67,10 @@ CampaignUtils.getCampaignNameById = function(pCampaignId)
  */
 CampaignUtils.getCampaignStepNameById = function(pCampaignStepId)
 {
-    let selectQuery = "select CAMPAIGNSTEP.NAME from CAMPAIGNSTEP";
-    let conditionField = "CAMPAIGNSTEP.CAMPAIGNSTEPID";
-    let defaultValue = "";
-    
-    return _CampaignUtils._loadSingleValueFromDb(selectQuery, conditionField, pCampaignStepId, defaultValue);
+    return newSelect("CAMPAIGNSTEP.NAME")
+        .from("CAMPAIGNSTEP")
+        .whereIfSet("CAMPAIGNSTEP.CAMPAIGNSTEPID", pCampaignStepId)
+        .cell(true);
 }
 
 /**
@@ -81,11 +79,10 @@ CampaignUtils.getCampaignStepNameById = function(pCampaignStepId)
  */
 CampaignUtils.getParticipantCountForStep = function(pCampaignStepId)
 {
-    let selectQuery = "select count(*) from CAMPAIGNPARTICIPANT";
-    let conditionField = "CAMPAIGNPARTICIPANT.CAMPAIGNSTEP_ID";
-    let defaultValue = 0;
-    
-    return _CampaignUtils._loadSingleValueFromDb(selectQuery, conditionField, pCampaignStepId, defaultValue);
+    return newSelect("count(*)")
+        .from("CAMPAIGNPARTICIPANT")
+        .whereIfSet("CAMPAIGNPARTICIPANT.CAMPAIGNSTEP_ID", pCampaignStepId)
+        .cell(true, 0);
 }
 
 /**
@@ -94,11 +91,10 @@ CampaignUtils.getParticipantCountForStep = function(pCampaignStepId)
  */
 CampaignUtils.getParticipantCount = function(pCampaignId)
 {
-    let selectQuery = "select count(*) from CAMPAIGNPARTICIPANT";
-    let conditionField = "CAMPAIGNPARTICIPANT.CAMPAIGN_ID";
-    let defaultValue = 0;
-
-    return _CampaignUtils._loadSingleValueFromDb(selectQuery, conditionField, pCampaignId, defaultValue);
+    return newSelect("count(*)")
+        .from("CAMPAIGNPARTICIPANT")
+        .whereIfSet("CAMPAIGNPARTICIPANT.CAMPAIGN_ID", pCampaignId)
+        .cell(true, 0);
 }
 
 /**
@@ -107,30 +103,27 @@ CampaignUtils.getParticipantCount = function(pCampaignId)
  */
 CampaignUtils.getMaxParticipantCountForStep = function(pCampaignStepId)
 {
-    let selectQuery = "select MAXPARTICIPANTS from CAMPAIGNSTEP";
-    let conditionField = "CAMPAIGNSTEP.CAMPAIGNSTEPID";
-    let defaultValue = 0;
-    
-    return _CampaignUtils._loadSingleValueFromDb(selectQuery, conditionField, pCampaignStepId, defaultValue);
+    return newSelect("MAXPARTICIPANTS")
+        .from("CAMPAIGNSTEP")
+        .whereIfSet("CAMPAIGNSTEP.CAMPAIGNSTEPID", pCampaignStepId)
+        .cell(true, 0);
 }
 
 CampaignUtils.getStepCount = function(pCampaignId)
 {
-    let selectQuery = "select count(*) from CAMPAIGNSTEP";
-    let conditionField = "CAMPAIGNSTEP.CAMPAIGN_ID";
-    let defaultValue = 0;
-
-    return _CampaignUtils._loadSingleValueFromDb(selectQuery, conditionField, pCampaignId, defaultValue);
+    return newSelect("count(*)")
+        .from("CAMPAIGNSTEP")
+        .whereIfSet("CAMPAIGNSTEP.CAMPAIGN_ID", pCampaignId)
+        .cell(true, 0);
 }
 
 CampaignUtils.getCampaignStatusByCampaignId = function(pCampaignId)
 {
-    let selectQuery = "select CAMPAIGN.STATUS from CAMPAIGN";
-    let conditionField = "CAMPAIGN.CAMPAIGNID";
-    let defaultValue = "";
-    
     let campaignState = $KeywordRegistry.campaignState();
-    let statusId = _CampaignUtils._loadSingleValueFromDb(selectQuery, conditionField, pCampaignId, defaultValue);
+    let statusId = newSelect("CAMPAIGN.STATUS")
+        .from("CAMPAIGN")
+        .whereIfSet("CAMPAIGN.CAMPAIGNID", pCampaignId)
+        .cell(true);
     return KeywordUtils.getViewValue(campaignState, statusId);
 }
 
@@ -208,17 +201,20 @@ CampaignUtils.getDefaultCampaignStep = function(pCampaignId)
 
 CampaignUtils.getCampaignStartDate = function(pCapmaignId)
 {
-    let campaignIdCondition = SqlCondition.begin()
-                                         .andPrepare("CAMPAIGNSTEP.CAMPAIGN_ID", pCapmaignId);
-    return db.cell(campaignIdCondition.buildSql("SELECT DATE_START, SORTING FROM CAMPAIGNSTEP", "1=2", "order by SORTING ASC"));
+    return newSelect("DATE_START")
+        .from("CAMPAIGNSTEP")
+        .whereIfSet("CAMPAIGNSTEP.CAMPAIGN_ID", pCapmaignId)
+        .orderBy("SORTING ASC")
+        .cell(true);
 }
 
 CampaignUtils.getCampaignEndDate = function(pCapmaignId)
 {
-    let campaignIdCondition = SqlCondition.begin()
-                                         .andPrepare("CAMPAIGNSTEP.CAMPAIGN_ID", pCapmaignId);
-
-    return db.cell(campaignIdCondition.buildSql("SELECT DATE_END, SORTING FROM CAMPAIGNSTEP", "1=2", "order by SORTING DESC"));
+    return newSelect("DATE_END")
+        .from("CAMPAIGNSTEP")
+        .whereIfSet("CAMPAIGNSTEP.CAMPAIGN_ID", pCapmaignId)
+        .orderBy("SORTING DESC")
+        .cell(true);
 }
 
 CampaignUtils.getMaxParticipantsValidationMessage = function()
@@ -286,40 +282,60 @@ CampaignUtils.updateCampaignStep = function(pCampaignStepId, pDateStart, pDateEn
     
     let columnsToUpdate = ["DATE_START", "DATE_END"];
     let newValues = [pDateStart, pDateEnd];
-    let campaignStepIdCondition = SqlCondition.equals("CAMPAIGNSTEP.CAMPAIGNSTEPID", pCampaignStepId, "1=2")
+    let campaignStepIdCondition = newWhere("CAMPAIGNSTEP.CAMPAIGNSTEPID", pCampaignStepId).from("CAMPAIGNSTEP");
     
-    db.updateData("CAMPAIGNSTEP", columnsToUpdate, null, newValues, campaignStepIdCondition)
+    campaignStepIdCondition.updateData(true, columnsToUpdate, null, newValues);
 }
 CampaignUtils.checkforCommRestrictions = function(contactid, campaignstepid)
 {
-    return db.cell(SqlCondition.begin()
-                .andPrepare("COMMRESTRICTION.CONTACT_ID", contactid)
-                .andPrepare("CAMPAIGNSTEP.CAMPAIGNSTEPID", campaignstepid)
-                .buildSql("select MEDIUM from CAMPAIGNSTEP join COMMRESTRICTION on MEDIUM = STEPMEDIUM", "1=2"));
+    return newSelect("MEDIUM")
+        .from("CAMPAIGNSTEP")
+        .where("COMMRESTRICTION.CONTACT_ID", contactid)
+        .join("COMMRESTRICTION", "MEDIUM = STEPMEDIUM")
+        .and("CAMPAIGNSTEP.CAMPAIGNSTEPID", campaignstepid)
+        .cell();
 }
 
 /**
- * @param {SqlCondition} pWhereCondition an SqlCondition object containing a condition to select from campaignparticipant
+ * @param {SqlBuilder} pWhereCondition an SqlBuilder object containing a condition to select from campaignparticipant
  * @return {String} the counts (as string)
  */
 CampaignUtils.GetParticipantsCountByCondition = function(pWhereCondition)
 {   
-    return db.cell(pWhereCondition.buildSql("SELECT COUNT(*) FROM CAMPAIGNPARTICIPANT", "1=2"));
+    return newSelect("COUNT(*)")
+                .from("CAMPAIGNPARTICIPANT")
+                // use .build("1=2") to get result of count(*) = 0 if pWhereCondition contains no condition. 
+                // If pWhereCondition would be used directly, 
+                // .cell() would return number of all participants and
+                // .cell(true) would return an empty string "", not 0
+                .where(pWhereCondition.build("1=2")) 
+                .cell();
 }
 
+/**
+ * @param {SqlBuilder} pWhereCondition
+ * @param {Boolean} pRightJoinContacts
+ * @return {String} the counts (as string)
+ */
 CampaignUtils.GetParticipantsAlreadyAddedCountByCondition = function(pWhereCondition, pRightJoinContacts)
 {
-    let selectSql = "select count(*) from PERSON"
+    let select = newSelect("count(*)")
+                    .from("PERSON")
     
+    let joinPrefix = "";
     if(pRightJoinContacts == "true")
-        selectSql += " right"
+        joinPrefix = "right";
     
-    selectSql += " join CONTACT on (CONTACT.PERSON_ID = PERSON.PERSONID)"
-    + " join ORGANISATION on (ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID)"
-    + " left join ADDRESS on (ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID)"
-    + " left join CAMPAIGNPARTICIPANT on CAMPAIGNPARTICIPANT.CONTACT_ID = CONTACT.CONTACTID"
-
-    return db.cell(pWhereCondition.buildSql(selectSql, "1=2"))
+    select.join("CONTACT", newWhere("CONTACT.PERSON_ID = PERSON.PERSONID"), undefined, joinPrefix)
+          .leftJoin("ADDRESS", newWhere("ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID"))
+          .leftJoin("CAMPAIGNPARTICIPANT", newWhere("CAMPAIGNPARTICIPANT.CONTACT_ID = CONTACT.CONTACTID"))
+          // use .build("1=2") to get result of count(*) = 0 if pWhereCondition contains no condition. 
+          // If pWhereCondition would be used directly, 
+          // .cell() would return number of all participants and
+          // .cell(true) would return an empty string "", not 0
+          .where(pWhereCondition.build("1=2"))
+          
+    return select.cell();
 }
 
 CampaignUtils.GetContactIdsNotInCampaignByRowIds = function(pCampaignId, pParticipantRowIds)
@@ -421,11 +437,9 @@ CampaignUtils.copyCampaign = function(pCampaignid, pDescription, pEmplContactId,
  */
 CampaignUtils.copyCampaignSteps = function(pSourceCampaignId, pTargetCampaignId)
 {
-        var InputMapping = {
+    var InputMapping = {
         "CAMPAIGNSTEP": {
-            condition: SqlUtils.translateConditionWithQuotes(SqlCondition().begin()
-                            .andPrepare("CAMPAIGN.CAMPAIGN_ID", pSourceCampaignId)
-                            .buildSql("", "1=2", "order by SORTING", false)),
+            condition: newWhere("CAMPAIGN.CAMPAIGN_ID", pSourceCampaignId).orderBy("SORTING").toString(),
             ValueMapping: {
                 "CAMPAIGN_ID" : pTargetCampaignId
             }
@@ -501,15 +515,3 @@ _CampaignUtils._convertToSqlValuesList = function(pValuesArray)
     rowIds += ")";
     return rowIds;
 }
-
-_CampaignUtils._loadSingleValueFromDb = function(pSelectQuery, pConditionField, pConditionValue, pDefaultValue)
-{
-    let res = pDefaultValue;
-    if (pConditionValue)
-    {
-        res = db.cell(SqlCondition.begin()
-                                  .andPrepare(pConditionField, pConditionValue)
-                                  .buildSql(pSelectQuery));
-    }
-    return res;
-}
\ No newline at end of file
diff --git a/process/Classification_lib/process.js b/process/Classification_lib/process.js
index f49ed47099fa0e99f715c5dcc9dbbc6ddc29ea51..4364c1aaecc458b9b7132135b446635aa9134059 100644
--- a/process/Classification_lib/process.js
+++ b/process/Classification_lib/process.js
@@ -22,16 +22,18 @@ function ClassificationUtils() {}
  */
 ClassificationUtils.getScore = function(pClassificationType, pObjectType, pObjectRowid, pClassificationGroup)
 {
-    var score = db.table(SqlCondition.begin()
-                                     .andPrepare("CLASSIFICATIONTYPE.CLASSIFICATIONTYPE", pClassificationType)
-                                     .andPrepareIfSet("CLASSIFICATIONTYPE.CLASSIFICATIONGROUP", pClassificationGroup)
-                                     .buildSql("select CLASSIFICATIONTYPE.CLASSIFICATIONGROUP, case when sum(score) is not null then sum(score) else 0 end from CLASSIFICATIONTYPE "
-                                                + SqlUtils.translateStatementWithQuotes(SqlCondition.begin()
-                                                                                    .andPrepare("CLASSIFICATION.OBJECT_TYPE", pObjectType)
-                                                                                    .andPrepare("CLASSIFICATION.OBJECT_ROWID", pObjectRowid)
-                                                                                    .buildSql("left join CLASSIFICATION on CLASSIFICATIONTYPEID = CLASSIFICATIONTYPE_ID and", "1=2", "", false))
-                                                + "left join CLASSIFICATIONSCORE on CLASSIFICATIONSCORE_ID = CLASSIFICATIONSCOREID", "1=2",
-                                                "group by CLASSIFICATIONGROUP order by CLASSIFICATIONGROUP"))
+    var score = newSelect("CLASSIFICATIONTYPE.CLASSIFICATIONGROUP, case when sum(score) is not null then sum(score) else 0 end")
+        .from("CLASSIFICATIONTYPE")
+        .leftJoin("CLASSIFICATION", newWhere("CLASSIFICATIONTYPEID = CLASSIFICATIONTYPE_ID")
+            .and("CLASSIFICATION.OBJECT_TYPE", pObjectType)
+            .and("CLASSIFICATION.OBJECT_ROWID", pObjectRowid))
+        .leftJoin("CLASSIFICATIONSCORE", "CLASSIFICATIONSCORE_ID = CLASSIFICATIONSCOREID")
+        .where("CLASSIFICATIONTYPE.CLASSIFICATIONTYPE", pClassificationType)
+        .andIfSet("CLASSIFICATIONTYPE.CLASSIFICATIONGROUP", pClassificationGroup)
+        .groupBy("CLASSIFICATIONGROUP")
+        .orderBy("CLASSIFICATIONGROUP")
+        .table();
+        
     var scores = {};
     score.forEach(function(pRow)
     {
@@ -93,14 +95,16 @@ ClassificationUtils.mapToClass = function(pScore)
  */
 ClassificationUtils.getAllGroups = function(pClassificationtype, pTwoCol)
 {
-    var sql = SqlCondition.begin()
-                .andPrepare("CLASSIFICATIONTYPE.CLASSIFICATIONTYPE", pClassificationtype)
-                .buildSql("select distinct CLASSIFICATIONGROUP" + (pTwoCol ? ", CLASSIFICATIONGROUP" : "") + " from CLASSIFICATIONTYPE", "", " order by CLASSIFICATIONGROUP")
+    var sql = new SqlBuilder()
+        .selectDistinct(["CLASSIFICATIONGROUP", (pTwoCol ? "CLASSIFICATIONGROUP" : "")])
+        .from("CLASSIFICATIONTYPE")
+        .where("CLASSIFICATIONTYPE.CLASSIFICATIONTYPE", pClassificationtype)
+        .orderBy("CLASSIFICATIONGROUP");
     
     if (pTwoCol)
-        return db.table(sql);
+        return sql.table();
     else
-        return db.array(db.COLUMN, sql);
+        return sql.arrayColumn();
 }
 
 /**
@@ -110,9 +114,11 @@ ClassificationUtils.getAllGroups = function(pClassificationtype, pTwoCol)
  */
 ClassificationUtils.getGroupFromDb = function(pClassificationtypeId)
 {
-    return db.cell(SqlCondition.begin()
-                .andPrepare("CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID", pClassificationtypeId)
-                .buildSql("select CLASSIFICATIONGROUP from CLASSIFICATIONTYPE", "", " order by CLASSIFICATIONGROUP"))
+    return newSelect("CLASSIFICATIONGROUP")
+        .from("CLASSIFICATIONTYPE")
+        .where("CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID", pClassificationtypeId)
+        .orderBy("CLASSIFICATIONGROUP")
+        .cell();
 }
 
 /**
@@ -129,7 +135,8 @@ ClassificationUtils.changeGroupName = function(pOldName, pNewName, pClassificati
                 
     if (groups.indexOf(pNewName, 0) == -1)
     {
-        db.updateData("CLASSIFICATIONTYPE", ["CLASSIFICATIONGROUP"], null, [pNewName], SqlCondition.equals("CLASSIFICATIONTYPE.CLASSIFICATIONGROUP", pOldName, "1=2"));
+        newWhere("CLASSIFICATIONTYPE.CLASSIFICATIONGROUP", pOldName)
+            .updateData(true, ["CLASSIFICATIONGROUP"], null, [pNewName], "CLASSIFICATIONTYPE");
     }
 }
 
@@ -164,5 +171,6 @@ ClassificationUtils.getUsageType = function(pParamField, pSelectionField)
  */
 ClassificationUtils.changeScoreName = function(pNewScoreName, pClassificationTypeId)
 {
-    db.updateData("CLASSIFICATIONTYPE", ["SCORETYPE"], null, [pNewScoreName], SqlCondition.equals("CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID", pClassificationTypeId, "1=2"));
+    newWhere("CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID", pClassificationTypeId)
+        .updateData(true, ["SCORETYPE"], null, [pNewScoreName], "CLASSIFICATIONTYPE");
 }
\ No newline at end of file
diff --git a/process/Communication_lib/process.js b/process/Communication_lib/process.js
index fccd20c99071cf8af874fa16c7493215a5bcfa87..05aa83f61f043ca118d03bd8cddc935b6a057170 100644
--- a/process/Communication_lib/process.js
+++ b/process/Communication_lib/process.js
@@ -25,15 +25,13 @@ function CommUtil(){}
 CommUtil.getMediumIdsByCategory = function (pCategory)
 {
     var keywordAttr = new KeywordAttribute($KeywordRegistry.communicationMedium(), "category");
-    //TODO: waiting for load entity via JDito
-    var sql = SqlCondition.begin()
-                            .andPrepare("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ATTRIBUTE_ID", keywordAttr.id)
-                            .andPrepare("AB_KEYWORD_ATTRIBUTERELATION." + keywordAttr.dbField, pCategory)
-                            .buildSql("select AB_KEYWORD_ENTRY.KEYID \n\
-                                        from AB_KEYWORD_ATTRIBUTERELATION \n\
-                                        join AB_KEYWORD_ENTRY on AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID = AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID");
-
-    var mediumIds = db.array(db.COLUMN, sql);
+    //TODO: use getRows() via JDito
+    var mediumIds = newSelect("AB_KEYWORD_ENTRY.KEYID")
+                        .from("AB_KEYWORD_ATTRIBUTERELATION")
+                        .join("AB_KEYWORD_ENTRY", "AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID = AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID")
+                        .where("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ATTRIBUTE_ID", keywordAttr.id)
+                        .and("AB_KEYWORD_ATTRIBUTERELATION." + keywordAttr.dbField, pCategory)
+                        .arrayColumn();
     return mediumIds;
 };
 
@@ -59,18 +57,19 @@ CommUtil.setStandardForCategory = function(pAffectedRowId, pNewStandardCommId, p
     var types = db.getColumnTypes("COMMUNICATION", cols);
     
     //set current standard comm-record as non-standard
-    var cond = SqlCondition.begin().and("ISSTANDARD = 1").andPrepare("COMMUNICATION.CONTACT_ID", pAffectedRowId);
-    //mediumIds cannot be empty so no need to do further checks (this is checked above)
-    cond.and("MEDIUM_ID in ('" + mediumIds.join("', '") + "')");
-    statements.push(["COMMUNICATION", cols, types, ["0"], cond.build()]);
+    var cond = newWhere("ISSTANDARD = 1")
+                .and("COMMUNICATION.CONTACT_ID", pAffectedRowId)
+                .and("COMMUNICATION.MEDIUM_ID", mediumIds, SqlBuilder.IN());
     
+     statements.push(["COMMUNICATION", cols, types, ["0"], cond.build()]);
+
     //pNewStandardCommId can be an empty string if the standard has to only be removed
     if (pNewStandardCommId != "")
     {
         //set the new standard comm-record
-        cond.clear();
+        cond = newWhere("COMMUNICATION.COMMUNICATIONID", pNewStandardCommId);
         //check communicationid, contactId and medium to prevent data-inconsistency when bad function params are passed by (e.g communicationid of a different category)
-        cond.andPrepare("COMMUNICATION.COMMUNICATIONID", pNewStandardCommId).andPrepare("COMMUNICATION.CONTACT_ID", pAffectedRowId);
+        cond.andPrepare().andPrepare("COMMUNICATION.CONTACT_ID", pAffectedRowId);
         cond.and("MEDIUM_ID in ('" + mediumIds.join("', '") + "')");
         statements.push(["COMMUNICATION", cols, types, ["1"], cond.build()]);
     }
@@ -106,7 +105,7 @@ CommUtil.setStandardMail = function(pAffectedRowId, pNewStandardCommId)
 /**
  * returns a sub sql-string (without bracets) for getting the standard address of a COMMUNICATION
  * @param {String} pCategory value of the keyword "COMMUNICATION.MEDIUM" custom.category; e.g. "PHONE"
- * @param {String|SqlCondition} [pContactField=CONTACT.CONTACTID] SQL-fieldname that shall be used for filtering the CONTACT_ID, this can be a string(fieldname) or an SqlCondition object
+ * @param {String|SqlBuilder} [pContactField=CONTACT.CONTACTID] SQL-fieldname that shall be used for filtering the CONTACT_ID, this can be a string(fieldname) or an SqlBuilder object
  * @return {String} sub-sql
  */
 CommUtil.getStandardSubSqlForCategory = function(pCategory, pContactField)
@@ -114,15 +113,18 @@ CommUtil.getStandardSubSqlForCategory = function(pCategory, pContactField)
     if (!pCategory)
         return "''";
     
-    var cond = SqlCondition.begin();
+    var selectStandardAddr = newSelect("max(COMMUNICATION.ADDR)")
+                                .from("COMMUNICATION")
+                                .where();
+                                
     if (pContactField == undefined)
-        cond.and("COMMUNICATION.CONTACT_ID = CONTACT.CONTACTID");
+        selectStandardAddr.and("COMMUNICATION.CONTACT_ID = CONTACT.CONTACTID");
     else if (typeof(pContactField) == "string")
-        cond.andPrepare("COMMUNICATION.CONTACT_ID", pContactField);
+        selectStandardAddr.and("COMMUNICATION.CONTACT_ID", pContactField);
     else if (typeof(pContactField) == "object")
     {
         //you may want to sepcify a concrete value
-        cond.andSqlCondition(pContactField, "1=2");
+        selectStandardAddr.and(pContactField);
     }
     else
         return "''";//TODO: throw error
@@ -131,22 +133,15 @@ CommUtil.getStandardSubSqlForCategory = function(pCategory, pContactField)
     if (mediumIds.length == 0)
         return "''";
     
-    var anyMediumIdCond = SqlCondition.begin();
-    mediumIds.forEach(function(pMediumId)
-    {
-        anyMediumIdCond.orPrepare("COMMUNICATION.MEDIUM_ID", pMediumId);
-    });
-    cond.andSqlCondition(anyMediumIdCond, "1=0");
-    
-    cond.and("COMMUNICATION.ISSTANDARD = 1");
+    selectStandardAddr.andIfSet("COMMUNICATION.MEDIUM_ID", mediumIds, SqlBuilder.IN());
+    selectStandardAddr.and("COMMUNICATION.ISSTANDARD = 1");
     
-    var res = SqlUtils.translateStatementWithQuotes(cond.buildSql("select max(COMMUNICATION.ADDR) from COMMUNICATION", "1=0"));
-    return res;
+    return selectStandardAddr.toString();
 };
 
 /**
  * returns a sub sql-string (without bracets) for getting the standard address of a PHONE-COMMUNICATION
- * @param {String|SqlCondition} [pContactField=CONTACT.CONTACTID] SQL-fieldname that shall be used for filtering the CONTACT_ID, this can be a string(fieldname) or an SqlCondition object
+ * @param {String|SqlBuilder} [pContactField=CONTACT.CONTACTID] SQL-fieldname that shall be used for filtering the CONTACT_ID, this can be a string(fieldname) or an SqlBuilder object
  * @return {String} sub-sql
  */
 CommUtil.getStandardSubSqlPhone = function(pContactField)
@@ -156,7 +151,7 @@ CommUtil.getStandardSubSqlPhone = function(pContactField)
 
 /**
  * returns a sub sql-string (without bracets) for getting the standard address of a EMAIL-COMMUNICATION
- * @param {String|SqlCondition} [pContactField=CONTACT.CONTACTID] SQL-fieldname that shall be used for filtering the CONTACT_ID, this can be a string(fieldname) or an SqlCondition object
+ * @param {String|SqlBuilder} [pContactField=CONTACT.CONTACTID] SQL-fieldname that shall be used for filtering the CONTACT_ID, this can be a string(fieldname) or an SqlBuilder object
  * @return {String} sub-sql
  */
 CommUtil.getStandardSubSqlMail = function(pContactField)
@@ -173,9 +168,7 @@ CommUtil.getStandardSubSqlMail = function(pContactField)
  */
 CommUtil.getStandardMail = function (pContactId)
 {
-    var query = CommUtil.getStandardSubSqlMail(SqlCondition.begin()
-        .andPrepare("COMMUNICATION.CONTACT_ID", pContactId)
-    );
+    var query = CommUtil.getStandardSubSqlMail(newWhere("COMMUNICATION.CONTACT_ID", pContactId));
     return db.cell(query);
 }
 
diff --git a/process/Contact_lib/process.js b/process/Contact_lib/process.js
index ae48caa5f0fe4d61727bbc34e6ac580b1e3de637..bcf2d27576f26ab5561684fa3c8214a51a2eae53 100644
--- a/process/Contact_lib/process.js
+++ b/process/Contact_lib/process.js
@@ -25,13 +25,11 @@ function OrganisationUtils() {}
  */
 OrganisationUtils.getNameByOrganisationId = function(pOrganisationId)
 {
-    var orgname = "";
-    if (pOrganisationId)
-    {
-        orgname = db.cell(SqlCondition.begin()
-                                      .andPrepare("ORGANISATION.ORGANISATIONID", pOrganisationId)
-                                      .buildSql("select ORGANISATION.NAME from ORGANISATION"));
-    }
+    var orgname = newSelect("ORGANISATION.NAME")
+        .from("ORGANISATION")
+        .whereIfSet("ORGANISATION.ORGANISATIONID", pOrganisationId)
+        .cell(true);
+    
     return orgname;
 };
 
@@ -44,15 +42,12 @@ OrganisationUtils.getNameByOrganisationId = function(pOrganisationId)
  */
 OrganisationUtils.getNameByContactId = function(pContactId)
 {
-    var orgname = "";
-    if (pContactId)
-    {
-        orgname = db.cell(SqlCondition.begin()
-            .andPrepare("CONTACT.CONTACTID", pContactId)
-            .buildSql("select ORGANISATION.NAME \n\
-                            from ORGANISATION \n\
-                            join CONTACT on (CONTACT.ORGANISATION_ID = ORGANISATION.ORGANISATIONID and CONTACT.PERSON_ID is null)"));
-    }
+    var orgname = newSelect("ORGANISATION.NAME")
+        .from("ORGANISATION")
+        .join("CONTACT", "CONTACT.ORGANISATION_ID = ORGANISATION.ORGANISATIONID and CONTACT.PERSON_ID is null")
+        .whereIfSet("CONTACT.CONTACTID", pContactId)
+        .cell(true);
+    
     return orgname;
 };
 
@@ -106,14 +101,15 @@ ContactUtils.validateIfAlreadyExists = function(pPersonId, pOrganisationId, pOwn
         return null;
     if (pOrganisationId == "")
         pOrganisationId = "0";
-    var cond = SqlCondition.begin()
-    .andPrepare("CONTACT.PERSON_ID", pPersonId)
-    .andPrepare("CONTACT.ORGANISATION_ID", pOrganisationId)
-    //exclude the own since we do not want a "is not valid"-message for our own entry (on EDIT-mode)
-    .andPrepareIfSet("CONTACT.CONTACTID", pOwnContactId, "# != ?");
-
-    var sql = cond.buildSql("select CONTACT.CONTACTID from CONTACT");
-    var alreadyExistantContactId = db.cell(sql);
+
+    var alreadyExistantContactId = newSelect("CONTACT.CONTACTID")
+        .from("CONTACT")
+        .where("CONTACT.PERSON_ID", pPersonId)
+        .and("CONTACT.ORGANISATION_ID", pOrganisationId)
+        //exclude the own since we do not want a "is not valid"-message for our own entry (on EDIT-mode)
+        .andIfSet("CONTACT.CONTACTID", pOwnContactId, "# != ?")
+        .cell();
+        
     if (alreadyExistantContactId)
         if (pOrganisationId.trim() == "0")
             return translate.text("This private person doeas already exist and can not be created once more.");
@@ -283,14 +279,12 @@ ContactUtils.getContextByContactId = function(pContactId)
  */
 ContactUtils.getPersOrgIds = function(pContactId)
 {
-    if (pContactId) {
-        return db.array(db.ROW, 
-            SqlCondition.begin()
-                        .andPrepare("CONTACT.CONTACTID", pContactId)
-                        .buildSql("select CONTACTID, PERSON_ID, ORGANISATION_ID from CONTACT", "1=0"));
-    }
+    var persOrgIds = newSelect("CONTACTID, PERSON_ID, ORGANISATION_ID")
+        .from("CONTACT")
+        .whereIfSet("CONTACT.CONTACTID", pContactId)
+        .arrayRow(true);
     
-    return [];
+    return persOrgIds;
 }
 
 ContactUtils.getPersId = function(pContactId)
@@ -315,12 +309,12 @@ ContactUtils.getPersId = function(pContactId)
 ContactUtils.getOrgContactId = function(pOrgId)
 {
     if (pOrgId) {
-        return db.cell(SqlCondition.begin()
-                        .andPrepare("CONTACT.ORGANISATION_ID", pOrgId)
-                        .and("CONTACT.PERSON_ID is null")
-                        .buildSql("select CONTACTID from CONTACT", "1=0"));
+        return newSelect("CONTACTID")
+            .from("CONTACT")
+            .where("CONTACT.ORGANISATION_ID", pOrgId)
+            .and("CONTACT.PERSON_ID is null")
+            .cell();
     }
-    
     return "";
 }
 
@@ -333,23 +327,19 @@ ContactUtils.getOrgContactId = function(pOrgId)
  */
 ContactUtils.getFullTitleByContactId = function(pContactId)
 {
-    if (pContactId) 
-    {
-        var data = db.array(db.ROW, SqlCondition.begin()
-                .andPrepare("CONTACT.CONTACTID", pContactId)
-                .buildSql("select ORGANISATION.NAME, PERSON.SALUTATION, PERSON.TITLE, PERSON.FIRSTNAME, PERSON.MIDDLENAME, PERSON.LASTNAME "
-                    + "from CONTACT CONTACT "
-                    + "join ORGANISATION on ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID "
-                    + "left join PERSON on PERSON.PERSONID = CONTACT.PERSON_ID", "1 = 2"));
-        if (data.length == 0)
-            return "";
-        var contact = new Contact();
-        [contact.organisationName, contact.salutation, contact.title, contact.firstname, contact.middlename, contact.lastname] = data;
-        var renderer = new ContactTitleRenderer(contact);
-        return renderer.asString();
-    }
-    
-    return "";
+    var data = newSelect("ORGANISATION.NAME, PERSON.SALUTATION, PERSON.TITLE, PERSON.FIRSTNAME, PERSON.MIDDLENAME, PERSON.LASTNAME")
+        .from("CONTACT")
+        .join("ORGANISATION", "ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID")
+        .leftJoin("PERSON", "PERSON.PERSONID = CONTACT.PERSON_ID")
+        .whereIfSet("CONTACT.CONTACTID", pContactId)
+        .arrayRow(true);
+
+    if (data.length == 0)
+        return "";
+    var contact = new Contact();
+    [contact.organisationName, contact.salutation, contact.title, contact.firstname, contact.middlename, contact.lastname] = data;
+    var renderer = new ContactTitleRenderer(contact);
+    return renderer.asString();
 }
 
 /**
@@ -362,21 +352,17 @@ ContactUtils.getFullTitleByContactId = function(pContactId)
  */
 ContactUtils.getTitleByPersonId = function(pPersonId)
 {
-    if (pPersonId) 
-    {
-        var data = db.array(db.ROW, SqlCondition.begin()
-            .andPrepare("PERSON.PERSONID", pPersonId)
-            .buildSql("select PERSON.SALUTATION, PERSON.TITLE, PERSON.FIRSTNAME, PERSON.MIDDLENAME, PERSON.LASTNAME "
-                + "from PERSON", "1 = 2"));
-        if (data.length == 0)
-            return "";
-        var contact = new Contact();
-        [contact.salutation, contact.title, contact.firstname, contact.middlename, contact.lastname] = data;
-        var renderer = new ContactTitleRenderer(contact);
-        return renderer.asString();
-    }
-    
-    return "";
+    var data = newSelect("PERSON.SALUTATION, PERSON.TITLE, PERSON.FIRSTNAME, PERSON.MIDDLENAME, PERSON.LASTNAME")
+        .from("PERSON")
+        .whereIfSet("PERSON.PERSONID", pPersonId)
+        .arrayRow(true);
+        
+    if (data.length == 0)
+        return "";
+    var contact = new Contact();
+    [contact.salutation, contact.title, contact.firstname, contact.middlename, contact.lastname] = data;
+    var renderer = new ContactTitleRenderer(contact);
+    return renderer.asString();
 }
 
 /**
@@ -389,16 +375,12 @@ ContactUtils.getTitleByPersonId = function(pPersonId)
  */
 ContactUtils.getTitleByContactId = function(pContactId)
 {
-    if (pContactId) 
-    {
-        var personId = db.cell(SqlCondition.begin()
-                                           .andPrepare("CONTACT.CONTACTID", pContactId)
-                                            .buildSql("select CONTACT.PERSON_ID from CONTACT ", "1 = 2"));
-        if (personId)
-            return ContactUtils.getTitleByPersonId(personId);
-    }
+    var personId = newSelect("CONTACT.PERSON_ID")
+        .from("CONTACT")
+        .whereIfSet("CONTACT.CONTACTID", pContactId)
+        .cell(true);
     
-    return "";
+    return ContactUtils.getTitleByPersonId(personId);
 }
 
 /**
@@ -421,19 +403,21 @@ ContactUtils.getFullContactString = function()
  */
 ContactUtils.getDefaultAddressId = function(pContactId)
 {
-    return db.cell(SqlCondition.begin().andPrepare("CONTACT.CONTACTID", pContactId)
-                               .buildSql("select ADDRESS_ID from CONTACT", "1=2"));
+    return newSelect("ADDRESS_ID")
+        .from("CONTACT")
+        .whereIfSet("CONTACT.CONTACTID", pContactId)
+        .cell(true);
 }
 
 /**
- * makes a SqlCondition that checks if there's (not) a commrestriction for a contact
+ * makes a SqlBuilder that checks if there's (not) a commrestriction for a contact
  * 
  * @param {String} pMedium medium to check
  * @param {boolean} [pNoRestriction=false] if true, the condition gets every contact that has no
  *                                     a commrestriction, otherwise every contact that has a commrestriction
  * @param {String|Number} [pStartDate=current date] the start date of the commrestriction
  * 
- * @return {SqlCondition} the condition
+ * @return {SqlBuilder} the condition
  */
 ContactUtils.getCommRestrictionCondition = function (pMedium, pNoRestriction, pStartDate)
 {
@@ -442,16 +426,14 @@ ContactUtils.getCommRestrictionCondition = function (pMedium, pNoRestriction, pS
     var existsQuery = SqlBuilder.begin()
         .select("COMMRESTRICTIONID")
         .from("COMMRESTRICTION")
-        .where(SqlCondition.begin()
-            .andPrepare("COMMRESTRICTION.MEDIUM", pMedium)
-            .andPrepare("COMMRESTRICTION.STARTDATE", pStartDate, "# <= ?")
-            .and("(COMMRESTRICTION.CONTACT_ID = CONTACT.CONTACTID or COMMRESTRICTION.CONTACT_ID = CONTACT.PERSON_ID)")
-            .build("1=2"));
+        .where("COMMRESTRICTION.MEDIUM", pMedium)
+        .and("COMMRESTRICTION.STARTDATE", pStartDate, "# <= ?")
+        .and("(COMMRESTRICTION.CONTACT_ID = CONTACT.CONTACTID or COMMRESTRICTION.CONTACT_ID = CONTACT.PERSON_ID)");
             
-    var cond = "exists";
+    var cond = "exists ?";
     if (pNoRestriction)
         cond = "not " + cond;
-    return SqlCondition.begin().andSqlBuilder(existsQuery, cond);
+    return newWhere(null, existsQuery, cond);
 }
 
 /**
@@ -465,12 +447,11 @@ ContactUtils.getCommRestrictionCondition = function (pMedium, pNoRestriction, pS
  */
 ContactUtils.hasCommRestriction = function (pContactId, pMedium, pStartDate)
 {
-    var query = SqlCondition.begin()
-        .andPrepare("CONTACT.CONTACTID", pContactId)
-        .andSqlCondition(ContactUtils.getCommRestrictionCondition(pMedium, false, pStartDate))
-        .buildSql("select count(*) from CONTACT", "1=2"); //TODO: is there a way exists could be used?
-
-    return db.cell(query) != "0";
+    return newSelect("CONTACTID")
+        .from("CONTACT")
+        .where("CONTACT.CONTACTID", pContactId)
+        .and(ContactUtils.getCommRestrictionCondition(pMedium, false, pStartDate))
+        .cell() != "";
 }
 
 /**
diff --git a/process/Context_lib/process.js b/process/Context_lib/process.js
index c0596399da8a1e11704c5b0a1c8bb95a39a2b406..6dc2369d7995be04ee462970a700119c39b35ddd 100644
--- a/process/Context_lib/process.js
+++ b/process/Context_lib/process.js
@@ -1,4 +1,3 @@
-import("system.logging");
 import("system.entities");
 import("system.tools");
 import("system.neon");
@@ -270,10 +269,10 @@ function ContextSelector(pTableName, pIdField, pTitleExpression)
     
     /**
      * an object which contains the subcontexts and the prepared select to get the contactIds of them.
-     *                                                                                V--With Tablename!
-     * {                       V-- before id-condition | add "and", if needed --V     V-IdCollumn name   V-- optional after-condition SQL (e.g. group by etc.)
-     *   "Person": ["select PERSON_ID from CONTACT where PERSON_ID is not null and", "CONTACT.ORGANISATION_ID", '', ["Offer", "Contract"]],
-     *                                                                                                            //  the contexts to show for this subcontext
+     *                                                                                
+     * {                       V-- SqlBuilder with all conditions needed                                 V-IdCollumn name (with Tablename!)    V-the contexts to show for this subcontext
+     *   "Person": "Person": [newSelect("CONTACTID").from("CONTACT").where("PERSON_ID is not null"), "CONTACT.ORGANISATION_ID", ["Offer", "Order", "Contract", "SupportTicket"]],
+     * 
      *   "Offer" ... // you can add as many subcontexts as you wish
      * }
      * read-only property; set it with a matching setter
@@ -320,19 +319,34 @@ ContextSelector.prototype.getFullFromClause = function()
         
 };
 /**
- * @return {String} full from-expression with tablename and join-part
+ * @return {Object} in the following format: 
+ *                  {
+ *                      "{contactid1}": [SqlBuilder, ContextArray],
+ *                      ...
+ *                      ...
+ *                  }
  */
 ContextSelector.prototype.getSubContexts = function(pParentRowId)
 {
     if (this.subContexts)
     {
         var sqls = {};
-        
         for (contextId in this.subContexts)
         {
-            sqls[contextId] = [SqlCondition.begin()
-                               .andPrepare(this.subContexts[contextId][1], pParentRowId)
-                               .buildSql(this.subContexts[contextId][0], "1=2", this.subContexts[contextId][2], false), this.subContexts[contextId][3]];
+            // Copy the builder to prevent modifying the builder in this.subContexts
+            var select = this.subContexts[contextId][0].copy();
+            
+            // add id-condition
+            if (select.whereWasCalled())
+            {
+                select.and(this.subContexts[contextId][1], pParentRowId);
+            }
+            else
+            {
+                select.where(this.subContexts[contextId][1], pParentRowId);
+            }
+            
+            sqls[contextId] = [select, this.subContexts[contextId][2]];
         }
         
         return sqls;
@@ -384,7 +398,7 @@ ContextSelector.prototype.setActiveStates = function(pValue)
 };
 /**
  * sets the condition property of a ContextSelector-object
- * @param {Object} pSqlCondition condition as SqlCondition-object
+ * @param {SqlBuilder} pSqlCondition condition as SqlBuilder-object
  */
 ContextSelector.prototype.setCondition = function(pSqlCondition)
 {
@@ -406,9 +420,9 @@ ContextUtils.getSelectMap  = function()
     return {
             "Organisation": ContextSelector.create("ORGANISATION", "CONTACT.CONTACTID", "ORGANISATION.NAME")
                                        .setJoinExpression("join CONTACT on ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID and CONTACT.PERSON_ID is null")
-                                       .setCondition(SqlCondition.begin().and("ORGANISATION.ORGANISATIONID != '0'"))
+                                       .setCondition(newWhere("ORGANISATION.ORGANISATIONID != '0'"))
                                        .setSubContexts({
-                                           "Person": ["select CONTACTID from CONTACT where PERSON_ID is not null and", "CONTACT.ORGANISATION_ID", '', ["Offer", "Order", "Contract", "SupportTicket"]]
+                                           "Person": [newSelect("CONTACTID").from("CONTACT").where("PERSON_ID is not null"), "CONTACT.ORGANISATION_ID", ["Offer", "Order", "Contract", "SupportTicket"]]
                                        })
             ,"Person": ContextSelector.create("CONTACT", "CONTACTID")
                                       .setTitleExpression(maskingUtils.concat([
@@ -495,7 +509,7 @@ ContextUtils.getSelectMap  = function()
             ,"CampaignStep" : ContextSelector.create("CAMPAIGNSTEP", "CAMPAIGNSTEPID", "NAME")
             ,"SupportTicket": ContextSelector.create("TICKET", "TICKETID", "TASK.SUBJECT")
                         .setJoinExpression("left join TASK on TASK.TASKID = TICKET.TASK_ID")
-                        .setCondition(SqlCondition.begin().andPrepare("TICKET.TICKETTYPE", $KeywordRegistry.ticketType$supportTicket()))
+                        .setCondition(newWhere("TICKET.TICKETTYPE", $KeywordRegistry.ticketType$supportTicket()))
                         .setContactIdField("TASK.REQUESTOR_CONTACT_ID")
                         .setStateField("TASK.STATUS")
                         .setActiveStates([
@@ -539,9 +553,10 @@ ContextUtils.getNameSql = function(pContextId, pRowId)
     var selectMap = ContextUtils.getSelectMap ()
     if (selectMap[pContextId] != undefined)
     {
-        return SqlCondition.begin().andPrepare(selectMap[pContextId].getFullIdField(), pRowId)
-                                   .buildSql("select " + selectMap[pContextId].titleExpression 
-                                            + " from " + selectMap[pContextId].getFullFromClause(), "1 = 2");
+        return newSelect(selectMap[pContextId].titleExpression)
+                    .from(selectMap[pContextId].getFullFromClause())
+                    .whereIfSet(selectMap[pContextId].getFullIdField(), pRowId)
+                    .build("1=2");
     }
     else
         return "select 1 from person where 1=2";
@@ -552,13 +567,13 @@ ContextUtils.getNameSql = function(pContextId, pRowId)
  */
 ContextUtils.getContactId = function(pContextId, pRowId)
 {
-    var selectMap = ContextUtils.getSelectMap ()
+    var selectMap = ContextUtils.getSelectMap()
     if (selectMap[pContextId] != undefined && selectMap[pContextId].contactIdField)
     {
-        
-        return db.cell(SqlCondition.begin().andPrepare(selectMap[pContextId].getFullIdField(), pRowId)
-                                   .buildSql("select " + selectMap[pContextId].contactIdField
-                                            + " from " + selectMap[pContextId].tableName, "1 = 2"));
+        return newSelect(selectMap[pContextId].contactIdField)
+                    .from(selectMap[pContextId].tableName)
+                    .where(selectMap[pContextId].getFullIdField(), pRowId)
+                    .cell();
     }
     else
         return "";
@@ -571,10 +586,22 @@ ContextUtils.getContextDataSql = function(pContextId, pContactId, pWithDate, pAc
 {
     var selectMap = ContextUtils.getSelectMap();
     var ownContextSelector = selectMap[pContextId];
-    var cond = SqlCondition.begin();
+    
+    var dateColumn = "";
+    if (pWithDate === true)
+        dateColumn = ", " + (ownContextSelector.getFullField(ownContextSelector.creationDateField) || "''");
+    var stateColumn = "";
+    if (pWithState === true)
+        stateColumn = ", " + (ownContextSelector.getFullField(ownContextSelector.stateField) || "''");
+    
+
+    var contextDataSelect = newSelect(ownContextSelector.getFullIdField() + ", " + ownContextSelector.titleExpression + dateColumn + stateColumn)
+                                .from(ownContextSelector.getFullFromClause())
+                                .where();
+                                
     if (pContactId)
     {
-        cond.andPrepare(ownContextSelector.getFullField(ownContextSelector.contactIdField), pContactId)
+        contextDataSelect.and(ownContextSelector.getFullField(ownContextSelector.contactIdField), pContactId)
     }
     
     if (pActive != undefined)
@@ -582,40 +609,26 @@ ContextUtils.getContextDataSql = function(pContextId, pContactId, pWithDate, pAc
         var activeStates = ownContextSelector.activeStates;
         if(activeStates != null && activeStates.length > 0)
         {
-            var condSub = SqlCondition.begin();
+            var condSub = newWhere();
             activeStates.forEach(function (state) 
             {   
                 if(pActive)
-                    condSub.orPrepare(ownContextSelector.getFullField(ownContextSelector.stateField), state)
+                    condSub.or(ownContextSelector.getFullField(ownContextSelector.stateField), state)
                 else
-                    condSub.andPrepare(ownContextSelector.getFullField(ownContextSelector.stateField), state, "# != ?")
+                    condSub.and(ownContextSelector.getFullField(ownContextSelector.stateField), state, "# != ?")
             });
-            cond.andSqlCondition(condSub);  
+            contextDataSelect.andIfSet(condSub);  
         }
     }
     
     if (pExcludedObjectIds)
-    {
-        var exludedIdsCond = new SqlCondition()
-        
-        pExcludedObjectIds.forEach(function(id)
-        {
-            this.andPrepare(ownContextSelector.getFullIdField(), id, "# <> ?");
-        }, exludedIdsCond)
-        
-        cond.andSqlCondition(exludedIdsCond);
+    {        
+        contextDataSelect.and(ownContextSelector.getFullIdField(), pExcludedObjectIds, SqlBuilder.NOT_IN());
     }
     
-    var dateColumn = "";
-    if (pWithDate === true)
-        dateColumn = ", " + (ownContextSelector.getFullField(ownContextSelector.creationDateField) || "''");
-    var stateColumn = "";
-    if (pWithState === true)
-        stateColumn = ", " + (ownContextSelector.getFullField(ownContextSelector.stateField) || "''");
-    if (ownContextSelector.condition)
-        cond.andSqlCondition(ownContextSelector.condition);
-    var res = cond.buildSql("select " + ownContextSelector.getFullIdField() + ", " + ownContextSelector.titleExpression + dateColumn + stateColumn 
-            +  " from " + ownContextSelector.getFullFromClause(), "1=1");
+    contextDataSelect.andIfSet(ownContextSelector.condition);
+    
+    var res = contextDataSelect.build();
     return res;
 }
 
@@ -630,8 +643,10 @@ ContextUtils.getCountByContactId = function(pContextId, pContactId)
     var join = contextObject.joinExpression;
     if (tableName && contactField)
     {
-        var sql = "select count(*) from " + tableName + (join ? join : "");
-        var count = db.cell(SqlCondition.begin().andPrepare(contactField, pContactId).buildSql(sql, "1=2"));
+        return newSelect("count(*)")
+                        .from(tableName + (join ? join : ""))
+                        .where(contactField, pContactId)
+                        .cell(true, "0");
         return count;
     }
     return 0;
diff --git a/process/CountryInfo_lib/process.js b/process/CountryInfo_lib/process.js
index c1a5563631ef990d4b30adb33cc249312f4e01b0..999d00d5d2021c5e16d9550d0a9493e5343bd83e 100644
--- a/process/CountryInfo_lib/process.js
+++ b/process/CountryInfo_lib/process.js
@@ -26,9 +26,10 @@ CountryUtils.getLatinNameByIso2 = function(pIso2, pLocale)
 {
     if (!pIso2)
         return "";
-    var countryName = db.cell(SqlCondition.begin()
-                                          .andPrepare("AB_COUNTRYINFO.ISO2", pIso2)
-                                          .buildSql("select AB_COUNTRYINFO.NAME_LATIN from AB_COUNTRYINFO"));
+    var countryName = newSelect("AB_COUNTRYINFO.NAME_LATIN")
+                        .from("AB_COUNTRYINFO")
+                        .where("AB_COUNTRYINFO.ISO2", pIso2)
+                        .cell();
     countryName = pLocale ? translate.text(countryName, pLocale) : translate.text(countryName);
     return countryName;
 };
diff --git a/process/DataPrivacy_lib/process.js b/process/DataPrivacy_lib/process.js
index bb8b3897f4ccc6c108108e0c11fb5dd21211eb44..4b186f6497f001e6b12c755efcce64c8594a96dd 100644
--- a/process/DataPrivacy_lib/process.js
+++ b/process/DataPrivacy_lib/process.js
@@ -296,32 +296,29 @@ function DataPrivacyUtils() {}
  * Selects the dsgvo-data from the DSGVO table. It already resolves the DSGVO-type display value
  * 
  * @param {String} pContactId 
- * @param {SqlCondition} [pFilterCond=undefined] Sql condition object containing additional conditions
+ * @param {SqlBuilder} [pFilterCond=undefined] SqlBuilder object containing additional conditions. Only the conditions are used!
  * 
  * @return {String[][]} the DSGVO data
  */
 DataPrivacyUtils.getDSGVO = function(pContactId, pFilterCond)
 {
-    var cond = SqlCondition.begin().andPrepare("DSGVO.CONTACT_ID", pContactId);
-    cond.andSqlCondition(pFilterCond);
-    
-    var select =    "DSGVOID," +               // 0
-                    "CONTACT_ID," +            // 1
-                    "DSGVOTYPE," +             // 2
-                    "ROW_ID," +                // 3
-                    "''," +                    // 4 - dummy for value
-                    "STATUORITYSOURCE," +      // 5
-                    "PURPOSE," +               // 6
-                    "VALID_TO," +              // 7
-                    "DATE_NEW," +              // 8
-                    "DATE_EDIT," +             // 9
-                    "USER_NEW," +              // 10
-                    "USER_EDIT, " +            // 11
-                    KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.dsgvoType(), "DSGVOTYPE") // 12 - dsgvotype-displayvalue
-
-    
-    var data = db.table(cond.buildSql("select " + select + " from DSGVO", "1 = 2"));
-    return data;
+    return newSelect("DSGVOID," +               // 0
+                        "CONTACT_ID," +            // 1
+                        "DSGVOTYPE," +             // 2
+                        "ROW_ID," +                // 3
+                        "''," +                    // 4 - dummy for value
+                        "STATUORITYSOURCE," +      // 5
+                        "PURPOSE," +               // 6
+                        "VALID_TO," +              // 7
+                        "DATE_NEW," +              // 8
+                        "DATE_EDIT," +             // 9
+                        "USER_NEW," +              // 10
+                        "USER_EDIT, " +            // 11
+                        KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.dsgvoType(), "DSGVOTYPE")) // 12 - dsgvotype-displayvalue)
+                .from("DSGVO")
+                .where("DSGVO.CONTACT_ID", pContactId)
+                .and(pFilterCond)
+                .table();
 }
 
 /**
@@ -332,7 +329,7 @@ DataPrivacyUtils.getDSGVO = function(pContactId, pFilterCond)
  *  - If NO FILTER is provided, it inserts all found data not already existing in DSGVO-table into the DSGVO-table.
  *  
  * @param {String} pContactId
- * @param {SqlCondition} [pFilterCond=undefined] Sql condition object containing additional conditions
+ * @param {SqlBuilder} [pFilterCond=undefined] SqlBuilder object containing additional conditions
  * 
  * @return {String[][]} the collected dsgvo data
  */
@@ -414,7 +411,9 @@ DataPrivacyUtils.collectAll = function(pContactId, pFilterCond)
         // filter no longer existing records and delete them
         if (!pRow[4])
         {
-            deletes.push(["DSGVO", SqlCondition.equals("DSGVO.DSGVOID", pRow[0], "1=2")]);
+            if (pRow[0])
+                deletes.push(["DSGVO", newWhere("DSGVO.DSGVOID", pRow[0])]);
+            
             return false;
         }
         
@@ -460,14 +459,15 @@ DataPrivacyUtils.notifyNeedDataPrivacyUpdate = function(pContactId, pShowMessage
  */
 DataPrivacyUtils.checkAllFilled = function(pContactId)
 {
-    var countNotFilled = db.cell(SqlCondition.begin()
-                        .andPrepare("DSGVO.CONTACT_ID", pContactId)
-                        .andSqlCondition(SqlCondition.begin()
-                            .or("STATUORITYSOURCE is null")
-                            .or("PURPOSE is null")
-                            .or("VALID_TO is null"))
-                        .buildSql("select count(*) from DSGVO", "1=2"))
-                        
+    var countNotFilled = newSelect("count(*)")
+                            .from("DSGVO")
+                            .where("DSGVO.CONTACT_ID", pContactId)
+                            .and(newWhere()
+                                .or("STATUORITYSOURCE is null")
+                                .or("PURPOSE is null")
+                                .or("VALID_TO is null"))
+                            .cell();
+                            
     return countNotFilled == "0";       
 }
 
@@ -613,11 +613,10 @@ DataPrivacyUtils.openReport = function(pContactId, pReportName, pDSGVOInfo, pLoc
             ], pLocale)
     }
     
-    var saveTill = datetime.toDate(db.cell(
-                            SqlCondition.begin()
-                                        .andPrepare("DSGVO.CONTACT_ID", pContactId)
-                                        .buildSql("select max(VALID_TO) from DSGVO", "1=2")),
-                        translate.text("dd.MM.yyyy", pLocale), "UTC");
+    var saveTill = datetime.toDate(newSelect("max(VALID_TO)")
+                                        .from("DSGVO")
+                                        .where("DSGVO.CONTACT_ID", pContactId)
+                                        .cell());
     
     saveTill = translate.text("We save your data until ", pLocale) + saveTill + ".";
     var addrObject = new AddrObject(pContactId);
diff --git a/process/DocumentTemplate_lib/.LCKprocess.js~ b/process/DocumentTemplate_lib/.LCKprocess.js~
new file mode 100644
index 0000000000000000000000000000000000000000..27faaf26be4fa558ed663829aa9e021855990ca1
--- /dev/null
+++ b/process/DocumentTemplate_lib/.LCKprocess.js~
@@ -0,0 +1 @@
+C:\entwicklungszweige\0.0\project\xRM-Basic2019\process\DocumentTemplate_lib\process.js
\ No newline at end of file
diff --git a/process/DocumentTemplate_lib/process.js b/process/DocumentTemplate_lib/process.js
index f54d3722b45f4ada3bfb891aa02d8931622b349a..1e58868f6fca8b4bfd63b1ccf74dec46213eba04 100644
--- a/process/DocumentTemplate_lib/process.js
+++ b/process/DocumentTemplate_lib/process.js
@@ -85,10 +85,10 @@ DocumentTemplate.prototype._resolveEmbeddedTemplate = function ()
         
         if (this.type == DocumentTemplate.types.HTML)
         {
-            templates = templates.concat(db.table(SqlCondition.begin()
-                        .andPrepare("DOCUMENTTEMPLATE.KIND", $KeywordRegistry.documentTemplateType$textModular())
-                        .andPrepare("DOCUMENTTEMPLATE.CLASSIFICATION", $KeywordRegistry.documentTemplateTypeCategory$htmlTemplate())
-                        .buildSql("select DOCUMENTTEMPLATEID, REPLACEMENTNAME from DOCUMENTTEMPLATE")));
+            templates = templates.concat(newSelect("DOCUMENTTEMPLATEID, REPLACEMENTNAME").from("DOCUMENTTEMPLATE")
+                .where("DOCUMENTTEMPLATE.KIND", $KeywordRegistry.documentTemplateType$textModular())
+                .and("DOCUMENTTEMPLATE.CLASSIFICATION", $KeywordRegistry.documentTemplateTypeCategory$htmlTemplate())
+                .table());
         }
         
         var alias = SqlUtils.getBinariesAlias();
@@ -131,10 +131,10 @@ DocumentTemplate.prototype.getAttachments = function ()
     
     if (this._attachmentCache == null)
     {
-        var attachmentIds = db.array(db.COLUMN, SqlCondition.begin()
-                                                 .andPrepare("DOCUMENTTEMPLATELINK.DOCUMENTTEMPLATE_ID_PARENT", this.templateId)
-                                                 .buildSql("select DOCUMENTTEMPLATE_ID_CHILD from DOCUMENTTEMPLATELINK"));
-
+        var attachmentIds = newSelect("DOCUMENTTEMPLATE_ID_CHILD")
+            .from("DOCUMENTTEMPLATELINK")
+            .where("DOCUMENTTEMPLATELINK.DOCUMENTTEMPLATE_ID_PARENT", this.templateId)
+            .arrayColumn();
         this._attachmentCache = attachmentIds.map(function(pAttachmentId)
         {
             return DocumentTemplateUtils.getTemplate(pAttachmentId, false);
@@ -409,11 +409,12 @@ DocumentTemplate.prototype.getReplacedContentByContactIds = function (pContactId
  *          of objects (dimensions are: document, table in that document, rows of the table). For the format, see example.
  * 
  * @example 
- * var contactSql = SqlCondition.begin()
- *       .andPrepare("CONTACT.ORGANISATION_ID", orgId)
- *       .buildSql("select FIRSTNAME, LASTNAME from CONTACT join PERSON on CONTACT.PERSON_ID = PERSON.PERSONID");
+ * var contacts = newSelect("FIRSTNAME, LASTNAME")
+ *                      .from("CONTACT")
+ *                      .join("PERSON", "CONTACT.PERSON_ID = PERSON.PERSONID")
+ *                      .where("CONTACT.ORGANISATION_ID", orgId)
+ *                      .table();
  *
- *   var contacts = db.table(contactSql);
  *   var tblRows = [];
  *   fnamePlaceholder = PlaceholderUtils.formatPlaceholder("fname");
  *   lnamePlaceholder = PlaceholderUtils.formatPlaceholder("lname");
diff --git a/process/Employee_lib/process.js b/process/Employee_lib/process.js
index 3702cc9561f22169e09ec71ea5f83587abb48934..94f25b38ba05c7d6a656312fc0e343fe96d902d7 100644
--- a/process/Employee_lib/process.js
+++ b/process/Employee_lib/process.js
@@ -115,18 +115,18 @@ EmployeeUtils.hasRelations = function (pContactId)
 {
     //sql queries with selects on tables where an employee can be used
     var queries = [
-        SqlCondition.begin()
-            .andPrepare("ACTIVITY.RESPONSIBLE", pContactId)
-            .buildSql("select 1 from ACTIVITY"),
-        SqlCondition.begin()
-            .andPrepare("TASK.REQUESTOR_CONTACT_ID", pContactId)
-            .buildSql("select 1 from TASK"),
-        SqlCondition.begin()
-            .andPrepare("TIMETRACKING.CONTACT_ID", pContactId)
-            .buildSql("select 1 from TIMETRACKING")
+        newSelect("1")
+            .from("ACTIVITY")
+            .where("ACTIVITY.RESPONSIBLE", pContactId),
+        newSelect("1")
+            .from("TASK")
+            .where("TASK.REQUESTOR_CONTACT_ID", pContactId),
+        newSelect("1")
+            .from("TIMETRACKING")
+            .where("TIMETRACKING.CONTACT_ID", pContactId),
     ];
-    return queries.some(function (sql)
+    return queries.some(function (pSelect)
         {
-            return db.cell(sql) != "";
+            return pSelect.cell() != "";
         });
 }
\ No newline at end of file
diff --git a/process/IncomingCallExecutor_lib/process.js b/process/IncomingCallExecutor_lib/process.js
index dbbfdb150b18c7b1ae0b233cd5e2535060eb3b03..eb8b65edb8334e2097cd6a6d36bb66b7e98ac642 100644
--- a/process/IncomingCallExecutor_lib/process.js
+++ b/process/IncomingCallExecutor_lib/process.js
@@ -199,17 +199,15 @@ IncomingCallExecutor._getContactsFromNumber = function(pNumber, pContactIds)
     return rows;
     */
     //load entities does not work here, so use instead a traditional sql-query:
-    var contactSql = SqlCondition.begin()
-                                 .andPrepareIfSet("COMMUNICATION.ADDR", phoneNumber)
-                                 .andIn("COMMUNICATION.CONTACT_ID", pContactIds)//this is automatically only added if pContactIds is truely
-                                 .andPrepare("CONTACT.STATUS", $KeywordRegistry.contactStatus$active())
-                                 .buildSql("select CONTACT.CONTACTID, CONTACT.ORGANISATION_ID, ORGANISATION.NAME, CONTACT.PERSON_ID, \n\
-                                                   CONTACT.ISOLANGUAGE, PERSON.LASTNAME, PERSON.FIRSTNAME from CONTACT \n\
-                                          join ORGANISATION on ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID \n\
-                                          left join PERSON on CONTACT.PERSON_ID = PERSON.PERSONID \n\
-                                          join COMMUNICATION on COMMUNICATION.CONTACT_ID = CONTACT.CONTACTID");
-
-    var contacts = db.table(contactSql);
+    var contacts = newSelect("CONTACT.CONTACTID, CONTACT.ORGANISATION_ID, ORGANISATION.NAME, CONTACT.PERSON_ID, CONTACT.ISOLANGUAGE, PERSON.LASTNAME, PERSON.FIRSTNAME")
+                        .from("CONTACT")
+                        .join("ORGANISATION", "ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID")
+                        .leftJoin("PERSON", "CONTACT.PERSON_ID = PERSON.PERSONID")
+                        .join("COMMUNICATION", "COMMUNICATION.CONTACT_ID = CONTACT.CONTACTID")
+                        .whereIfSet("COMMUNICATION.ADDR", phoneNumber)
+                        .and("COMMUNICATION.CONTACT_ID", pContactIds, SqlBuilder.IN())
+                        .and("CONTACT.STATUS", $KeywordRegistry.contactStatus$active())
+                        .table();
     
     return contacts.map(function (e){//map to the result how the entities-methods would return it to have less effort later
         return {
diff --git a/process/IncomingEmailExecutor_lib/process.js b/process/IncomingEmailExecutor_lib/process.js
index d77eba0b91df6718f22d1e498658ae2108be0e7f..27532e621d43c937fa28fa4d1c9bea88f8b8361c 100644
--- a/process/IncomingEmailExecutor_lib/process.js
+++ b/process/IncomingEmailExecutor_lib/process.js
@@ -55,10 +55,11 @@ IncomingEmailExecutor.prototype.setActivityEmployeeContact = function (pContactI
     //autodetect language if not given
     if (pLanguageIso3 == undefined)
     {
-        var langSql = SqlCondition.begin(this._alias)
-                                  .andPrepare("CONTACT.CONTACTID", pContactId)
-                                  .buildSql("select CONTACT.ISOLANGUAGE from CONTACT");
-        var lang = db.cell(langSql, this._alias);
+        var lang = newSelect("CONTACT.ISOLANGUAGE", this._alias)
+                            .from("CONTACT")
+                            .where("CONTACT.CONTACTID", pContactId)
+                            .cell();
+                            
         if (lang)
             pLanguageIso3 = lang;
     }
@@ -147,13 +148,11 @@ IncomingEmailExecutor.prototype.isUnlinkable = function ()
 IncomingEmailExecutor.getContactDataByEmail = function (pMailAddress, pAlias)
 {
     var mailAddress = EmailUtils.extractAddress(pMailAddress).toUpperCase();
-    var sql = SqlCondition.begin(pAlias)
-    .andPrepare("COMMUNICATION.ADDR", mailAddress, "upper(#) = ?")
-    .buildSql("select CONTACT.CONTACTID, CONTACT.STATUS, CONTACT.PERSON_ID, CONTACT.ISOLANGUAGE \n\
-                                                        from COMMUNICATION \n\
-                                                        join CONTACT on (COMMUNICATION.CONTACT_ID = CONTACT.CONTACTID)");
-    var res = db.table(sql, pAlias);
-    return res;
+    return newSelect("CONTACT.CONTACTID, CONTACT.STATUS, CONTACT.PERSON_ID, CONTACT.ISOLANGUAGE", pAlias)
+                    .from("COMMUNICATION")
+                    .join("CONTACT", "COMMUNICATION.CONTACT_ID = CONTACT.CONTACTID")
+                    .where("COMMUNICATION.ADDR", mailAddress, "upper(#) = ?")
+                    .table();
 }
 
 IncomingEmailExecutor.prototype.createActivity = function(pAdditionalLinks)
@@ -206,10 +205,8 @@ IncomingEmailExecutor.prototype.createActivity = function(pAdditionalLinks)
 
 IncomingEmailExecutor.prototype.deleteUnlinkedMail = function (pUnlinkedMailId)
 {
-    if (pUnlinkedMailId)
-    {
-        db.deleteData("AB_UNLINKEDMAIL", SqlCondition.begin().andPrepare("AB_UNLINKEDMAIL.AB_UNLINKEDMAILID", pUnlinkedMailId).build(), this._alias);
-    }
+    newWhere("AB_UNLINKEDMAIL.AB_UNLINKEDMAILID", pUnlinkedMailId, undefined, undefined, this._alias)
+        .deleteData(true, "AB_UNLINKEDMAIL");
 }
 
 IncomingEmailExecutor.prototype.autoProcess = function(pUnlinkedMailId)
diff --git a/process/JditoFilter_lib/process.js b/process/JditoFilter_lib/process.js
index c704e068bca1eb937e04db4cc5437a39d9d68ef1..2e1416fbd1faa9d14a723ddea24838724ba050a3 100644
--- a/process/JditoFilter_lib/process.js
+++ b/process/JditoFilter_lib/process.js
@@ -1,3 +1,4 @@
+import("system.logging");
 import("Sql_lib");
 
 //private scope to make only JditoFilterUtils public
@@ -145,34 +146,34 @@ JditoFilterUtils.filterRecords = function (pColumns, pRecords, pFilter, pCustomC
  * @param {Object} pFilter the filter object
  * @param {String} pTable the database table
  * @param {String} [pTableAlias=null] the database table alias
- * @param {Object} [pColumnOrFnMap=null] Custom mapping for the fields to the DB columns or functions that return a SqlCondition, this is necessary
+ * @param {Object} [pColumnOrFnMap=null] Custom mapping for the fields to the DB columns or functions that return a SqlBuilder, this is necessary
  *      if the fields are from different tables. Structure has to be like this:
  *      {
  *          FIELD1 : "TABLE1.COLUMN1",
  *          FIELD2 : ["TABLE2", "COLUMN2", "TABLE2ALIAS"], //do it like this if the table has an alias
  *          FIELD3 : function (pValue, pOperator)          //function if you need to build a special condition
  *          {
- *              var cond = new SqlCondition();
+ *              var cond = new SqlBuilder();
  *              ...
  *              return cond;
  *          }
  *      }
  *      
  * @example
- * var condition = SqlCondition.begin();
+ * var condition = newSelect("AB_ATTRIBUTEID").from("AB_ATTRIBUTE");
  * if (vars.exists("$local.filter") && vars.get("$local.filter"))
  * {
  *     var filter = vars.get("$local.filter");
  *     if (filter.filter)
- *      condition.andSqlCondition((JditoFilterUtils.getSqlCondition(filter.filter, "AB_ATTRIBUTE")));
+ *      condition.and((JditoFilterUtils.getSqlCondition(filter.filter, "AB_ATTRIBUTE")));
  * }
- * var attributeSql = condition.buildSql("select AB_ATTRIBUTEID from AB_ATTRIBUTE");
+ * var attributeSql = condition.build();
  * 
- * @return {SqlCondition} the SqlCondition object
+ * @return {SqlBuilder} the SqlBuilder object containing the condition
  */
 JditoFilterUtils.getSqlCondition = function (pFilter, pTable, pTableAlias, pColumnOrFnMap)
 {
-    var condition = new SqlCondition();
+    var condition = newWhere();    
     
     if (!pFilter)
         return condition;
@@ -181,53 +182,54 @@ JditoFilterUtils.getSqlCondition = function (pFilter, pTable, pTableAlias, pColu
     
     _addCondition.call(condition, pFilter, pFilter.operator);
     
+    logging.log(JSON.stringify([condition.build()], null, "\t"))
     return condition;
     
     //recursive function (for compatibility with a condition tree) that
-    //builds the SqlCondition
-    function _addCondition (pCondition, pOperator)
+    //builds the SqlBuilder
+    function _addCondition (pFilter, pOperator)
     {
-        if (pCondition.type == "row")
+        if (pFilter.type == "row")
         {
-            if (pCondition.name in pColumnOrFnMap)
-                pCondition.name = pColumnOrFnMap[pCondition.name];
+            if (pFilter.name in pColumnOrFnMap)
+                pFilter.name = pColumnOrFnMap[pFilter.name];
             else if (pTable && pTableAlias)
-                pCondition.name = [pTable, pCondition.name, pTableAlias];
+                pFilter.name = [pTable, pFilter.name, pTableAlias];
             else if (pTable)
-                pCondition.name = pTable + "." + pCondition.name;
+                pFilter.name = pTable + "." + pFilter.name;
             
-            pCondition.value = (pCondition.key || pCondition.value);
+            pFilter.value = (pFilter.key || pFilter.value);
             
             var condition;
-            if (typeof(pCondition.name) === "function")
+            if (typeof(pFilter.name) === "function")
             {
-                condition = pCondition.name.call(null, pCondition.value, pCondition.operator);
+                condition = pFilter.name.call(null, pFilter.value, pFilter.operator);
                 if (pOperator == "AND")
-                    this.andSqlCondition(condition);
+                    this.andIfSet(condition);
                 else if (pOperator == "OR")
-                    this.orSqlCondition(condition);
+                    this.orIfSet(condition);
             }
             else
             {
-                condition = _getCondition.call(pCondition, pCondition.value, pCondition.operator);
+                condition = _getCondition.call(pFilter, pFilter.value, pFilter.operator);
                 if (pOperator == "AND")
-                    this.andPrepare(pCondition.name, pCondition.value, condition);
+                    this.andIfSet(pFilter.name, pFilter.value, condition);
                 else if (pOperator == "OR")
-                    this.orPrepare(pCondition.name, pCondition.value, condition);
+                    this.orIfSet(pFilter.name, pFilter.value, condition);
             }
         }
-        else if (pCondition.type == "group")
+        else if (pFilter.type == "group")
         {
-            let subCondition = new SqlCondition();
-            let operator = pCondition.operator;
-            pCondition.childs.forEach(function (cond)
+            let subCondition = newWhere();
+            let operator = pFilter.operator;
+            pFilter.childs.forEach(function (cond)
             {
                 _addCondition.call(subCondition, cond, operator);
             });
             if (pOperator == "AND")
-                this.andSqlCondition(subCondition);
+                this.andIfSet(subCondition);
             else if (pOperator == "OR")
-                this.orSqlCondition(subCondition);
+                this.orIfSet(subCondition);
         }
     }
     
diff --git a/process/KeywordData_lib/process.js b/process/KeywordData_lib/process.js
index 3eb97115b302f01e8bbc722a9ad93bb8f19dc631..32bc18cd92b498635edd0fcff6b5dec332069e45 100644
--- a/process/KeywordData_lib/process.js
+++ b/process/KeywordData_lib/process.js
@@ -20,13 +20,15 @@ KeywordData.getSimpleData = function (pKeywordContainer, pLocale, pOnlyActives)
     var identifier = "KeywordSimpleData_" + pKeywordContainer + flags;
     var cache = new CachedData(identifier, true, pLocale);
     return cache.load(function (pTranslationNecessary, pLocale){
-        var cond = SqlCondition.begin().andPrepare("AB_KEYWORD_ENTRY.CONTAINER", pKeywordContainer);
+        var keywordEntrySelect = newSelect("AB_KEYWORD_ENTRY.KEYID, AB_KEYWORD_ENTRY.TITLE")
+                                    .from("AB_KEYWORD_ENTRY")
+                                    .orderBy("AB_KEYWORD_ENTRY.SORTING asc, AB_KEYWORD_ENTRY.TITLE asc")
+                                    .where("AB_KEYWORD_ENTRY.CONTAINER", pKeywordContainer);
         
         if (onlyActives)
-            cond.andPrepare("AB_KEYWORD_ENTRY.ISACTIVE", "1");
+            keywordEntrySelect.and("AB_KEYWORD_ENTRY.ISACTIVE", "1");
         
-        var keywordData = db.table(cond.buildSql("select AB_KEYWORD_ENTRY.KEYID, AB_KEYWORD_ENTRY.TITLE from AB_KEYWORD_ENTRY", null, 
-            "order by AB_KEYWORD_ENTRY.SORTING asc, AB_KEYWORD_ENTRY.TITLE asc"));
+        var keywordData = keywordEntrySelect.table();
 
         for (var i = 0, l = keywordData.length; i < l; i++)
         {
@@ -54,19 +56,15 @@ KeywordData.getKeyIdMap = function (pKeywordContainer, pLocale)
 
 KeywordData.getKeywordAttributeRelations = function (pKeywordContainer)
 {
-    var data = CachedData.make("KeywordAttributeRelationObj_" + pKeywordContainer, false, function(){
-        var cond = SqlCondition.begin()
-        .andPrepare("AB_KEYWORD_ENTRY.CONTAINER", pKeywordContainer);
-        
-        var sql = cond.buildSql("select AB_KEYWORD_ENTRY.KEYID, AB_KEYWORD_ATTRIBUTE.NAME, AB_KEYWORD_ATTRIBUTE.KIND, \n\
-        AB_KEYWORD_ATTRIBUTERELATION.CHAR_VALUE, AB_KEYWORD_ATTRIBUTERELATION.LONG_CHAR_VALUE, AB_KEYWORD_ATTRIBUTERELATION.NUMBER_VALUE, AB_KEYWORD_ATTRIBUTERELATION.BOOL_VALUE \n\
-        from AB_KEYWORD_ENTRY \n\
-        join AB_KEYWORD_ATTRIBUTE on (AB_KEYWORD_ATTRIBUTE.CONTAINER = AB_KEYWORD_ENTRY.CONTAINER) \n\
-        left join AB_KEYWORD_ATTRIBUTERELATION \n\
-            on (AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ATTRIBUTE_ID = AB_KEYWORD_ATTRIBUTE.AB_KEYWORD_ATTRIBUTEID\n\
-                and AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID = AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID)");
+    return CachedData.make("KeywordAttributeRelationObj_" + pKeywordContainer, false, function(){
+        var data = newSelect("AB_KEYWORD_ENTRY.KEYID, AB_KEYWORD_ATTRIBUTE.NAME, AB_KEYWORD_ATTRIBUTE.KIND, \n\
+                            AB_KEYWORD_ATTRIBUTERELATION.CHAR_VALUE, AB_KEYWORD_ATTRIBUTERELATION.LONG_CHAR_VALUE, AB_KEYWORD_ATTRIBUTERELATION.NUMBER_VALUE, AB_KEYWORD_ATTRIBUTERELATION.BOOL_VALUE")
+                        .from("AB_KEYWORD_ENTRY")
+                        .join("AB_KEYWORD_ATTRIBUTE", "AB_KEYWORD_ATTRIBUTE.CONTAINER = AB_KEYWORD_ENTRY.CONTAINER")
+                        .leftJoin("AB_KEYWORD_ATTRIBUTERELATION", newWhere("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ATTRIBUTE_ID = AB_KEYWORD_ATTRIBUTE.AB_KEYWORD_ATTRIBUTEID")
+                                                                    .and("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID = AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID"))
+                        .table();
 
-        var data = db.table(sql);
         var res = {};
         var keyId, name, type, charVal, longCharVal, numVal, boolVal;
 
@@ -99,7 +97,6 @@ KeywordData.getKeywordAttributeRelations = function (pKeywordContainer)
         }
         return res;
     });
-    return data;
 }
 
 function LanguageData(){}
diff --git a/process/KeywordRegistry_basic/process.js b/process/KeywordRegistry_basic/process.js
index f3db5255815df2c575c3419e6267213f8181bdac..7a3ea68a86917fab65c943a63ecd9de4a06736f3 100644
--- a/process/KeywordRegistry_basic/process.js
+++ b/process/KeywordRegistry_basic/process.js
@@ -62,6 +62,8 @@ $KeywordRegistry.taskStatus$assigned = function(){return $KeywordRegistry._autoP
 $KeywordRegistry.taskStatus$inProgress = function(){return $KeywordRegistry._autoPad("IN-PROGRESS");};
 $KeywordRegistry.taskStatus$waiting = function(){return $KeywordRegistry._autoPad("WAITING");};
 $KeywordRegistry.taskStatus$ended = function(){return $KeywordRegistry._autoPad("ENDED");};
+$KeywordRegistry.taskStatus$endedDone = function(){return $KeywordRegistry._autoPad("ENDED-DONE");};
+$KeywordRegistry.taskStatus$endedAbandoned = function(){return $KeywordRegistry._autoPad("ENDED-ABANDONED");};
 $KeywordRegistry.taskStatus$customerChecks = function(){return $KeywordRegistry._autoPad("CUSTOMER-CHECKS");};
 
 $KeywordRegistry.taskType = function(){return "TaskType";};
diff --git a/process/Keyword_lib/process.js b/process/Keyword_lib/process.js
index cdee4d4334482080ddca333405ec150b1bc823e3..8f1892d8fc0780f6986f090a24d2b7da0c48c2ac 100644
--- a/process/Keyword_lib/process.js
+++ b/process/Keyword_lib/process.js
@@ -142,11 +142,13 @@ KeywordUtils.getEntryNamesByContainer = function(pContainerName, pLocale)
 KeywordUtils.getEntryNamesAndIdsByContainer = function(pContainerName, pLocale)
 {
     //TODO: this can be propably removed when the "Salesproject_entity.REASONS.dropDownProcess.js" is replaced by a consumer
-    var sql = SqlCondition.begin()
-                          .andPrepare("AB_KEYWORD_ENTRY.CONTAINER", pContainerName)
-                          .buildSql("select AB_KEYWORD_ENTRY.KEYID, AB_KEYWORD_ENTRY.TITLE from AB_KEYWORD_ENTRY", null, "order by AB_KEYWORD_ENTRY.SORTING asc, AB_KEYWORD_ENTRY.TITLE asc")
-                          
-    var list = db.table(sql).map(function (elem){
+    var list = newSelect("AB_KEYWORD_ENTRY.KEYID, AB_KEYWORD_ENTRY.TITLE")
+                    .from("AB_KEYWORD_ENTRY")
+                    .where("AB_KEYWORD_ENTRY.CONTAINER", pContainerName)
+                    .orderBy("AB_KEYWORD_ENTRY.SORTING asc, AB_KEYWORD_ENTRY.TITLE asc")
+                    .table();
+                    
+    list = list.map(function (elem){
         elem[1] = pLocale ? translate.text(elem[1], pLocale) : translate.text(elem[1]);
         return elem;
     });
@@ -165,11 +167,13 @@ KeywordUtils.getEntryNamesAndIdsByContainer = function(pContainerName, pLocale)
 KeywordUtils.exists = function(pKeyId, pContainerName)
 {
     //a check if a keyword exists should always be on the origin data and not the cache, so do not cache here
-    var sql = SqlCondition.begin()
-                          .andPrepare("AB_KEYWORD_ENTRY.KEYID", pKeyId)
-                          .andPrepare("AB_KEYWORD_ENTRY.CONTAINER", pContainerName)
-                          .buildSql("select count(*) from AB_KEYWORD_ENTRY", "1=2")
-    return parseInt(db.cell(sql)) > 0;
+    return parseInt(
+        newSelect("count(*)")
+            .from("AB_KEYWORD_ENTRY")
+            .where("AB_KEYWORD_ENTRY.KEYID", pKeyId)
+            .and("AB_KEYWORD_ENTRY.CONTAINER", pContainerName)
+            .cell(true, "0")
+    ) > 0;
 };
 
 /**
@@ -224,13 +228,12 @@ function KeywordAttribute(pContainerName, pAttributeName, pDefault)
     this.container = pContainerName;
     this.attribute = pAttributeName;
     this.defaultValue = pDefault;
-    
-    var sql  = SqlCondition.begin()
-                           .andPrepare("AB_KEYWORD_ATTRIBUTE.CONTAINER", pContainerName)
-                           .andPrepare("AB_KEYWORD_ATTRIBUTE.NAME", pAttributeName)
-                           .buildSql("select AB_KEYWORD_ATTRIBUTE.AB_KEYWORD_ATTRIBUTEID, AB_KEYWORD_ATTRIBUTE.KIND from AB_KEYWORD_ATTRIBUTE");
-    
-    var keywordAttrData = db.array(db.ROW, sql);
+
+    var keywordAttrData = newSelect("AB_KEYWORD_ATTRIBUTE.AB_KEYWORD_ATTRIBUTEID, AB_KEYWORD_ATTRIBUTE.KIND")
+                            .from("AB_KEYWORD_ATTRIBUTE")
+                            .where("AB_KEYWORD_ATTRIBUTE.CONTAINER", pContainerName)
+                            .and("AB_KEYWORD_ATTRIBUTE.NAME", pAttributeName)
+                            .arrayRow();
     
     if (keywordAttrData.length > 0) 
     {
@@ -257,12 +260,14 @@ KeywordAttribute.prototype.getValue = function(pKeyId)
 {
     if (this.exists()) 
     {
-        var sql = SqlCondition.begin()
-                          .andPrepare("AB_KEYWORD_ENTRY.CONTAINER", this.container)
-                          .andPrepare("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ATTRIBUTE_ID", this.id)
-                          .andPrepare("AB_KEYWORD_ENTRY.KEYID", pKeyId)
-                          .buildSql("select " + this.dbField + " from AB_KEYWORD_ENTRY join AB_KEYWORD_ATTRIBUTERELATION on AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID = AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID");
-        var attrValue = db.cell(sql);
+        var attrValue = newSelect(this.dbField)
+                        .from("AB_KEYWORD_ENTRY")
+                        .join("AB_KEYWORD_ATTRIBUTERELATION", "AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID = AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID")
+                        .where("AB_KEYWORD_ENTRY.CONTAINER", this.container)
+                        .and("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ATTRIBUTE_ID", this.id)
+                        .and("AB_KEYWORD_ENTRY.KEYID", pKeyId)
+                        .cell();
+
         if (attrValue)
             return attrValue;
         
diff --git a/process/ObjectRelation_lib/process.js b/process/ObjectRelation_lib/process.js
index badb2f5ff02c8a4d4b4044e9e8760a81ccc17942..330272e687261fd31d763b68beab6cf5118683d8 100644
--- a/process/ObjectRelation_lib/process.js
+++ b/process/ObjectRelation_lib/process.js
@@ -81,7 +81,8 @@ ObjectRelationUtils.getPossibleRelationTypes = function(pObjectTypes, pFullInfo,
              else 'reverse'\n\
         end direction,\n\
         main.HIERARCHY, \n\
-        type2.OBJECT_TYPE destObjectType, \n\
+        ( case when type2.AB_OBJECTRELATIONTYPEID is null then main.OBJECT_TYPE " + // if type is 'same' (type2.AB_OBJECTRELATIONTYPEID is null) then use the same object type for dest as for source
+        "    else type2.OBJECT_TYPE end ) destObjectType, \n\
         main.OBJECT_TYPE sourceObjectType, \n\
         -- typeId of Object2\n\
         case when main.SIDE = 1 then main.AB_OBJECTRELATIONTYPEID\n\
diff --git a/process/OfferOrder_lib/process.js b/process/OfferOrder_lib/process.js
index bd665cf48f54d85e87eac8f24a3efe1e9cad57a8..9e02ea00da00ce3008a1799650eac7c70b1462f4 100644
--- a/process/OfferOrder_lib/process.js
+++ b/process/OfferOrder_lib/process.js
@@ -94,29 +94,23 @@ function ItemUtils(pOfferOrderId, pTableName) {
 }
 
 /**
- * get netto and vat for all items or for all given items.
+ * get netto and vat for all items excluding the provided ones.
  * 
- * @param {String[]} [itemIds = null] if given, only these id's are used.
+ * @param {String[]} [pExcludedItemIds) = null] if given, all but these ids are selected.
  * 
  * @return {Double[]} result as array with [nettoSum, vat] 
  */
-ItemUtils.prototype.getNetAndVat = function(itemIds) {
+ItemUtils.prototype.getNetAndVat = function(pExcludedItemIds) {
     // TODO: Bessere Möglichkeit als per SQL die zugehörigen Posten aus der DB zu holen?
     var sum = 0;
     var vat = 0;
 
 
-    var condition = SqlCondition.begin().andPrepare(this.tableName + "ITEM." + this.tableName + "_ID", this.offerOrderId);
-    
-    if (itemIds != undefined)
-    {
-        itemIds.forEach(function(pItem)
-        {
-            condition.andPrepare(this.tableName + "ITEM." + this.tableName + "ITEMID", pItem, "# <> ?");
-        }, this);
-    }
-
-    var orderItems = db.table(condition.buildSql("select QUANTITY, PRICE, DISCOUNT, VAT, OPTIONAL from " + this.tableName + "ITEM", "1 = 0"));   
+    var orderItems = newSelect("QUANTITY, PRICE, DISCOUNT, VAT, OPTIONAL")
+                            .from(this.tableName + "ITEM")
+                            .where(this.tableName + "ITEM." + this.tableName + "_ID", this.offerOrderId)
+                            .andIfSet(this.tableName + "ITEM." + this.tableName + "ITEMID", pExcludedItemIds, SqlBuilder.NOT_IN())
+                            .table();
 
     for (var i = 0; i < orderItems.length; i++)
     {
@@ -137,10 +131,11 @@ ItemUtils.prototype.initItemTree = function() {
     if (this.ItemTree == undefined) {
         this.ItemTree = {};
         this.ItemIds = [];
-        var data = db.table(SqlCondition.begin()
-                                        .andPrepare(this.tableName + "ITEM." + this.tableName + "_ID", this.offerOrderId)
-                                        .buildSql("select " + this.tableName + "ITEMID, ASSIGNEDTO, ITEMPOSITION, ITEMSORT from " + this.tableName + "ITEM",
-                                                    "1=2", "order by ITEMSORT"))
+        var data = newSelect(this.tableName + "ITEMID, ASSIGNEDTO, ITEMPOSITION, ITEMSORT")
+                        .from(this.tableName + "ITEM")
+                        .where(this.tableName + "ITEM." + this.tableName + "_ID", this.offerOrderId)
+                        .orderBy("ITEMSORT")
+                        .table();
        
         for (var i = 0; i < data.length; i++)
         {
@@ -328,9 +323,7 @@ ItemUtils.prototype.deletePartsList = function(itemId) {
         for (var i = 0; i < itemsToDelete.length; i++) {
             
             //unshift due to foreign key constraints (Delete hierarchically starting at the bottom)                                           
-            statements.unshift([self.tableName + "ITEM", SqlCondition.begin()
-                                           .andPrepare(self.tableName + "ITEM." + self.tableName + "ITEMID", itemsToDelete[i])
-                                           .build("1 = 2")]);
+            statements.unshift([self.tableName + "ITEM", newWhere(self.tableName + "ITEM." + self.tableName + "ITEMID", itemsToDelete[i]).build()]);
             
             deletedItemIds.push(itemsToDelete[i]);
             __itemDeleteStatement(itemsToDelete[i]);
diff --git a/process/Offer_lib/process.js b/process/Offer_lib/process.js
index 5766569d1c8b04fabd858deda5267cec985a52f6..ae8b8944ebfc0bf9c523c321de8bc09242e5fa8b 100644
--- a/process/Offer_lib/process.js
+++ b/process/Offer_lib/process.js
@@ -121,21 +121,20 @@ OfferUtils.openOfferReport = function (pOfferID)
         "LETTERSALUTATION" // 15
     ];
    
-    var offerSql = SqlCondition.begin()
-        .andPrepare("OFFER.OFFERID", pOfferID)
-        .buildSql("select " + offerFields.join(", ") + " from OFFER", "1 = 0");
-    var offerData = db.array(db.ROW, offerSql);
-    
+    var offerData = newSelect(offerFields)
+                        .from("OFFER")
+                        .where("OFFER.OFFERID", pOfferID)
+                        .arrayRow();
+  
     var letterSalutation = offerData[15];
     
     offerData[7] = datetime.toDate(offerData[7], translate.text("dd.MM.yyyy", language));
     
-    var language = db.cell(SqlCondition.begin()
-        .andPrepare("AB_LANGUAGE.ISO3", offerData[2])
-        .buildSql("select ISO2 from AB_LANGUAGE", "1=0"));
-    var contactId = offerData[1];
-    
-    
+    var language = newSelect("ISO2")
+                        .from("AB_LANGUAGE")
+                        .where("AB_LANGUAGE.ISO3", offerData[2])
+                        .cell();
+        
     var offerItemFields = [
         "OFFERITEM.INFO", 
         "OFFERITEM.ASSIGNEDTO",
@@ -154,14 +153,12 @@ OfferUtils.openOfferReport = function (pOfferID)
         "''"
     ]; 
     
-    var offerItemSql = SqlCondition.begin()
-        .andPrepare("OFFERITEM.OFFER_ID", pOfferID)
-        .buildSql(
-            "select " + offerItemFields.join(", ") + " from OFFERITEM left join PRODUCT on PRODUCT.PRODUCTID = OFFERITEM.PRODUCT_ID", 
-            "1 = 0"
-        );
-    var itemData = db.table(offerItemSql);
-    
+    var itemData = newSelect(offerItemFields)
+                            .from("OFFERITEM")
+                            .leftJoin("PRODUCT", "PRODUCT.PRODUCTID = OFFERITEM.PRODUCT_ID")
+                            .where("OFFERITEM.OFFER_ID", pOfferID)
+                            .table();
+            
     if (itemData.length == 0)
         return;
     
@@ -348,7 +345,8 @@ OfferUtils.copyOfferItems = function (pSourceOfferId, pTargetOfferId)
     cols = ["NET", "VAT"];
     var vals = oiUtils.getNetAndVat();
     
-    db.updateData("OFFER", cols, null, vals, SqlCondition.equals("OFFER.OFFERID", pTargetOfferId, "1 = 2"));
+    newWhere("OFFER.OFFERID", pTargetOfferId)
+        .updateData(true, cols, null, vals, "OFFER");
 }
 
 /**
@@ -389,9 +387,11 @@ OfferUtils.getOfferTitleById = function (pOfferId)
 {
     if (!pOfferId)
         return "";
-    var offerNumber = db.array(db.ROW, SqlCondition.begin()
-        .andPrepare("OFFER.OFFERID", pOfferId)
-        .buildSql("select OFFERCODE, VERSNR from OFFER"));
+    var offerNumber = newSelect("OFFERCODE, VERSNR")
+                        .from("OFFER")
+                        .where("OFFER.OFFERID", pOfferId)
+                        .arrayRow();
+                        
     return offerNumber.length > 0 
         ? translate.text("Offer") + " " + offerNumber.join("-") 
         : "";
@@ -469,11 +469,14 @@ OfferItemUtils.prototype.insertPartsList = function(pProductId, pAssignedTo, pCu
                 , "ITEMPOSITION"
                 , "ITEMSORT"];
 
-    return ItemUtils.prototype.insertPartsList.apply(this, [cols, pProductId, pAssignedTo, pCurrency, pContactId, [[["info", "INFO"], ["info", SqlUtils.translateStatementWithQuotes(SqlCondition.begin()
-                                  .andPrepare("DESCRIPTIONTRANSLATION.OBJECT_ROWID", pProductId)
-                                  .and("DESCRIPTIONTRANSLATION.OBJECT_TYPE = 'Product'")
-                                  .andPrepare("DESCRIPTIONTRANSLATION.LANG", pLanguage)
-                                  .buildSql("(select DESCRIPTION from DESCRIPTIONTRANSLATION", "1=2", ")"))]]]]);
+    return ItemUtils.prototype.insertPartsList.apply(this, [cols, pProductId, pAssignedTo, pCurrency, pContactId, [[["info", "INFO"], ["info", 
+                            "( " + newSelect("DESCRIPTION")
+                                .from("DESCRIPTIONTRANSLATION")
+                                .where("DESCRIPTIONTRANSLATION.OBJECT_ROWID", pProductId)
+                                .and("DESCRIPTIONTRANSLATION.OBJECT_TYPE = 'Product'")
+                                .and("DESCRIPTIONTRANSLATION.LANG", pLanguage)
+                                .toString() + ")"]]]]);
+                                  
 }
 
 /**
diff --git a/process/Order_lib/process.js b/process/Order_lib/process.js
index 547a53e14dbe5173c504bc750555c0691e471012..5a8428c8a166a387b6f2611eaf484b3dac83b96a 100644
--- a/process/Order_lib/process.js
+++ b/process/Order_lib/process.js
@@ -159,7 +159,8 @@ OrderUtils.copyOfferItemsToOrder = function (pOfferId, pOrderId)
     cols = ["NET", "VAT"];
     var vals = oiUtils.getNetAndVat();
     
-    db.updateData("SALESORDER", cols, null, vals, SqlCondition.equals("SALESORDER.SALESORDERID", pOrderId, "1 = 2"));
+    newWhere("SALESORDER.SALESORDERID", pOrderId)
+        .updateData(true, cols, null, vals, "SALESORDER");
 }
 
 OrderUtils.openOrderReport = function (pOrderID)
@@ -187,14 +188,15 @@ OrderUtils.openOrderReport = function (pOrderID)
         "ORDERTYPE" // 15
     ];
    
-    var orderSql = SqlCondition.begin()
-        .andPrepare("SALESORDER.SALESORDERID", pOrderID)
-        .buildSql("select " + orderFields.join(", ") + " from SALESORDER", "1 = 0");
-    var orderData = db.array(db.ROW, orderSql);
-    
-     var language = db.cell(SqlCondition.begin()
-        .andPrepare("AB_LANGUAGE.ISO3", orderData[2])
-        .buildSql("select ISO2 from AB_LANGUAGE", "1=0"));   
+    var orderData = newSelect(orderFields)
+                        .from("SALESORDER")
+                        .where("SALESORDER.SALESORDERID", pOrderID)
+                        .arrayRow();
+    
+    var language = newSelect("ISO2")
+                        .from("AB_LANGUAGE")
+                        .where("AB_LANGUAGE.ISO3", orderData[2])
+                        .cell();
         
     orderData[7] = datetime.toDate(orderData[7], translate.text("dd.MM.yyyy", language));
     
@@ -218,13 +220,11 @@ OrderUtils.openOrderReport = function (pOrderID)
         "''"
     ]; 
     
-    var orderItemSql = SqlCondition.begin()
-        .andPrepare("SALESORDERITEM.SALESORDER_ID", pOrderID)
-        .buildSql(
-            "select " + orderItemFields.join(", ") + " from SALESORDERITEM left join PRODUCT on PRODUCT.PRODUCTID = SALESORDERITEM.PRODUCT_ID", 
-            "1 = 0"
-        );
-    var itemData = db.table(orderItemSql);
+    var itemData = newSelect(orderItemFields)
+                            .from("SALESORDERITEM")
+                            .leftJoin("PRODUCT", "PRODUCT.PRODUCTID = SALESORDERITEM.PRODUCT_ID")
+                            .where("SALESORDERITEM.SALESORDER_ID", pOrderID)
+                            .table();
     
     if (itemData.length == 0)
         return;
@@ -401,15 +401,16 @@ OrderUtils.openReminderReport = function (pOrderID)
         "DUNNINGTEXT"  //20
     ];
    
-    var orderSql = SqlCondition.begin()
-        .andPrepare("SALESORDER.SALESORDERID", pOrderID)
-        .buildSql("select " + orderFields.join(", ") + " from SALESORDER", "1 = 0");
-    var orderData = db.array(db.ROW, orderSql);
-    
-     var language = db.cell(SqlCondition.begin()
-        .andPrepare("AB_LANGUAGE.ISO3", orderData[2])
-        .buildSql("select ISO2 from AB_LANGUAGE", "1=0"));   
-        
+    var orderData = newSelect(orderFields)
+                        .from("SALESORDER")
+                        .where("SALESORDER.SALESORDERID", pOrderID)
+                        .arrayRow();
+    
+    var language = newSelect("ISO2")
+                        .from("AB_LANGUAGE")
+                        .where("AB_LANGUAGE.ISO3", orderData[2])
+                        .cell();
+                        
     orderData[7] = datetime.toDate(orderData[7], translate.text("dd.MM.yyyy", language));
     orderData[18] = datetime.toDate(orderData[18], translate.text("dd.MM.yyyy", language));
     
@@ -433,12 +434,12 @@ OrderUtils.openReminderReport = function (pOrderID)
         "''"
     ]; 
     
-    var orderItemSql = SqlCondition.begin()
-        .andPrepare("SALESORDERITEM.SALESORDER_ID", pOrderID)
-        .buildSql(
-            "select " + orderItemFields.join(", ") + " from SALESORDERITEM left join PRODUCT on PRODUCT.PRODUCTID = SALESORDERITEM.PRODUCT_ID", 
-            "1 = 0"
-        );
+    var orderItemSql = newSelect(orderItemFields)
+                            .from("SALESORDERITEM")
+                            .leftJoin("PRODUCT", "PRODUCT.PRODUCTID = SALESORDERITEM.PRODUCT_I")
+                            .where("SALESORDERITEM.SALESORDER_ID", pOrderID)
+                            .table();
+
     var itemData = db.table(orderItemSql);
     
     if (itemData.length == 0)
diff --git a/process/Organisation_lib/process.js b/process/Organisation_lib/process.js
index f80c70ad5e6d59ac7454b930a4de74a19b4ebea7..875556f1d2e3f0b60bf72b5d17fa67dcf847d1ba 100644
--- a/process/Organisation_lib/process.js
+++ b/process/Organisation_lib/process.js
@@ -65,17 +65,17 @@ OrgUtils.openOrgReport = function(pOrgId)
     var relationId = pOrgId;
     
     //org info
-    var info = db.cell(SqlCondition.begin()
-        .andPrepare("ORGANISATION.ORGANISATIONID", pOrgId)
-        .buildSql("select ORGANISATION.INFO from ORGANISATION"));
+    var info = newSelect("ORGANISATION.INFO")
+                    .from("ORGANISATION")
+                    .where("ORGANISATION.ORGANISATIONID", pOrgId)
+                    .cell();
     
     //communication data of the organization
-    var commSql = "select MEDIUM_ID, ADDR from COMMUNICATION";
-    commSql = SqlCondition.begin()
-        .andPrepare("COMMUNICATION.CONTACT_ID", relationId)
-        .and("ISSTANDARD = 1")
-        .buildSql(commSql);
-    var commData = db.table(commSql);
+    var commData = newSelect("MEDIUM_ID, ADDR")
+                    .from("COMMUNICATION")
+                    .where("COMMUNICATION.CONTACT_ID", relationId)
+                    .and("ISSTANDARD = 1")
+                    .table();
     
     //resolve keyword
     commData.forEach(function (row)
@@ -85,18 +85,17 @@ OrgUtils.openOrgReport = function(pOrgId)
     commData = ReportData.begin(["KINDOFCOMM", "COMMVALUE"]).add(commData);
     
     //select people from the organization
-    
-    var persSql = "select SALUTATION, TITLE, FIRSTNAME, LASTNAME "
-        + ",CONTACTROLE as PERSFUNCITON, DEPARTMENT as PERSDEPARTMENT "
-        + ",(" + CommUtil.getStandardSubSqlMail() + ")"
-        + ",(" + CommUtil.getStandardSubSqlPhone() + ")"
-        + ",ORGANISATION_ID, CONTACTID "
-        + "from PERSON join CONTACT on PERSONID = PERSON_ID";
-    persSql = SqlCondition.begin()
-        .andPrepare("CONTACT.ORGANISATION_ID", pOrgId)
-        .and("CONTACT.STATUS = '" + $KeywordRegistry.contactStatus$active() + "'") //TODO: replace this with something that isn't a hard coded id
-        .buildSql(persSql, "", " order by PERSON.LASTNAME asc");
-    var persData = db.table(persSql);
+    var persData = newSelect("SALUTATION, TITLE, FIRSTNAME, LASTNAME "
+                            + ",CONTACTROLE as PERSFUNCITON, DEPARTMENT as PERSDEPARTMENT "
+                            + ",(" + CommUtil.getStandardSubSqlMail() + ")"
+                            + ",(" + CommUtil.getStandardSubSqlPhone() + ")"
+                            + ",ORGANISATION_ID, CONTACTID")
+                        .from("PERSON")
+                        .join("CONTACT", "PERSONID = PERSON_ID")
+                        .where("CONTACT.ORGANISATION_ID", pOrgId)
+                        .and("CONTACT.STATUS", $KeywordRegistry.contactStatus$active()) 
+                        .orderBy("PERSON.LASTNAME asc")
+                        .table();
     
     for (let i = 0; i < persData.length; i++)
     {
@@ -105,14 +104,14 @@ OrgUtils.openOrgReport = function(pOrgId)
     }
     persData = ReportData.begin(["PERSNAMECOMPLETE", "PERSFUNCTION", "PERSDEPARTMENT", "PERSCOMM", "ORGANISATION_ID", "CONTACT_ID"]).add(persData);
 
-    var histSql = "select ENTRYDATE, CATEGORY, FIRSTNAME, LASTNAME, INFO from ACTIVITY "
-        + " join ACTIVITYLINK on ACTIVITYLINK.ACTIVITY_ID = ACTIVITYID "
-        + " join CONTACT on ACTIVITYLINK.OBJECT_ROWID = CONTACTID"
-        + " left join PERSON on CONTACT.PERSON_ID = PERSONID";
-    histSql = SqlCondition.begin()
-        .andPrepare("CONTACT.ORGANISATION_ID", pOrgId)   //= all activities linked to the organization or an employee
-        .buildSql(histSql, "", "order by ENTRYDATE desc");
-    var histData = db.table(histSql);
+    var histData = newSelect("ENTRYDATE, CATEGORY, FIRSTNAME, LASTNAME, INFO")
+                    .from("ACTIVITY")
+                    .join("ACTIVITYLINK", "ACTIVITYLINK.ACTIVITY_ID = ACTIVITYID")
+                    .join("CONTACT", "ACTIVITYLINK.OBJECT_ROWID = CONTACTID")
+                    .leftJoin("PERSON", "CONTACT.PERSON_ID = PERSONID")
+                    .where("CONTACT.ORGANISATION_ID", pOrgId)  //= all activities linked to the organization or an employee
+                    .orderBy("ENTRYDATE desc")
+                    .table();
     
     var dateFormat = translate.text("dd.MM.yyyy");
     histData.forEach(function (row) 
@@ -134,13 +133,12 @@ OrgUtils.openOrgReport = function(pOrgId)
         .join("\n");
     
     //tasks
-    var taskSql = "select TASK.SUBJECT, TASK.DESCRIPTION, TASK.STATUS, FIRSTNAME, LASTNAME from TASK"
-        + " join CONTACT on EDITOR_CONTACT_ID = CONTACTID"
-        + " left join PERSON on CONTACT.PERSON_ID = PERSONID";
-    taskSql = SqlCondition.begin()
-        .andPrepare("CONTACT.ORGANISATION_ID", pOrgId)
-        .buildSql(taskSql);
-    var taskData = db.table(taskSql);
+    var taskData = newSelect("TASK.SUBJECT, TASK.DESCRIPTION, TASK.STATUS, FIRSTNAME, LASTNAME")
+                    .from("TASK")
+                    .join("CONTACT", "EDITOR_CONTACT_ID = CONTACTID")
+                    .leftJoin("PERSON", "CONTACT.PERSON_ID = PERSONID")
+                    .where("CONTACT.ORGANISATION_ID", pOrgId)
+                    .table();
     
     taskData.forEach(function (row) 
     {
diff --git a/process/Permission_lib/process.js b/process/Permission_lib/process.js
index b3088f98e9f8d9ee68525d0ca9017956c920da9f..44013f2ffea73bedeb5a732de907c48b7c6f41da 100644
--- a/process/Permission_lib/process.js
+++ b/process/Permission_lib/process.js
@@ -23,10 +23,10 @@ function PermissionUtil () {}
  */
     PermissionUtil.getChildSetsOfSet = function (pSetId) 
     {   
-        return db.array(db.COLUMN, SqlCondition.begin()
-            .and("ASYS_PERMISSIONSET_ID = '" + pSetId + "'")
-            .buildSql("select ASYS_PERMISSIONSETID from ASYS_PERMISSIONSET")
-            , alias);
+        return newSelect("ASYS_PERMISSIONSETID", alias)
+                    .from("ASYS_PERMISSIONSET")
+                    .whereIfSet("ASYS_PERMISSIONSET_ID", pSetId)
+                    .arrayColumn(true);
     }
 
     /**
@@ -38,11 +38,11 @@ function PermissionUtil () {}
  */
     PermissionUtil.getActionsOfSet = function (pSetId)
     {
-        return db.array(db.COLUMN, SqlCondition.begin()
-            .and("ASYS_PERMISSION.ASYS_PERMISSIONSET_ID = '" + pSetId + "'")
-            .buildSql("select ASYS_PERMISSIONACTION.ASYS_PERMISSIONACTIONID from ASYS_PERMISSIONACTION"
-                + " join ASYS_PERMISSION on ASYS_PERMISSION.ASYS_PERMISSIONID = ASYS_PERMISSIONACTION.ASYS_PERMISSION_ID")
-            , alias);
+        return newSelect("ASYS_PERMISSIONACTION.ASYS_PERMISSIONACTIONID", alias)
+                    .from("ASYS_PERMISSIONACTION")
+                    .join("ASYS_PERMISSION", "ASYS_PERMISSION.ASYS_PERMISSIONID = ASYS_PERMISSIONACTION.ASYS_PERMISSION_ID")
+                    .whereIfSet("ASYS_PERMISSION.ASYS_PERMISSIONSET_ID", pSetId)
+                    .arrayColumn(true);
     }
     
     /**
@@ -53,7 +53,13 @@ function PermissionUtil () {}
  * @result {String[]} returns ids of all permission actions. The result can never be null.
  */
     PermissionUtil.getActions = function(pPermIds) {
-        return db.table("select ASYS_PERMISSIONACTIONID from ASYS_PERMISSIONACTION where ASYS_PERMISSIONACTION.ASYS_PERMISSION_ID in ('" + pPermIds.join("','") + "')", alias);
+        if (pPermIds.length <= 0)
+            return [];
+        
+        return newSelect("ASYS_PERMISSIONACTIONID", alias)
+                .from("ASYS_PERMISSIONACTION")
+                .whereIfSet("ASYS_PERMISSIONACTION.ASYS_PERMISSION_ID", pPermIds, SqlBuilder.IN())
+                .table(true);
     }
 
     /**
@@ -65,10 +71,10 @@ function PermissionUtil () {}
  */
     PermissionUtil.resolveActionId = function (pActionId)
     {
-        return db.cell(SqlCondition.begin()
-            .and("ASYS_PERMISSIONACTIONID = '" + pActionId + "'")
-            .buildSql("select ASYS_PERMISSIONACTION.ACTION from ASYS_PERMISSIONACTION")
-            , alias);
+        return newSelect("ASYS_PERMISSIONACTION.ACTION", alias)
+                    .from("ASYS_PERMISSIONACTION")
+                    .whereIfSet("ASYS_PERMISSIONACTIONID", pActionId)
+                    .cell(true);
     }
 
     /**
@@ -112,7 +118,7 @@ function PermissionUtil () {}
         return notFound;
     }
 
-    /**
+/**
  * Checks a permission if the given actions are different to the actions in the database.
  * 
  * @param {String} pPermId permission id to which the actions are linked to
@@ -122,8 +128,10 @@ function PermissionUtil () {}
  * @result {String[]} returns the different elements
  */
     PermissionUtil.getActionDiff = function(pPermId, pActionNew) {
-        var sqlStr = "select ACTION from ASYS_PERMISSIONACTION where ASYS_PERMISSION_ID = '" + pPermId + "'";
-        var actionOld = db.array(db.COLUMN, sqlStr, alias);
+        var actionOld = newSelect("ACTION", alias)
+                            .from("ASYS_PERMISSIONACTION")
+                            .whereIfSet("ASYS_PERMISSION_ID", pPermId)
+                            .arrayColumn(true);
     
         return arrDiff(actionOld, pActionNew);
     }
@@ -142,8 +150,10 @@ function PermissionUtil () {}
  * @result {Boolean} returns true if different, otherwise false
  */
     PermissionUtil.isDiff = function(pId, pString, pDbCol, pDbTable) {
-        var sqlStr = "select " + pDbCol + " from " + pDbTable + " where " + pDbTable + "ID = '" + pId + "'";
-        var stringDb = db.cell(sqlStr, alias);
+        var stringDb = newSelect(pDbCol, alias)
+                            .from(pDbTable)
+                            .whereIfSet(pDbTable + "ID", pId)
+                            .cell(true);
         return stringDb != pString ? true : false;
     }
 
@@ -164,8 +174,10 @@ function PermissionUtil () {}
         if (PermissionUtil.isDiff(pId, pValue, pDbCol, pDbTable)) {
             var cols = [pDbCol];
             var vals = [pValue];
-            var cond = SqlCondition.begin().and(pDbTable + "ID = '" + pId + "'").build();
-            return db.updateData(pDbTable, cols, null, vals, cond, alias);
+            
+            var cond = new SqlBuilder(alias).whereIfSet(pDbTable + "ID", pId);
+            
+            return cond.updateData(true, cols, null, vals, pDbTable)
         }
         return 0;
     }
@@ -178,11 +190,14 @@ function PermissionUtil () {}
  * @result {Integer} returns number of permissions linked to the entity.
  */
     PermissionUtil.getNumberOfPermissions = function(pEntityName) {
-        var table = "ASYS_PERMISSIONSET";
-        var sqlStr = "select COUNT(*) from " + table + " where ENTITY_ID = '" + pEntityName + "'";
-        return db.cell(sqlStr, alias);
+        return newSelect("COUNT(*)", alias)
+                    .from("ASYS_PERMISSIONSET")
+                    .whereIfSet("ENTITY_ID", pEntityName)
+                    .cell(true, "0");
     }
 
+// TODO: use SqlBuilder in whole lib (why? --> Prepared statements should be used always)
+
     /**
  * Gets the default permission of the root permission set.
  * 
diff --git a/process/PostalAddress_lib/process.js b/process/PostalAddress_lib/process.js
index 9e2a28bb1c1b7a77ce4767255bbe741efd8f84e6..61dbe3754ecf60ae6196717c66ed36bc048a07c9 100644
--- a/process/PostalAddress_lib/process.js
+++ b/process/PostalAddress_lib/process.js
@@ -62,11 +62,10 @@ AddressUtils.getFormattedOnlineAddressById = function(pAddressId)
     var addr = "";
     if (addrId) 
     {
-        var select = "select ADDRESS.COUNTRY, ADDRESS.ADDRESS, ADDRESS.BUILDINGNO, ADDRESS.ZIP, ADDRESS.CITY, ADDRESS.ADDRIDENTIFIER from ADDRESS ";
-        var addrData = db.array(db.ROW, 
-            SqlCondition.begin()
-            .andPrepare("ADDRESS.ADDRESSID", addrId)
-            .buildSql(select));
+        var addrData = newSelect("ADDRESS.COUNTRY, ADDRESS.ADDRESS, ADDRESS.BUILDINGNO, ADDRESS.ZIP, ADDRESS.CITY, ADDRESS.ADDRIDENTIFIER")
+                            .from("ADDRESS")
+                            .whereIfSet("ADDRESS.ADDRESSID", addrId)
+                            .arrayRow(true);
 
         addr = AddressUtils.formatOneline.apply(this, addrData);
     }
@@ -81,12 +80,18 @@ AddressUtils.getFormattedOnlineAddressById = function(pAddressId)
  * @return {String}
  */
 AddressUtils.getAddress = function(pContactId) {
-    var address = db.array(db.ROW, SqlCondition.begin().andPrepare("CONTACT.CONTACTID", pContactId).buildSql('select CONTACTID, ADDRESS, BUILDINGNO, ZIP, CITY, "NAME", FIRSTNAME, LASTNAME, TITLE from' + ContactUtils.getFullContactString(), "1=0"));
-    
+    var address = newSelect("CONTACTID, ADDRESS, BUILDINGNO, ZIP, CITY, \"NAME\", FIRSTNAME, LASTNAME, TITLE")
+                    .from(ContactUtils.getFullContactString())
+                    .whereIfSet("CONTACT.CONTACTID", pContactId)
+                    .arrayRow(true);
+                        
     // TODO: currently there are some relations without standard address. Use Hardcoded one.
     if (!address[1]) {
-        var dummyAddress = db.array(db.ROW, SqlCondition.begin().andPrepare("ADDRESS.ADDRESSID", '97d37aea-d7f8-4436-bb31-875439f5f7f1').buildSql('select ADDRESS, BUILDINGNO, ZIP, CITY from ADDRESS', "1=0"));
-        address[1] = dummyAddress[0];
+        var dummyAddress = newSelect("ADDRESS, BUILDINGNO, ZIP, CITY")
+                                .from("ADDRESS")
+                                .where("ADDRESS.ADDRESSID", '97d37aea-d7f8-4436-bb31-875439f5f7f1')
+                                .arrayRow();
+        address[1] = "DUMMYADDR - (no standard addr set)" + dummyAddress[0];
         address[2] = dummyAddress[1];
         address[3] = dummyAddress[2];
         address[4] = dummyAddress[3];
@@ -94,7 +99,7 @@ AddressUtils.getAddress = function(pContactId) {
     }
     var type = ContactUtils.getContactTypeByContactId(pContactId);
     
-    return AddressUtils.formatAddress(type, "DUMMYADDR - (no standard addr set)" + address[1], address[2], address[3], address[4], address[5], address[6], address[7], address[8]);
+    return AddressUtils.formatAddress(type, address[1], address[2], address[3], address[4], address[5], address[6], address[7], address[8]);
 }
 
 /**
@@ -105,14 +110,17 @@ AddressUtils.getAddress = function(pContactId) {
  * @return {String}
  */
 AddressUtils.getAddressById = function(pAddressId) {
-    var address = db.array(db.ROW, SqlCondition.begin()
-                                               .andPrepare("ADDRESS.ADDRESSID", pAddressId)
-                                               .buildSql("select CONTACT_ID, ADDRESS, BUILDINGNO, ZIP, CITY from "
-                                                          + "ADDRESS", "1=0"));
+    var address = newSelect("CONTACT_ID, ADDRESS, BUILDINGNO, ZIP, CITY")
+                    .from("ADDRESS")
+                    .whereIfSet("ADDRESS.ADDRESSID", pAddressId)
+                    .arrayRow(true);
     
     // TODO: currently there are some relations without standard address. Use Hardcoded one.
     if (!address[1]) {
-        var dummyAddress = db.array(db.ROW, SqlCondition.begin().andPrepare("ADDRESS.ADDRESSID", '97d37aea-d7f8-4436-bb31-875439f5f7f1').buildSql('select CONTACT_ID, ADDRESS, BUILDINGNO, ZIP, CITY from ADDRESS', "1=0"));
+        var dummyAddress = newSelect("CONTACT_ID, ADDRESS, BUILDINGNO, ZIP, CITY")
+                                .from("ADDRESS")
+                                .where("ADDRESS.ADDRESSID", '97d37aea-d7f8-4436-bb31-875439f5f7f1')
+                                .arrayRow();
         address[0] = dummyAddress[0];
         address[1] = dummyAddress[1];
         address[2] = dummyAddress[2];
@@ -124,10 +132,12 @@ AddressUtils.getAddressById = function(pAddressId) {
     
     if (address[0])
     {
-        var names = db.array(db.ROW, SqlCondition.begin()
-                                             .andPrepare("CONTACT.CONTACTID", address[0])
-                                             .buildSql("select ORGANISATION.NAME, FIRSTNAME, LASTNAME, TITLE from CONTACT left join PERSON on                                                           PERSONID = PERSON_ID left join ORGANISATION on ORGANISATIONID = ORGANISATION_ID"
-                                                            , "1=0"));
+        var names = newSelect("ORGANISATION.NAME, FIRSTNAME, LASTNAME, TITLE")
+                        .from("CONTACT")
+                        .leftJoin("PERSON", "PERSONID = PERSON_ID")
+                        .leftJoin("ORGANISATION", "ORGANISATIONID = ORGANISATION_ID")
+                        .where("CONTACT.CONTACTID", address[0])
+                        .arrayRow();
         return AddressUtils.formatAddress(type, address[1], address[2], address[3], address[4], names[0], names[1], names[2], names[3]);
     }
     
@@ -173,9 +183,13 @@ AddressUtils.formatAddress = function(pAddrType, pAddress, pBuildingno, pZip, pC
  * @return {String}
  */
 AddressUtils.getAllPossibleAddresses = function(pRelationId) {
-    var addresses = db.table(SqlCondition.begin().andPrepare("CONTACT.CONTACTID", pRelationId)
-                                                     .buildSql("select ADDRESSID, ADDR_TYPE, ADDRIDENTIFIER from ADDRESS join CONTACT on CONTACTID = CONTACT_ID or CONTACT_ID = ORGANISATION_ID", "1=0"));
-                                                     
+    var addresses = newSelect("ADDRESSID, ADDR_TYPE, ADDRIDENTIFIER")
+                        .from("ADDRESS")
+                        .join("CONTACT", newWhere("CONTACTID = CONTACT_ID")
+                                            .or("CONTACT_ID = ORGANISATION_ID"))
+                        .where("CONTACT.CONTACTID", pRelationId)
+                        .table();
+                                    
     return addresses.map(function(pAddress) {
         return [pAddress[0], KeywordUtils.getViewValue($KeywordRegistry.addressType(), pAddress[1]) + ": " + pAddress[2]];
     });
@@ -214,8 +228,10 @@ AddressValidationUtils._getRequiredFields = function(countryCode)
 {
     if (!countryCode)
         return "";
-    var requiredFields = db.cell(SqlCondition.begin().andPrepare("AB_COUNTRYINFO.ISO2", countryCode)
-                                                     .buildSql("select AB_COUNTRYINFO.REQUIRED_FIELDS from AB_COUNTRYINFO"));
+    var requiredFields = newSelect("AB_COUNTRYINFO.REQUIRED_FIELDS")
+                            .from("AB_COUNTRYINFO")
+                            .whereIfSet("AB_COUNTRYINFO.ISO2", countryCode)
+                            .cell(true);
     return requiredFields;
 };
 
@@ -242,12 +258,10 @@ AddressValidationUtils.isMandatoryField = function(countryCode, fieldCode)
  */
 AddressValidationUtils._getZipValidationRegEx = function(countryCode)
 {
-    if (!countryCode)
-        return "";
-    var cond = new SqlCondition();
-    cond.andPrepare("AB_COUNTRYINFO.ISO2", countryCode );
-    var stmt = cond.buildSql("select AB_COUNTRYINFO.ZIP_REGEX from AB_COUNTRYINFO");
-    return db.cell(stmt);
+    return newSelect("AB_COUNTRYINFO.ZIP_REGEX")
+                .from("AB_COUNTRYINFO")
+                .whereIfSet("AB_COUNTRYINFO.ISO2", countryCode)
+                .cell(true);
 };
 
 /**
diff --git a/process/Product_lib/process.js b/process/Product_lib/process.js
index 61310ddd92946d5186473c1b18f44436bde8b3c4..1c7f91318e380e29494e92336d82c25677160a6c 100644
--- a/process/Product_lib/process.js
+++ b/process/Product_lib/process.js
@@ -34,21 +34,23 @@ ProductUtils.getCurrentProductPrice = function(pid, buySell, onlyStandard) {
     if (pid != undefined && pid != "" && buySell != undefined && buySell != "")
     {
         var today = datetime.clearTime(vars.get("sys.date"), "utc");
-        var actualPriceCondition = SqlCondition.begin();
+        var actualPriceSelect = newSelect("PRICE, CURRENCY, VAT")
+                                    .from("PRODUCTPRICE")
+                                    .where();
         
         if (onlyStandard != undefined && onlyStandard)
         {
-            actualPriceCondition.andPrepare("PRODUCTPRICE.PRICELIST", $KeywordRegistry.productPricelist$standardList());
+            actualPriceSelect.and("PRODUCTPRICE.PRICELIST", $KeywordRegistry.productPricelist$standardList());
         }
                     
-        actualPriceCondition.andPrepare("PRODUCTPRICE.BUYSELL", buySell)
-                            .andPrepare("PRODUCTPRICE.PRODUCT_ID", pid)
-                            .andPrepare("PRODUCTPRICE.VALID_FROM", today, "# <= ?")
-                            .andSqlCondition(SqlCondition.begin()
-                                .orPrepare("PRODUCTPRICE.VALID_TO", today, "# >= ?")
-                                .or("PRODUCTPRICE.VALID_TO is null"), "1 = 2");
+        actualPriceSelect.and("PRODUCTPRICE.BUYSELL", buySell)
+                         .and("PRODUCTPRICE.PRODUCT_ID", pid)
+                         .and("PRODUCTPRICE.VALID_FROM", today, "# <= ?")
+                         .and(newWhere("PRODUCTPRICE.VALID_TO", today, "# >= ?")
+                                   .or("PRODUCTPRICE.VALID_TO is null"));
                             
-        var productPriceData = db.array(db.ROW, actualPriceCondition.buildSql("select PRICE, CURRENCY, VAT from PRODUCTPRICE", "1 = 2", "order by VALID_FROM desc"));
+        var productPriceData = actualPriceSelect.orderBy("VALID_FROM desc")
+                                                .arrayRow();
 
         if (productPriceData[0] && productPriceData[1])
             return  [productPriceData[0], KeywordUtils.getViewValue($KeywordRegistry.currency(), productPriceData[1]), productPriceData[2]];
@@ -71,10 +73,10 @@ ProductUtils.getCurrentProductPrice = function(pid, buySell, onlyStandard) {
 ProductUtils.getStockCount = function(pid) {
     if (pid != undefined && pid != "")
     {
-        var sum = db.cell(SqlCondition.begin()
-                                      .andPrepare("STOCK.PRODUCT_ID", pid)
-                                      .buildSql("select sum(QUANTITY * case IN_OUT when 0 then -1 else 1)"
-                                                 + " from STOCK"));
+        var sum = newSelect("sum(QUANTITY * case IN_OUT when 0 then -1 else 1)")
+                        .from("STOCK")
+                        .whereIfSet("STOCK.PRODUCT_ID", pid)
+                        .cell(true, "0");
         
         if (sum == "")
             sum = "0";
@@ -162,7 +164,7 @@ ProductUtils.getProductDetails = function(pid, priceListFilter, additionalProduc
     
     cols = cols.concat(colsProduct);
 
-    var joins = [];
+    var joins = []; // should contain: arrays of [joinPrefix, table, tableAlias, conditioinAsStringOrSqlBuilder]
     var orderby = ["PRODUCTID"];
 
     //PriceList (all)
@@ -170,7 +172,7 @@ ProductUtils.getProductDetails = function(pid, priceListFilter, additionalProduc
                         , "allPP.VALID_FROM", "allPP.VALID_TO", "allPP.BUYSELL", "allPP.FROMQUANTITY", "allPP.CURRENCY"];
 
     cols = cols.concat(colsPricelistAll);
-    joins.push(" left join PRODUCTPRICE allPP on allPP.PRODUCT_ID = PRODUCTID ");
+    joins.push(["left", "PRODUCTPRICE", "allPP", "allPP.PRODUCT_ID = PRODUCTID"]);
 
     //PriceList (currently valid)
     var validPriceLists = false;
@@ -184,33 +186,34 @@ ProductUtils.getProductDetails = function(pid, priceListFilter, additionalProduc
         orderby = orderby.concat(["validPP.VALID_FROM desc", "validPP.FROMQUANTITY desc"]);
 
         cols = cols.concat(colsPricelistValid);
-        joins.push("left join PRODUCTPRICE validPP on " 
-                    + SqlCondition.begin()
-                               .and("validPP.PRODUCT_ID = PRODUCTID")
-                               .andPrepare(["PRODUCTPRICE", "CURRENCY", "validPP"], priceListFilter.currency)
-                                .andPrepare(["PRODUCTPRICE", "VALID_FROM", "validPP"], datetime.date().toString(), "# <= ?")
-                                .andSqlCondition(SqlCondition.begin()
-                                    .andPrepare(["PRODUCTPRICE", "VALID_TO", "validPP"], datetime.date().toString(), "# >= ?")
-                                    .or("validPP.VALID_TO is null")
-                                )
-                               .andPrepare(["PRODUCTPRICE", "FROMQUANTITY", "validPP"], priceListFilter.quantity, "# <= ?")
-                               .andSqlCondition(SqlCondition.begin()
-                                    .orPrepare(["PRODUCTPRICE", "CONTACT_ID", "validPP"], priceListFilter.relationId)
-                                    .orSqlCondition(SqlCondition.begin()
-                                        .and("validPP.CONTACT_ID is null")
-                                        .andPrepare(["PRODUCTPRICE", "BUYSELL", "validPP"], 'SP'), 
-                                    "1 = 2"), 
-                                "1 = 2")
-                                .translate("1 = 2"))
+        joins.push(["left", "PRODUCTPRICE", "validPP", 
+                        newWhere("validPP.PRODUCT_ID = PRODUCTID")
+                            .and(["PRODUCTPRICE", "CURRENCY", "validPP"], priceListFilter.currency)
+                            .and(["PRODUCTPRICE", "VALID_FROM", "validPP"], datetime.date().toString(), "# <= ?")
+                            .and(newWhere()
+                                    .or(["PRODUCTPRICE", "VALID_TO", "validPP"], datetime.date().toString(), "# >= ?")
+                                    .or("validPP.VALID_TO is null"))
+                            .and(["PRODUCTPRICE", "FROMQUANTITY", "validPP"], priceListFilter.quantity, "# <= ?")
+                            .and(newWhere()
+                                    .or(["PRODUCTPRICE", "CONTACT_ID", "validPP"], priceListFilter.relationId)
+                                    .or(newWhere()
+                                            .and("validPP.CONTACT_ID is null")
+                                            .and(["PRODUCTPRICE", "BUYSELL", "validPP"], 'SP')))
+                    ]);
     }
     
-    var ProductDataSql = SqlCondition.begin()
-                            .andPrepare("PRODUCT.PRODUCTID", pid)
-                            .buildSql("select " + cols.join(", ") + " from PRODUCT " + joins.join(" "),
-                                         "1 = 2",
-                                         "order by " + orderby.join(", "))
-                                         
-    var ProductData = db.table(ProductDataSql);
+    var productDataSql = newSelect(cols)
+                            .from("PRODUCT")
+                            
+    joins.forEach(function(pJoin)
+    {
+        this.join(pJoin[1], pJoin[3], pJoin[2], pJoin[0]);
+    }, productDataSql)
+        
+     var ProductData = productDataSql
+                        .where("PRODUCT.PRODUCTID", pid)
+                        .orderBy(orderby)
+                        .table();
 
     for (var i = 0; i < ProductData.length; i++)
     {
diff --git a/process/Salesproject_lib/process.js b/process/Salesproject_lib/process.js
index 981f58e59787e82ee5ad4be9b7a4cd41cc69c659..0bff3a0ff69898a74cb169f82d44ec09d0aa8932 100644
--- a/process/Salesproject_lib/process.js
+++ b/process/Salesproject_lib/process.js
@@ -49,23 +49,17 @@ Salesproject.validateProjectNumber = function(projectNumber) {
  */
 Salesproject.insertMilestone = function(salesprojectId, type, value, notifyForecast) {
     if (KeywordUtils.exists(value, type)) {
-        var id= db.cell(SqlCondition.begin()
-                        .andPrepare("SALESPROJECT_MILESTONE.SALESPROJECT_ID", salesprojectId)
-                        .andPrepare("SALESPROJECT_MILESTONE.KIND", type)
-                        .and("SALESPROJECT_MILESTONE.DATE_END is null")
-                        .buildSql("select SALESPROJECT_MILESTONE.SALESPROJECT_MILESTONEID from SALESPROJECT_MILESTONE "));
+        var id = newSelect("SALESPROJECT_MILESTONE.SALESPROJECT_MILESTONEID")
+                    .from("SALESPROJECT_MILESTONE")
+                    .where("SALESPROJECT_MILESTONE.SALESPROJECT_ID", salesprojectId)
+                    .and("SALESPROJECT_MILESTONE.KIND", type)
+                    .and("SALESPROJECT_MILESTONE.DATE_END is null")
+                    .cell();       
         
-        
-        db.updateData(
-            "SALESPROJECT_MILESTONE",
-            ["DATE_END"],
-            null,
-            [vars.get("$sys.date")],
-            SqlCondition.begin()
-                        .andPrepare("SALESPROJECT_MILESTONE.SALESPROJECT_ID", salesprojectId)
-                        .andPrepare("SALESPROJECT_MILESTONE.KIND", type)
-                        .and("SALESPROJECT_MILESTONE.DATE_END is null")
-                        .build("1=2"));
+        newWhere("SALESPROJECT_MILESTONE.SALESPROJECT_ID", salesprojectId)
+            .and("SALESPROJECT_MILESTONE.KIND", type)
+            .and("SALESPROJECT_MILESTONE.DATE_END is null")
+            .updateData(true, ["DATE_END"], null, [vars.get("$sys.date")], "SALESPROJECT_MILESTONE");
         
         db.insertData(
             "SALESPROJECT_MILESTONE",
@@ -96,9 +90,10 @@ Salesproject.notifyToUpdateForecast = function() {
  */
 Salesproject.getSalesProjectTitleById = function(pSalesProjectId)
 {
-    return db.cell( SqlCondition.begin()
-                        .andPrepare("SALESPROJECT.SALESPROJECTID", pSalesProjectId)
-                        .buildSql("select PROJECTTITLE from SALESPROJECT", "1=0"));
+    return newSelect("PROJECTTITLE")
+                .from("SALESPROJECT")
+                .where("SALESPROJECT.SALESPROJECTID", pSalesProjectId)
+                .cell();
 }
 
 /**
diff --git a/process/SqlLib_tests/SqlLib_tests.aod b/process/SqlLib_tests/SqlLib_tests.aod
new file mode 100644
index 0000000000000000000000000000000000000000..eef9797dca72eed272601f6841e8e4e0465ce180
--- /dev/null
+++ b/process/SqlLib_tests/SqlLib_tests.aod
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<process xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.2.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/process/1.2.1">
+  <name>SqlLib_tests</name>
+  <majorModelMode>DISTRIBUTED</majorModelMode>
+  <process>%aditoprj%/process/SqlLib_tests/process.js</process>
+  <alias>Data_alias</alias>
+  <variants>
+    <element>EXECUTABLE</element>
+  </variants>
+</process>
diff --git a/process/SqlLib_tests/process.js b/process/SqlLib_tests/process.js
new file mode 100644
index 0000000000000000000000000000000000000000..e73201a7ec719c960e9b041d95453321e4ed01e3
--- /dev/null
+++ b/process/SqlLib_tests/process.js
@@ -0,0 +1,774 @@
+import("system.db");
+import("system.vars");
+import("system.translate");
+import("system.logging");
+import("system.SQLTYPES");
+import("Sql_lib");
+import("UnitTest_lib");
+
+var validAndUsageTests = new TestSuite([
+    ["and should just add simple strings as condition just as it is", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where("PERSON.FIRSTNAME = 'Tim'") // NOTE: you should not do this as this does not add a real prepared statement with "?"
+                            .and("PERSON.LASTNAME = 'Admin'")
+
+        pTester.assert("PERSON.FIRSTNAME = 'Tim' and PERSON.LASTNAME = 'Admin'", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(0, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["and should add a condition if field and value are passed", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where("PERSON.FIRSTNAME", "Tim")
+                            .and("PERSON.LASTNAME", "Admin")
+                            
+        pTester.assert("PERSON.FIRSTNAME = ? and PERSON.LASTNAME = ?", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(2, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["and should add a condition if value is an empty string", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where("PERSON.FIRSTNAME", "")
+                            .and("PERSON.LASTNAME", "")
+                            
+        pTester.assert("PERSON.FIRSTNAME = ? and PERSON.LASTNAME = ?", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(2, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["and should add a condition if field and value as jdito-var are passed", function(pTester)
+    {
+        vars.set("$global.TestUnitValueName", "Tim");
+        var actual = new SqlBuilder()
+                            .where("PERSON.FIRSTNAME", "$global.TestUnitValueName")
+                            
+        pTester.assert("( PERSON.FIRSTNAME = 'Tim' ) ", actual.toString());
+    }],
+
+    ["and should add a condition if value is a jdito-var containing an empty string", function(pTester)
+    {
+        vars.set("$global.TestingVarEmptyString", "");
+        var actual = new SqlBuilder()
+                            .where("PERSON.FIRSTNAME", "$global.TestingVarEmptyString")
+                            .and("PERSON.LASTNAME", "$global.TestingVarEmptyString")
+                            
+        pTester.assert("PERSON.FIRSTNAME = ? and PERSON.LASTNAME = ?", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(2, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["and should use the given condition pattern", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where("PERSON.FIRSTNAME", "Tim", "# <> ?")
+                            .and("PERSON.LASTNAME", "Admin")
+                            
+        pTester.assert("PERSON.FIRSTNAME <> ? and PERSON.LASTNAME = ?", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(2, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["and should use the given SQLTYPE if provided", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where("PERSON.FIRSTNAME", 6, null, SQLTYPES.INTEGER)
+                            .and("PERSON.LASTNAME", 7, undefined, SQLTYPES.INTEGER)
+                            .and("PERSON.LASTNAME", 8, "# <> ?", SQLTYPES.INTEGER)
+        
+        pTester.assert("PERSON.FIRSTNAME = ? and PERSON.LASTNAME = ? and PERSON.LASTNAME <> ?", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(3, actual._where.preparedValues.length, "number of params");
+        pTester.assert(SQLTYPES.INTEGER, actual._where.preparedValues[0][1], "sql type of param 1 is the provided type");
+        pTester.assert(SQLTYPES.INTEGER, actual._where.preparedValues[1][1], "sql type of param 2 is the provided type");
+        pTester.assert(SQLTYPES.INTEGER, actual._where.preparedValues[2][1], "sql type of param 3 is the provided type");
+    }],
+
+    ["and only with a prepared statement-array should just use it as it is", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where([
+                                "PERSON.FIRSTNAME = ?", [["Peter", 12]]
+                            ])
+                            .and([
+                                "exists (select * FROM CONTACT where PERSON_ID = PERSONID)", []
+                            ])
+                            
+        pTester.assert(" ( PERSON.FIRSTNAME = ? )  and  ( exists (select * FROM CONTACT where PERSON_ID = PERSONID) ) ", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(1, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["and only with a SqlBulder object should just use the condition from it", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where(new SqlBuilder()
+                                .where("PERSON.FIRSTNAME", "Tim")
+                                .and("PERSON.LASTNAME", "Admin"))
+                            
+        pTester.assert(" ( PERSON.FIRSTNAME = ? and PERSON.LASTNAME = ? ) ", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(2, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["and with a builder as value and condition (field is null|undefined) should add the whole builder as subquery", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where(null, new SqlBuilder()
+                                .select("FIRSTNAME")
+                                .from("PERSON")
+                                .where("PERSON.FIRSTNAME", "Tim")
+                                .and("PERSON.LASTNAME", "Admin"),
+                                "exists ?")  // Note: you can use SqlBuilder.EXISTS() instead of  "exists ?"
+        
+        pTester.assert("exists  ( select FIRSTNAME from PERSON where PERSON.FIRSTNAME = ? and PERSON.LASTNAME = ? ) ", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(2, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["and with a builder as value and field should add the whole builder as subquery with field = (subquery)", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where("PERSON.FIRSTNAME", new SqlBuilder()
+                                .select("FIRSTNAME")
+                                .from("PERSON")
+                                .where("PERSON.FIRSTNAME", "Tim")
+                                .and("PERSON.LASTNAME", "Admin"))
+        
+        pTester.assert("PERSON.FIRSTNAME =  ( select FIRSTNAME from PERSON where PERSON.FIRSTNAME = ? and PERSON.LASTNAME = ? ) ", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(2, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["and with a prepared statement-array as value and field is null|undefined should add the whole statement as subquery", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where(null, ["select FIRSTNAME from PERSON.FIRSTNAME = ?", [["Peter", 12]]], "exists ?")
+                            .and(null, ["exists (select FIRSTNAME from PERSON.FIRSTNAME = ?)", [["Peter", 12]]]) // also without pCond it should work as the condition could be included in the prep statement
+        
+        pTester.assert("exists  ( select FIRSTNAME from PERSON.FIRSTNAME = ? )  and  ( exists (select FIRSTNAME from PERSON.FIRSTNAME = ?) ) ", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(2, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["and with a prepared statement-array as value and field should add the whole statement as subquery with field = (subquery)", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where("PERSON.FIRSTNAME", ["select FIRSTNAME from PERSON.FIRSTNAME = ?", [["Peter", 12]]])
+        
+        pTester.assert("PERSON.FIRSTNAME =  ( select FIRSTNAME from PERSON.FIRSTNAME = ? ) ", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(1, actual._where.preparedValues.length, "number of params");
+    }]
+]);
+
+var validOrUsageTests = new TestSuite([
+    ["or should just add simple strings as condition just as it is", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where("PERSON.FIRSTNAME = 'Tim'") // NOTE: you should not do this as this does not add a real prepared statement with "?"
+                            .or("PERSON.LASTNAME = 'Admin'")
+
+        pTester.assert("PERSON.FIRSTNAME = 'Tim' or PERSON.LASTNAME = 'Admin'", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(0, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["or should add a condition if field and value are passed", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where("PERSON.FIRSTNAME", "Tim")
+                            .or("PERSON.LASTNAME", "Admin")
+                            
+        pTester.assert("PERSON.FIRSTNAME = ? or PERSON.LASTNAME = ?", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(2, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["or should use the given condition pattern", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where("PERSON.FIRSTNAME", "Tim", "# <> ?")
+                            .or("PERSON.LASTNAME", "Admin")
+                            
+        pTester.assert("PERSON.FIRSTNAME <> ? or PERSON.LASTNAME = ?", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(2, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["or should use the given SQLTYPE if provided", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where("PERSON.FIRSTNAME", 6, null, SQLTYPES.INTEGER)
+                            .or("PERSON.LASTNAME", 7, undefined, SQLTYPES.INTEGER)
+                            .or("PERSON.LASTNAME", 8, "# <> ?", SQLTYPES.INTEGER)
+                            
+        pTester.assert("PERSON.FIRSTNAME = ? or PERSON.LASTNAME = ? or PERSON.LASTNAME <> ?", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(3, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["or only with a prepared statement-array should just use it as it is", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where([
+                                "PERSON.FIRSTNAME = ?", [["Peter", 12]]
+                            ])
+                            .or([
+                                "exists (select * FROM CONTACT where PERSON_ID = PERSONID)", []
+                            ])
+                            
+        pTester.assert(" ( PERSON.FIRSTNAME = ? )  or  ( exists (select * FROM CONTACT where PERSON_ID = PERSONID) ) ", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(1, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["or only with a SqlBulder object should just use the condition from it", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where(new SqlBuilder()
+                                .where("PERSON.FIRSTNAME", "Tim")
+                                .or("PERSON.LASTNAME", "Admin"))
+                            
+        pTester.assert(" ( PERSON.FIRSTNAME = ? or PERSON.LASTNAME = ? ) ", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(2, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["or with a builder as value and condition (field is null|undefined) should add the whole builder as subquery", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where(null, new SqlBuilder()
+                                .select("FIRSTNAME")
+                                .from("PERSON")
+                                .where("PERSON.FIRSTNAME", "Tim")
+                                .or("PERSON.LASTNAME", "Admin"),
+                                "exists ?")
+        
+        pTester.assert("exists  ( select FIRSTNAME from PERSON where PERSON.FIRSTNAME = ? or PERSON.LASTNAME = ? ) ", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(2, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["or with a builder as value and field should add the whole builder as subquery with field = (subquery)", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where("PERSON.FIRSTNAME", new SqlBuilder()
+                                .select("FIRSTNAME")
+                                .from("PERSON")
+                                .where("PERSON.FIRSTNAME", "Tim")
+                                .or("PERSON.LASTNAME", "Admin"))
+        
+        pTester.assert("PERSON.FIRSTNAME =  ( select FIRSTNAME from PERSON where PERSON.FIRSTNAME = ? or PERSON.LASTNAME = ? ) ", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(2, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["or with a prepared statement-array as value and field is null|undefined should add the whole statement as subquery", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where(null, ["select FIRSTNAME from PERSON.FIRSTNAME = ?", [["Peter", 12]]], "exists ?")
+                            .or(null, ["exists (select FIRSTNAME from PERSON.FIRSTNAME = ?)", [["Peter", 12]]]) // also without pCond it should work as the condition could be included in the prep statement
+        
+        pTester.assert("exists  ( select FIRSTNAME from PERSON.FIRSTNAME = ? )  or  ( exists (select FIRSTNAME from PERSON.FIRSTNAME = ?) ) ", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(2, actual._where.preparedValues.length, "number of params");
+    }]
+]);
+
+var combinedAndOrTests = new TestSuite([
+    ["or combining two and", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                        .where("PERSON.FIRSTNAME", "Tim")
+                        .and("PERSON.LASTNAME", "Admin")
+                        .or(new SqlBuilder()
+                                .where("PERSON.FIRSTNAME", "Peter")
+                                .and("PERSON.LASTNAME", "Müller"))
+        
+        pTester.assert("(PERSON.FIRSTNAME = ? and PERSON.LASTNAME = ?) or  ( PERSON.FIRSTNAME = ? and PERSON.LASTNAME = ? ) ", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(4, actual._where.preparedValues.length, "number of params");
+    }],
+    
+    ["and combining two or", function(pTester)
+    {                 
+        var actual = new SqlBuilder()
+                        .where(new SqlBuilder()
+                                .where("PERSON.FIRSTNAME", "Tim")
+                                .or("PERSON.LASTNAME", "Admin"))
+                        .and(new SqlBuilder()
+                                .where("PERSON.FIRSTNAME", "Peter")
+                                .or("PERSON.LASTNAME", "Müller"))
+        
+        pTester.assert(" ( PERSON.FIRSTNAME = ? or PERSON.LASTNAME = ? )  and  ( PERSON.FIRSTNAME = ? or PERSON.LASTNAME = ? ) ", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(4, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["some and/or combinations in one select", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                        .where("PERSON.FIRSTNAME", "Tim")
+                        .or("PERSON.FIRSTNAME", "Franz")
+                        .and("PERSON.LASTNAME", "Admin")
+                        .and(new SqlBuilder()
+                                .where("PERSON.FIRSTNAME", "Peter")
+                                .or("PERSON.LASTNAME", "Müller"))
+                        .or("PERSON.FIRSTNAME", "Franz")
+                        .and("PERSON.FIRSTNAME", "Franz")
+                        .or(new SqlBuilder()
+                                .where("PERSON.FIRSTNAME", "Peter")
+                                .and("PERSON.LASTNAME", "Müller")
+                                .and(new SqlBuilder()
+                                        .where("PERSON.FIRSTNAME", "Peter")
+                                        .or("PERSON.LASTNAME", "Müller")))
+                        
+        pTester.assert("PERSON.FIRSTNAME = ? or PERSON.FIRSTNAME = ? and PERSON.LASTNAME = ? and  ( PERSON.FIRSTNAME = ? or PERSON.LASTNAME = ? )  or (PERSON.FIRSTNAME = ?) and PERSON.FIRSTNAME = ? or  ( PERSON.FIRSTNAME = ? and PERSON.LASTNAME = ? and  ( PERSON.FIRSTNAME = ? or PERSON.LASTNAME = ? )  ) ", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(11, actual._where.preparedValues.length, "number of params");
+    }]
+]);
+
+var ifSetTests = new TestSuite([
+    ["simple and if set with all types of empty values.", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                        .whereIfSet("PERSON.LASTNAME", null)
+                        .andIfSet("PERSON.LASTNAME", undefined)
+                        
+        pTester.assert("", actual._where._sqlStorage, "no sql should be added");
+        pTester.assert(0, actual._where.preparedValues.length, "no params should be added");
+    }],
+
+    ["jdito variable with null", function(pTester)
+    {
+        vars.set("$global.TestingVarNull", null);
+        
+        var actual = new SqlBuilder()
+                        .whereIfSet("PERSON.FIRSTNAME", "$global.TestingVarNull")
+                        
+        pTester.assert("", actual._where._sqlStorage, "no sql should be added");
+        pTester.assert(0, actual._where.preparedValues.length, "no params should be added");
+    }],
+
+    ["empty simple conditions", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                        .whereIfSet("")
+                        .andIfSet(["", []])
+                        .andIfSet(new SqlBuilder())
+                        
+        pTester.assert("", actual._where._sqlStorage, "no sql should be added");
+        pTester.assert(0, actual._where.preparedValues.length, "no params should be added");
+    }],
+
+    ["empty subqueries", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                        .whereIfSet("PERSON.FIRSTNAME", ["", []])
+                        .andIfSet("PERSON.LASTNAME", new SqlBuilder())
+                        
+        pTester.assert("", actual._where._sqlStorage, "no sql should be added");
+        pTester.assert(0, actual._where.preparedValues.length, "no params should be added");
+    }]
+]);
+
+function cleanWrapperTests()
+{
+    try {
+        db.runStatement("drop table SQL_LIB_TEST_TABLE");
+    } catch(ex) {}
+    
+    try {
+        db.deleteData("PERSON", "PERSONID in ('TEST-5', 'TEST-6')")
+    } catch(ex) {}
+    
+}
+
+var dbWrapperTests = new TestSuite([
+    ["cell should load only one value", function(pTester)
+    {
+        var builder = new SqlBuilder()
+                            .select("FIRSTNAME")
+                            .from("PERSON")
+                            .where("PERSON.PERSONID", "TEST-5")
+        pTester.assert("Franz", builder.cell());
+    }],
+
+    ["cell should just return '' if no condition set but pExecuteOnlyIfConditionExists is true", function(pTester)
+    {
+        var builder = new SqlBuilder()
+                            .select("FIRSTNAME")
+                            .from("PERSON")
+        pTester.assert("", builder.cell(true));
+    }],
+
+    ["cell should return a value if no condition set and pExecuteOnlyIfConditionExists is false", function(pTester)
+    {
+        var builder = new SqlBuilder()
+                            .select("FIRSTNAME")
+                            .from("PERSON");
+                            
+        var actual = builder.cell(false)
+        pTester.assert(true, actual !== "" && actual !== null && actual !== undefined);
+    }],
+
+    ["array should load an array of values", function(pTester)
+    {
+        var builder = new SqlBuilder()
+                            .select("FIRSTNAME, LASTNAME")
+                            .from("PERSON")
+                            .where("PERSON.PERSONID", "TEST-5");
+                            
+        var actual = builder.array(db.ROW);
+        pTester.assert("Franz", actual[0], "firstname should be 'Franz'");
+        pTester.assert("Müller", actual[1], "lastname should be 'Müller'");
+    }],
+
+    ["array should return an empty array if no condition set but pExecuteOnlyIfConditionExists is true", function(pTester)
+    {
+        var builder = new SqlBuilder()
+                            .select("FIRSTNAME, LASTNAME")
+                            .from("PERSON")
+                            
+        var actual = builder.array(db.ROW, true);
+        pTester.assert(0, actual.length);
+    }],
+
+    ["array should return a non-empty array if no condition set and pExecuteOnlyIfConditionExists is false", function(pTester)
+    {
+        var builder = new SqlBuilder()
+                            .select("FIRSTNAME, LASTNAME")
+                            .from("PERSON")
+                            
+        var actual = builder.array(db.ROW, false);
+        pTester.assert(true, actual.length > 0);
+    }],
+ 
+    ["table should load an array of arrays with values", function(pTester)
+    {
+        var builder = new SqlBuilder()
+                            .select("FIRSTNAME, LASTNAME")
+                            .from("PERSON")
+                            .where("PERSON.PERSONID", "TEST-5")
+                            .or("PERSON.PERSONID", "TEST-6")
+                            .orderBy("PERSONID asc");
+                            
+        var actual = builder.table();
+        pTester.assert("Franz", actual[0][0], "firstname should be 'Franz'");
+        pTester.assert("Müller", actual[0][1], "lastname should be 'Müller'");
+        
+        pTester.assert("Marco", actual[1][0], "firstname should be 'Marco'");
+        pTester.assert("Polo", actual[1][1], "lastname should be 'Polo'");
+    }],
+
+    ["table should return an empty array if no condition set but pExecuteOnlyIfConditionExists is true", function(pTester)
+    {
+        var builder = new SqlBuilder()
+                            .select("FIRSTNAME, LASTNAME")
+                            .from("PERSON");
+                            
+        var actual = builder.table(true);
+        pTester.assert(0, actual.length);
+    }],
+
+    ["table should return a non-empty array if no condition set and pExecuteOnlyIfConditionExists is false", function(pTester)
+    {
+        var builder = new SqlBuilder()
+                            .select("FIRSTNAME, LASTNAME")
+                            .from("PERSON");
+                            
+        var actual = builder.table(false);
+        pTester.assert(true, actual.length > 0);
+    }],
+
+    ["delete should delete the data and use the from and condition from the builder", function(pTester)
+    {
+        db.deleteData("SQL_LIB_TEST_TABLE", "TESTID = 'TEST-7'");
+        db.insertData("SQL_LIB_TEST_TABLE", ["TESTID", "FIRSTNAME", "LASTNAME"], null, ["TEST-7", "Ludwig", "Fischer"]);
+        
+        var builder = new SqlBuilder()
+                            .from("SQL_LIB_TEST_TABLE")
+                            .where("SQL_LIB_TEST_TABLE.TESTID", "TEST-7");
+                            
+        var deletedRows = builder.deleteData();
+        pTester.assert(1, deletedRows);
+    }],
+
+    ["delete should delete the data from the provided table and use the condition from the builder. It ignores .from if a table is given.", function(pTester)
+    {
+        db.deleteData("SQL_LIB_TEST_TABLE", "TESTID = 'TEST-7'");
+        db.insertData("SQL_LIB_TEST_TABLE", ["TESTID", "FIRSTNAME", "LASTNAME"], null, ["TEST-7", "Ludwig", "Fischer"]);
+        
+        var builder = new SqlBuilder()
+                            .from("PERSON")
+                            .where("SQL_LIB_TEST_TABLE.TESTID", "TEST-7");
+                            
+        var deletedRows = builder.deleteData(false, "SQL_LIB_TEST_TABLE");
+        pTester.assert(1, deletedRows);
+    }],
+
+    ["delete should delete ALL data from a table if the builder has no condition and pExecuteOnlyIfConditionExists is false", function(pTester)
+    {
+        db.deleteData("SQL_LIB_TEST_TABLE", "TESTID in ('TEST-7', 'TEST-8')");
+        db.insertData("SQL_LIB_TEST_TABLE", ["TESTID", "FIRSTNAME", "LASTNAME"], null, ["TEST-7", "Ludwig", "Fischer"]);
+        db.insertData("SQL_LIB_TEST_TABLE", ["TESTID", "FIRSTNAME", "LASTNAME"], null, ["TEST-8", "Ludwig", "Fischer"]);
+        
+        var builder = new SqlBuilder()
+                            .from("SQL_LIB_TEST_TABLE")
+                            
+        var deletedRows = builder.deleteData(false);
+        pTester.assert(2, deletedRows);
+    }],
+
+    ["delete should delete NO data from a table if the builder has no condition and pExecuteOnlyIfConditionExists is true", function(pTester)
+    {
+        db.deleteData("SQL_LIB_TEST_TABLE", "TESTID in ('TEST-7', 'TEST-8')");
+        db.insertData("SQL_LIB_TEST_TABLE", ["TESTID", "FIRSTNAME", "LASTNAME"], null, ["TEST-7", "Ludwig", "Fischer"]);
+        db.insertData("SQL_LIB_TEST_TABLE", ["TESTID", "FIRSTNAME", "LASTNAME"], null, ["TEST-8", "Ludwig", "Fischer"]);
+        
+        var builder = new SqlBuilder()
+                            .from("SQL_LIB_TEST_TABLE")
+                            
+        var deletedRows = builder.deleteData(true);
+        pTester.assert(0, deletedRows);
+    }],
+
+    ["update should update the data and use the from and condition from the builder", function(pTester)
+    {
+        db.deleteData("SQL_LIB_TEST_TABLE", "TESTID = 'TEST-7'");
+        db.insertData("SQL_LIB_TEST_TABLE", ["TESTID", "FIRSTNAME", "LASTNAME"], null, ["TEST-7", "Ludwig", "Fischer"]);
+        
+        var builder = new SqlBuilder()
+                            .from("SQL_LIB_TEST_TABLE")
+                            .where("SQL_LIB_TEST_TABLE.TESTID", "TEST-7");
+                            
+        builder.updateData(false, ["FIRSTNAME"], null, ["Fritz"]);
+        
+        var actual = db.cell("select FIRSTNAME from SQL_LIB_TEST_TABLE where SQL_LIB_TEST_TABLE.TESTID = 'TEST-7'")
+        
+        pTester.assert("Fritz", actual);
+    }],
+
+    ["update should update the data from the provided table and use the condition from the builder. It ignores .from if a table is given.", function(pTester)
+    {
+        db.deleteData("SQL_LIB_TEST_TABLE", "TESTID = 'TEST-7'");
+        db.insertData("SQL_LIB_TEST_TABLE", ["TESTID", "FIRSTNAME", "LASTNAME"], null, ["TEST-7", "Ludwig", "Fischer"]);
+        
+        var builder = new SqlBuilder()
+                            .from("PERSON")
+                            .where("SQL_LIB_TEST_TABLE.TESTID", "TEST-7");
+                            
+        builder.updateData(false, ["FIRSTNAME"], null, ["Fritz"], "SQL_LIB_TEST_TABLE");
+        
+        var actual = db.cell("select FIRSTNAME from SQL_LIB_TEST_TABLE where SQL_LIB_TEST_TABLE.TESTID = 'TEST-7'")
+        
+        pTester.assert("Fritz", actual);
+    }],
+
+    ["update should update ALL data from a table if the builder has no condition and pExecuteOnlyIfConditionExists is false", function(pTester)
+    {
+        db.deleteData("SQL_LIB_TEST_TABLE", "TESTID in ('TEST-7', 'TEST-8')");
+        db.insertData("SQL_LIB_TEST_TABLE", ["TESTID", "FIRSTNAME", "LASTNAME"], null, ["TEST-7", "Ludwig", "Fischer"]);
+        db.insertData("SQL_LIB_TEST_TABLE", ["TESTID", "FIRSTNAME", "LASTNAME"], null, ["TEST-8", "Franz", "Fischer"]);
+        
+        var builder = new SqlBuilder()
+                            .from("SQL_LIB_TEST_TABLE")
+                            
+        builder.updateData(false, ["FIRSTNAME"], null, ["Fritz"]);
+        
+        var actual1 = db.cell("select FIRSTNAME from SQL_LIB_TEST_TABLE where SQL_LIB_TEST_TABLE.TESTID = 'TEST-7'")
+        var actual2 = db.cell("select FIRSTNAME from SQL_LIB_TEST_TABLE where SQL_LIB_TEST_TABLE.TESTID = 'TEST-8'")
+        
+        pTester.assert("Fritz", actual1, "TEST-7 should have Firstname Fritz");        
+        pTester.assert("Fritz", actual2, "TEST-8 should have Firstname Fritz");
+    }],
+
+    ["update should update NO data from a table if the builder has no condition and pExecuteOnlyIfConditionExists is true", function(pTester)
+    {
+        db.deleteData("SQL_LIB_TEST_TABLE", "TESTID in ('TEST-7', 'TEST-8')")        
+        db.insertData("SQL_LIB_TEST_TABLE", ["TESTID", "FIRSTNAME", "LASTNAME"], null, ["TEST-7", "Ludwig", "Fischer"]);
+        db.insertData("SQL_LIB_TEST_TABLE", ["TESTID", "FIRSTNAME", "LASTNAME"], null, ["TEST-8", "Franz", "Fischer"]);
+        
+        var builder = new SqlBuilder()
+                            .from("SQL_LIB_TEST_TABLE")
+                            
+        builder.updateData(true, ["FIRSTNAME"], null, ["Fritz"]);
+        
+        var actual1 = db.cell("select FIRSTNAME from SQL_LIB_TEST_TABLE where SQL_LIB_TEST_TABLE.TESTID = 'TEST-7'")
+        var actual2 = db.cell("select FIRSTNAME from SQL_LIB_TEST_TABLE where SQL_LIB_TEST_TABLE.TESTID = 'TEST-8'")
+        
+        pTester.assert("Ludwig", actual1, "TEST-7 should have Firstname Ludwig");        
+        pTester.assert("Franz", actual2, "TEST-8 should have Firstname Franz");
+    }]
+], function preAll() 
+{
+    // remove data which may exist if previous test-run failed and postAll was not executed
+    cleanWrapperTests()
+    
+    // add table for save testing of deletes
+    db.runStatement("create table SQL_LIB_TEST_TABLE (TESTID varchar(36), FIRSTNAME varchar(100), LASTNAME varchar(100))");
+    
+    // add test persons
+    db.insertData("PERSON", ["PERSONID", "FIRSTNAME", "LASTNAME", "USER_NEW", "DATE_NEW"], null, ["TEST-5", "Franz", "Müller", "testuser", vars.get("$sys.date")])
+    db.insertData("PERSON", ["PERSONID", "FIRSTNAME", "LASTNAME", "USER_NEW", "DATE_NEW"], null, ["TEST-6", "Marco", "Polo", "testuser", vars.get("$sys.date")])
+}, undefined, undefined, function postAll()
+{
+    cleanWrapperTests()
+})
+
+var mandatoryErrorTests = new TestSuite([
+// and
+    ["and without parameter should error", function(pTester)
+    {
+        new SqlBuilder().where().or();
+    }, SqlBuilder.ERROR_NO_PARAMETER_PROVIDED()],
+
+    ["and with null as value should error", function(pTester)
+    {
+        new SqlBuilder().where().or("PERSON.FIRSTNAME", null);
+    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY()],
+
+    ["and with undefined as value should error", function(pTester)
+    {
+        new SqlBuilder().where().or("PERSON.FIRSTNAME", undefined);
+    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY()],
+
+    ["and with a jdito-var containing null should error", function(pTester)
+    {
+        vars.set("$global.TestingVarNull", null);
+        
+        new SqlBuilder().where().or("PERSON.FIRSTNAME", "$global.TestingVarNull");
+    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY_JDITO_VAR()],
+
+    ["and with an empty sql-builder as subquery should error", function(pTester)
+    {        
+        new SqlBuilder().where().or("PERSON.FIRSTNAME", new SqlBuilder());
+    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY()],
+
+    ["and with an empty prepared statement as subquery should error", function(pTester)
+    {        
+        new SqlBuilder().where().or("PERSON.FIRSTNAME", ["", []]);
+    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY()],
+
+
+// or
+    ["or without parameter should error", function(pTester)
+    {
+        new SqlBuilder().where().or();
+    }, SqlBuilder.ERROR_NO_PARAMETER_PROVIDED()],
+
+    ["or with null as value should error", function(pTester)
+    {
+        new SqlBuilder().where().or("PERSON.FIRSTNAME", null);
+    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY()],
+
+    ["or with undefined as value should error", function(pTester)
+    {
+        new SqlBuilder().where().or("PERSON.FIRSTNAME", undefined);
+    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY()],
+
+    ["or with a jdito-var containing null should error", function(pTester)
+    {
+        vars.set("$global.TestingVarNull", null);
+        
+        new SqlBuilder().where().or("PERSON.FIRSTNAME", "$global.TestingVarNull");
+    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY_JDITO_VAR()],
+
+    ["or with an empty sql-builder as subquery should error", function(pTester)
+    {        
+        new SqlBuilder().where().or("PERSON.FIRSTNAME", new SqlBuilder());
+    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY()],
+
+    ["or with an empty prepared statement as subquery should error", function(pTester)
+    {        
+        new SqlBuilder().where().or("PERSON.FIRSTNAME", ["", []]);
+    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY()],
+]);
+
+var inStatementTests = new TestSuite([
+    ["simple and in", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where("PERSON.LASTNAME", ["Franz", "Fritz"]) // Note: you can use SqlBuilder.IN() or "# in ?" as 3rd parameter
+                            .or("PERSON.LASTNAME", ["Peter", "Mayer"]);
+                            
+        pTester.assert(" ( PERSON.LASTNAME in  (?, ?)  )  or  ( PERSON.LASTNAME in  (?, ?)  ) ", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(4, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["simple and not in", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .where("PERSON.LASTNAME", ["Franz", "Fritz"], "# not in ?"); // Note: you can use SqlBuilder.NOT_IN() instead of "# not in ?"
+                            
+        pTester.assert(" ( PERSON.LASTNAME not in  (?, ?)  ) ", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(2, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["in with subquery", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                        .where("PERSON.FIRSTNAME", new SqlBuilder()
+                                                        .select("PERSON.FIRSTNAME")
+                                                        .from("PERSON")
+                                                        .where("PERSON.LASTNAME", "Fritz")
+                                                , "# in ?"); // Note: you can use SqlBuilder.IN() instead of "# in ?"
+                            
+        pTester.assert("PERSON.FIRSTNAME in  ( select PERSON.FIRSTNAME from PERSON where PERSON.LASTNAME = ? ) ", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(1, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["in with prepared statement-array", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                        .where("PERSON.FIRSTNAME", ["select PERSON.FIRSTNAME from PERSON where PERSON.LASTNAME = ?", [["Fritz", SQLTYPES.VARCHAR]]]
+                                                , "# in ?"); // Note: you can use SqlBuilder.IN() instead of "# in ?"
+                            
+        pTester.assert("PERSON.FIRSTNAME in  ( select PERSON.FIRSTNAME from PERSON where PERSON.LASTNAME = ? ) ", actual._where._sqlStorage, "prepared sql");
+        pTester.assert(1, actual._where.preparedValues.length, "number of params");
+    }],
+
+    ["andIfSet should ignore empty array", function(pTester)
+    {
+        var actual = new SqlBuilder()
+                            .whereIfSet("PERSON.LASTNAME", []);
+                            
+        pTester.assert("", actual._where._sqlStorage, "prepared sql should be empty");
+        pTester.assert(0, actual._where.preparedValues.length, "number of params should be 0");
+    }],
+
+    ["and should error on an empty array", function(pTester)
+    {
+        new SqlBuilder()
+                .where("PERSON.LASTNAME", []);
+    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY()]
+]);
+
+var testConstantFunctions = new TestSuite([
+    ["SqlBuilder.IN()", function(pTester)
+    {
+        pTester.assert("# in ?", SqlBuilder.IN());
+    }],
+    
+    ["SqlBuilder.NOT_IN()", function(pTester)
+    {
+        pTester.assert("# not in ?", SqlBuilder.NOT_IN());
+    }],
+
+    ["SqlBuilder.EXISTS()", function(pTester)
+    {
+        pTester.assert("exists ?", SqlBuilder.EXISTS());
+    }]
+]);
+
+var selectTests = new TestSuite([
+    ["test if a sql-builder in a fields-array is translated to sql correctly", function(pTester)
+    {
+        var countSubQuery = newSelect("count(*)")
+                                .from("AB_ATTRIBUTEUSAGE")
+                                .where("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", "myType")
+                                .and("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID");
+    
+        var actual = SqlBuilder.begin()
+            .select(["AB_ATTRIBUTEID", "AB_ATTRIBUTEUSAGEID", countSubQuery])
+            .from("AB_ATTRIBUTE")
+                        
+        pTester.assert("select AB_ATTRIBUTEID, AB_ATTRIBUTEUSAGEID, (select count(*) from AB_ATTRIBUTEUSAGE where AB_ATTRIBUTEUSAGE.OBJECT_TYPE = ? and AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID)", actual._select._sqlStorage, "prepared select-sql");
+        pTester.assert(1, actual._select.preparedValues.length, "number of params");
+    }],
+])    
+
+var tester = new Tester("Test SqlBuilder");
+tester.test(validAndUsageTests);
+tester.test(validOrUsageTests);
+tester.test(combinedAndOrTests);
+tester.test(ifSetTests);
+tester.test(dbWrapperTests);
+tester.test(mandatoryErrorTests);
+tester.test(inStatementTests);
+tester.test(testConstantFunctions);
+tester.test(selectTests);
+
+logging.log("-------------------------");
+tester.printResults();
diff --git a/process/Sql_lib/process.js b/process/Sql_lib/process.js
index a11e8669d5a86f7bf786b62ea845045a8c0dfd7a..39843f71b1f7e7664fa8223421792b2f4a00bbde 100644
--- a/process/Sql_lib/process.js
+++ b/process/Sql_lib/process.js
@@ -9,833 +9,873 @@ import("system.SQLTYPES");
 import("system.text");
 import("Util_lib");
 
-/**
- * object for easier handling of conditions;
- * With this object you do not have to check if the string is empty or not;
- * you don't need to append a "1=1" condition or similar;
- * this objects gains most benefit if you have a lot of conditions that are added (or not) depending on tons of JDito-conditions
- * 
- * You can also use SqlCondition.begin(alias) for simpler object creation without new and without the need for an extra variable to save the object.
- * 
- * @class 
- * @param {String} [alias=the current alias] the database alias where the condition shall be executed later (important for column types of preparedStatements)
- * @example 
- * see others/guide/HowToSqlConditionLib.adoc
- */
-function SqlCondition(alias) {
-    // setting null is only needed to provide autocomplete for the ADITO-designer
-    this.preparedValues = null;
-    this._init(); // the properties are initalized in an extra function because init is nearly the same as resetting (clearing) the SqlConditions
-    this.alias = alias;
-    
-    // save, if the last condition was an OR. For better bracket-placement
-    this._lastWasOr = false;
+function newSelect(pFields, pAlias)
+{
+    return new SqlBuilder(pAlias).select(pFields);
 }
 
-/**
- * Alternative possibility to crate a new condition.
- * With this you don't need new SqlCondition and you can use the object directly after it's creation
- * --> cleaner code
- * 
- * It is very usefull for the orSqlCondition() and andSqlCondition() because now you can create a new condition inline.
- * You can also use it for simple selects without the need to save the conditionObject in an extra variable.
- * See Examples!
- * 
- * @param {String} [alias=the current alias] the database alias where the condition shall be executed later (important for column types of preparedStatements)
- * @return {SqlCondition} the new SqlCondition-object
- * 
- * @example 
- * vars mySelect = SqlCondition.begin(alias)
- *                             .and("MYID = '123'")
- *                             .and(SqlCondition.begin()
- *                                              .or("NAME = 'Max'")
- *                                              .or("NAME = 'Bob'")
- *                              )
- *                             .buildSql("select * from MYTABLE");
- *                             
- * // Or use it for simple selects:
- * var sum = db.cell(SqlCondition.begin()
- *                               .andPrepared("STOCK.PRODUCT_ID", pid)
- *                               .buildSql("select sum(QUANTITY * IN_OUT) from STOCK"));
- */
-SqlCondition.begin = function(alias) {
-    return new SqlCondition(alias);
+function newWhere(pFieldOrCond, pValue, pCond, pFieldType, pAlias)
+{
+    return new SqlBuilder(pAlias).where(pFieldOrCond, pValue, pCond, pFieldType);
 }
 
-/**
- * checks if conditions have been added to the object
- * @return {Boolean} true if conditions have been added, false when not
- */
-SqlCondition.prototype.isSet = function() {
-    if (this._sqlStorage)
-        return true;
-    return false;
+function newWhereIfSet(pFieldOrCond, pValue, pCond, pFieldType, pAlias)
+{
+    return new SqlBuilder(pAlias).whereIfSet(pFieldOrCond, pValue, pCond, pFieldType);
 }
-
-
 /**
- * append with SQL-and; no paranthesize of existing conditions is done
- * @param {String} cond the condition string which shall be appended
- * @return {SqlCondition} current SqlCondition-object
+ * Object for building sqls. The main purpose of this is to make it easy to use prepared statements.
+ * You should ALWAYS use prepared statemnts for Security and maybe also for performance reasons.
+ * This can also be useful to build complex sqls where parts should be added
+ * dynamically while keeping the code clean.
+ * 
+ * @param {String} [pAlias=the current alias] the database alias where the condition shall be executed later (important for column types of preparedStatements)
+ * @class
  */
-SqlCondition.prototype.and = function(cond) {
-    if (!cond)
-        return this;
-    if (this.isSet())
-        this._sqlStorage += " and ";
-    this._sqlStorage += cond;
-    return this;
+function SqlBuilder (pAlias)
+{
+    if(!(this instanceof SqlBuilder)) 
+        throw SqlBuilder.ERROR_INSTANCIATE_WITH_NEW();
+    this._select = null;
+    this._from = null;
+    this._tableName = null; //for update/delete
+    this._joins = [];
+    this._groupBy = null;
+    this._having = null;
+    this._orderBy = null;
+    this._unions = [];
+    this.alias = pAlias;
+    
+    this._where = {
+        preparedValues: [],
+        _sqlStorage: "",
+        
+        // save, if the last condition was an OR. For better bracket-placement
+        _lastWasOr: false,
+        _previouslyOnlyOr: false,
+        _whereWasCalled: false
+    }
 }
 
 /**
- * append with SQL-or; Also paranthesize the existing conditions
- * @param {String} cond the condition string which shall be appended
- * @return {SqlCondition} current SqlCondition-object
+ * Deep copies the SqlBuilder object and returns a new one.
  */
-SqlCondition.prototype.or = function(cond) {
-    if (!cond)
-        return this;
+SqlBuilder.prototype.copy = function()
+{
+    var newBuilder = _deepCopyByJson(this, new SqlBuilder());
+    return newBuilder;
     
-    if (this.isSet() && !this._lastWasOr) {
-        this._sqlStorage = "(" + this._sqlStorage + ") or (" + cond + ")";
-        this._lastWasOr = true;
+    // NOTE: this works only with simple data types. 
+    // Here we only use strings, arrays, booleans and null, so this should work
+    function _deepCopyByJson(pObject, pNewObject)
+    {
+        // deep copy by using json
+        var deepCopied = JSON.parse(JSON.stringify(pObject));
         
-    } else if (this.isSet() && this._lastWasOr) {
-        this._sqlStorage = this._sqlStorage + " or (" + cond + ")";
-        this._lastWasOr = true;
+        // set the props of the new object to the deepCopied ones.
+        // without this all functions would be lost
+        for (prop in deepCopied)
+        {
+            pNewObject[prop] = deepCopied[prop]
+        }
         
-    } else {
-        this._sqlStorage = cond;
+        return pNewObject;
     }
-    return this;
 }
 
-/**
- * append a prepared-array to this sql condition with SQL-and
- * @param {Array} preparedObj a prepared condition-array
- * @return {SqlCondition} current SqlCondition-object
- */
-SqlCondition.prototype.andAttachPrepared = function(preparedObj) {
-    if (preparedObj)
-    {
-        this.preparedValues = this.preparedValues.concat(preparedObj[1]);
-        return this.and(preparedObj[0]);
-    }
-    
-    return this;
+SqlBuilder.ERROR_INSTANCIATE_WITH_NEW = function() 
+{
+    return new Error(translate.text("SqlBuilder must be instanciated with 'new'"));
 }
 
-/**
- * append a prepared-array to this sql condition with SQL-or
- * @param {Array} preparedObj a prepared condition-array
- * @return {SqlCondition} current SqlCondition-object
- */
-SqlCondition.prototype.orAttachPrepared = function(preparedObj) {
-    if (preparedObj)
-    {
-        this.preparedValues = this.preparedValues.concat(preparedObj[1]);
-        return this.or(preparedObj[0]);
-    }
-    
-    return this;
+SqlBuilder.ERROR_INVALID_CONDITION_VALUE_TYPE = function() 
+{
+    return new Error(translate.text("SqlBuilder.and/or: invalid value-type for pCondition"));
 }
 
-/**
- * append another condition with SQL-and
- * 
- * @param {SqlCondition} cond the condition which shall be appended
- * @param {String} [alternativeCond=""] condition if the given SqlCondition has none
- * @return {SqlCondition} current SqlCondition-object
- */
-SqlCondition.prototype.andSqlCondition = function(cond, alternativeCond) {
-    if (!cond)
-        return this
-        
-    var otherCondition = cond.toString(alternativeCond);
-    if (otherCondition.trim() != "")
-    {
-        this.and(" ( " + cond.toString(alternativeCond) + " ) ");
-        if (cond.preparedValues) {
-            this.preparedValues = this.preparedValues.concat(cond.preparedValues);
-        }
-    }
-    return this;
+SqlBuilder.ERROR_NO_CONDITION = function() 
+{
+    return new Error(translate.text("SqlBuilder.and/or: if you use a subQuery (e.g. SqlBuilder) you have to provide pCondition (e.g. \"exists ?\")"));
 }
 
-/**
- * append another condition with SQL-or; Also paranthesize the existing conditions
- * 
- * @param {SqlCondition} cond the condition which shall be appended
- * @param {String} [alternativeCond=""] condition if the given SqlCondition has none
- * @return {SqlCondition} current SqlCondition-object
- */
-SqlCondition.prototype.orSqlCondition = function(cond, alternativeCond) {
-    var otherCondition = cond.toString(alternativeCond);
-    if (otherCondition.trim() != "")
-    {
-        this.or(" ( " + cond.toString(alternativeCond) + " ) ");
-        if (cond.preparedValues) {
-            this.preparedValues = this.preparedValues.concat(cond.preparedValues);
-        }
-    }
-    return this;
+SqlBuilder.ERROR_INVALID_SUBQUERY_TYPE = function() 
+{
+    return new Error(translate.text("SqlBuilder.and/or: invalid value-type for pFieldOrCond. It can be a fully qualified SqlBuilder (e.g. select, from, ... have to be set) or an jdito-prepared-statement array"));
 }
 
-/**
- * append an condition that uses a subQuery with SQL-and
- * 
- * @param {SqlBuilder} subQuery the SqlBuilder object that will be used as a subquery
- * @param {String} [cond="exists"] condition that is used (e. g. exists, not exists, COLUMN = any, COLUMN in, ...)
- * @return {SqlCondition} current SqlCondition-object
- */
-SqlCondition.prototype.andSqlBuilder = function(subQuery, cond) {
-    if (!cond)
-        cond = "exists";
-    
-    var preparedObj = subQuery.build();
-    preparedObj[0] = cond + " ( " + preparedObj[0] + " ) ";
-    this.andAttachPrepared(preparedObj);
-    
-    return this;
+SqlBuilder.ERROR_VALUE_IS_MANDATORY = function() 
+{
+    return new Error(translate.text("SqlBuilder.and/or: pValue (or pFieldOrCond if only one param) is not allowed to be null, undefined or []. (use *IfSet functions if you need optional conditions which are just ignored if value is null or undefined)"));
 }
 
-/**
- * append an condition that uses a subQuery with SQL-or
- * 
- * @param {SqlBuilder} subQuery the SqlBuilder object that will be used as a subquery
- * @param {String} [cond="exists"] condition that is used (e. g. exists, not exists, COLUMN = any, COLUMN in, ...)
- * @return {SqlCondition} current SqlCondition-object
- */
-SqlCondition.prototype.orSqlBuilder = function(subQuery, cond) {
-    if (!cond)
-        cond = "exists";
-    
-    var preparedObj = subQuery.build();
-    preparedObj[0] = cond + " ( " + preparedObj[0] + " ) ";
-    this.orAttachPrepared(preparedObj);
-    
-    return this;
+SqlBuilder.ERROR_VALUE_IS_MANDATORY_JDITO_VAR = function() 
+{
+    return new Error(translate.text("SqlBuilder.and/or: pValue has to be a jdito variable which returns something different than null. (use *IfSet functions if you need optional conditions which are just ignored if value is null or undefined)"));
 }
 
-/**
- * same as the "and"-function but with preparedStatement functionality
- * @param {String | String[]} field the database field as "tablename.columnname"; e.g. "ORGANISATION.NAME" or as array with column-alias: ["ORGANISATION", "NAME", "myorgAlias"]
- * @param {String} value the value that shall be set into the prepared statement
- * @param {String} [cond="# = ?"] the strucutre of the SQL condition as preparedString, you can use a number sign "#" as placeholder for you fieldname; 
- *                 e.g. "# > ?"; escaping the number sign is possible with a backslash "\"
- * @param {Numeric | Boolean} [fieldType] SQL-column-type; if the fieldType is not given it's loaded automatically;
- *                              The loaded type is cached if no type is given. So it is also safe to use this in a loop.
- *                              e.g.
- *                              for (...) {
- *                                  cond.andPrepare("SALESPROJECT_CLASSIFICATION.TYPE", entry, "# <> ?")
- *                              }
- * @return {SqlCondition} current SqlCondition-object
- */
-SqlCondition.prototype.andPrepare = function(field, value, cond, fieldType) {
-    cond = this._prepare(field, value, cond, fieldType);
-    return this.and(cond);
+SqlBuilder.ERROR_UNSUPPORTED_PARAMETER_COMBINATION = function() 
+{
+    return new Error(translate.text("SqlBuilder.and/or: unsupportet parameter combination"));
 }
 
-/**
- * same as the "or"-function but with preparedStatement functionality
- * @param {String | String[]} field the database field as "tablename.columnname"; e.g. "ORGANISATION.NAME" or as array with column-alias: ["ORGANISATION", "NAME", "myorgAlias"]
- * @param {String} value the value that shall be set into the prepared statement
- * @param {String} [cond="# = ?"] the strucutre of the SQL condition as preparedString, you can use a number sign "#" as placeholder for you fieldname; 
- *                 e.g. "# > ?"; escaping the number sign is possible with a backslash "\"
- * @param {Numeric | Boolean} [fieldType] SQL-column-type; if the fieldType is not given it's loaded automatically;
- *                              The loaded type is cached if no type is given. So it is also safe to use this in a loop.
- *                              e.g.
- *                              for (...) {
- *                                  cond.andPrepare("SALESPROJECT_CLASSIFICATION.TYPE", entry, "# <> ?")
- *                              }
- * @return {SqlCondition} current SqlCondition-object
- */
-SqlCondition.prototype.orPrepare = function(field, value, cond, fieldType) {
-    cond = this._prepare(field, value, cond, fieldType);
-    return this.or(cond);
+SqlBuilder.ERROR_NO_TABLE = function()
+{
+    return new Error(translate.text("SqlBuilder.deleteDat/updateData: You have to specify a tablename"));
+}
+
+SqlBuilder.ERROR_NO_PARAMETER_PROVIDED = function()
+{
+    return new Error(translate.text("SqlBuilder.and/or: You have to specify at least one parameter"));
+}
+
+SqlBuilder.ERROR_WHERE_NOT_FIRST = function()
+{
+    return new Error(translate.text("SqlBuilder: .where has to be called before following and/or."));
+}
+
+SqlBuilder.ERROR_ONLY_ONE_WHERE = function()
+{
+    return new Error(translate.text("SqlBuilder: .where has to be called only one time. Use and/or for further conditions."));
+}
+
+SqlBuilder.ERROR_INCOMPLETE_SELECT = function ()
+{
+    return new Error(translate.text("SqlBuilder: select and from were expected, but not provided."));
 }
 
+SqlBuilder.ERROR_CONDITION_IS_MANDATORY = function ()
+{
+    return new Error(translate.text("SqlBuilder.and/or: You have to provide a subquery as SqlBuilder, prepared-array or string"));
+}
 /**
- * same as the "andPrepare"-function but only applied if the passed "value" is truely
- * @param {String | String[]} field the database field as "tablename.columnname"; e.g. "ORGANISATION.NAME" or as array with column-alias: ["ORGANISATION", "NAME", "myorgAlias"]
- * @param {String} value the value that shall be set into the prepared statement
- * @param {String} [cond="# = ?"] the strucutre of the SQL condition as preparedString, you can use a number sign "#" as placeholder for you fieldname; 
- *                 e.g. "# > ?"; escaping the number sign is possible with a backslash "\"
- * @param {Numeric | Boolean} [fieldType] SQL-column-type; if the fieldType is not given it's loaded automatically;
- *                              The loaded type is cached if no type is given. So it is also safe to use this in a loop.
- *                              e.g.
- *                              for (...) {
- *                                  cond.andPrepare("SALESPROJECT_CLASSIFICATION.TYPE", entry, "# <> ?")
- *                              }
- * @return {SqlCondition} current SqlCondition-object
+ * Alternative way of creating a new SqlBuilder object that allows to use
+ * methods on it directly without having to put brackets around it
+ * 
+ * @param {String} [pAlias=the current alias] the database alias where the condition shall be executed later (important for column types of preparedStatements)
+ * @return {SqlBuilder} a new SqlBuilder object
+ * 
+ * @example 
+ * var query = SqlBuilder.begin()
+ *   .select("ORGANISATION.NAME, FIRSTNAME, LASTNAME")
+ *   .from("PERSON")
+ *   .join("CONTACT", "CONTACT.PERSON_ID = PERSON.PERSONID")
+ *   .leftJoin("ORGANISATION", SqlCondition.begin()
+ *       .and("CONTACT.ORGANISATION_ID = ORGANISATION.ORGANISATIONID")
+ *       .andPrepare("ORGANISATION.NAME", "S%", "# like ?")
+ *       .build("1=2"))
+ *   .where(SqlCondition.begin()
+ *       .andPrepare("CONTACT.STATUS", $KeywordRegistry.contactStatus$active())
+ *       .build("1=2"));
+ * 
+ * if (getCountry) //changing and adding parts
+ * {
+ *   query.select("ORGANISATION.NAME, FIRSTNAME, LASTNAME, COUNTRY");
+ *   query.leftJoin("ADDRESS", "CONTACT.ADDRESS_ID = ADDRESS.ADDRESSID");
+ * }
+ *   
+ * var data = db.table(query.build());
  */
-SqlCondition.prototype.andPrepareIfSet = function(field, value, cond, fieldType) {
-    if (value)
-        return this.andPrepare(field, value, cond, fieldType);
-    return this;
+SqlBuilder.begin = function(pAlias)
+{
+    return new SqlBuilder(pAlias);
 }
 
 /**
- * same as the "orPrepare"-function but only applied if the passed "value" is truely
- * @param {String | String[]} field the database field as "tablename.columnname"; e.g. "ORGANISATION.NAME" or as array with column-alias: ["ORGANISATION", "NAME", "myorgAlias"]
- * @param {String} value the value that shall be set into the prepared statement
- * @param {String} [cond="# = ?"] the strucutre of the SQL condition as preparedString, you can use a number sign "#" as placeholder for you fieldname; 
- *                 e.g. "# > ?"; escaping the number sign is possible with a backslash "\"
- * @param {Numeric | Boolean} [fieldType] SQL-column-type; if the fieldType is not given it's loaded automatically;
- *                              The loaded type is cached if no type is given. So it is also safe to use this in a loop.
- *                              e.g.
- *                              for (...) {
- *                                  cond.andPrepare("SALESPROJECT_CLASSIFICATION.TYPE", entry, "# <> ?")
- *                              }
- * @return {SqlCondition} current SqlCondition-object
+ * Builds the sql and uses db.translateStatement to make a string out of it.
+ * @return {String} the sql as string
  */
-SqlCondition.prototype.orPrepareIfSet = function(field, value, cond, fieldType) {
-    if (value)
-        return this.orPrepare(field, value, cond, fieldType);
-    return this;
+SqlBuilder.prototype.toString = function(pDefaultConditionIfNone)
+{
+    var built = this.build(pDefaultConditionIfNone)
+    
+    if (built[0] !== "")
+    {
+        if (!this.isFullSelect() && (this.hasCondition() || pDefaultConditionIfNone))
+            return SqlUtils.translateConditionWithQuotes(built, this.alias);
+        else
+            return SqlUtils.translateStatementWithQuotes(built, this.alias);
+    }
+    
+    return "";
 }
 
 /**
- * same as the "andPrepare"-function but with validation of adito-variables functionality
- * @param {String | String[]} field the database field as "tablename.columnname"; e.g. "ORGANISATION.NAME" or as array with column-alias: ["ORGANISATION", "NAME", "myorgAlias"]
- * @param {String} variable the adito-variable that shall be set into the prepared statement
- * @param {String} [cond = "# = ?" ] the strucutre of the SQL condition as preparedString, you can use a number sign "#" as placeholder for you fieldname; 
- *                 e.g. "# > ?"; escaping the number sign is possible with a backslash "\"
- * @param {Numeric | Boolean} [fieldType] SQL-column-type; if the fieldType is not given it's loaded automatically;
- *                              The loaded type is cached if no type is given. So it is also safe to use this in a loop.
- *                              e.g.
- *                              for (...) {
- *                                  cond.andPrepare("SALESPROJECT_CLASSIFICATION.TYPE", entry, "# <> ?")
- *                              }
- * @return {SqlCondition} current SqlCondition-object
+ * Sets the select clause of the sql.
+ * @param {String|String[]} pFields
+ * @return {SqlBuilder} current SqlBuilder object
  */
-SqlCondition.prototype.andPrepareVars = function(field, variable, cond, fieldType) {
-    variable = this._checkVars(variable)
-    if (variable) {
-        return this.andPrepare(field, variable, cond, fieldType);
-    }
+SqlBuilder.prototype.select = function(pFields)
+{
+    this._select = SqlBuilder._getStatement(pFields, "select", undefined, true);
     return this;
 }
 
 /**
- * same as the "orPrepare"-function but with validation of adito-variables functionality
- * @param {String | String[]} field the database field as "tablename.columnname"; e.g. "ORGANISATION.NAME" or as array with column-alias: ["ORGANISATION", "NAME", "myorgAlias"]
- * @param {String} variable the adito-variable that shall be set into the prepared statement
- * @param {String} [cond="# = ?"] the strucutre of the SQL condition as preparedString, you can use a number sign "#" as placeholder for you fieldname; 
- *                 e.g. "# > ?"; escaping the number sign is possible with a backslash "\"
- * @param {Numeric | Boolean} [fieldType] SQL-column-type; if the fieldType is not given it's loaded automatically;
- *                              The loaded type is cached if no type is given. So it is also safe to use this in a loop.
- *                              e.g.
- *                              for (...) {
- *                                  cond.andPrepare("SALESPROJECT_CLASSIFICATION.TYPE", entry, "# <> ?")
- *                              }
- * @return {SqlCondition} current SqlCondition-object
+ * Sets the select clause of the sql with distinct.
+ * @param {String|String[]} pFields
+ * @return {SqlBuilder} current SqlBuilder object
  */
-SqlCondition.prototype.orPrepareVars = function(field, variable, cond, fieldType) {
-    variable = this._checkVars(variable)
-    if (variable) {
-        return this.orPrepare(field, variable, cond, fieldType);
-    }
+SqlBuilder.prototype.selectDistinct = function(pFields)
+{
+    this._select = SqlBuilder._getStatement(pFields, "select distinct", undefined, true);
     return this;
 }
 
 /**
- * creates a IN-statement out of a field and an array of values.
- * Be carefull with a big number of values. This may have a bad performance.
- * 
- * @param {String | String[]} field the database field as "tablename.columnname"; e.g. "ORGANISATION.NAME" or as array with column-alias: ["ORGANISATION", "NAME", "myorgAlias"]
- * @param {String[]} values the value that shall be set into the prepared statement
- * @param {Numeric | Boolean} [fieldType] SQL-column-type; if the fieldType is not given it's loaded automatically;
- *                              The loaded type is cached if no type is given. So it is also safe to use this in a loop.
- *                              e.g.
- *                              for (...) {
- *                                  cond.andPrepare("SALESPROJECT_CLASSIFICATION.TYPE", entry, "# <> ?")
- *                              }
- * @param {Boolean} [not = undefined] if true, add not before in
- * @return {SqlCondition} current SqlCondition-object
+ * Sets the from clause of the sql.
+ * @param {String|SqlBuilder} pTable
+ * @param {String} [pTableAlias] table alias
+ * @return {SqlBuilder} current SqlBuilder object
  */
-SqlCondition.prototype.andIn = function(field, values, fieldType, not) {
-    return this.andAttachPrepared(this._in(field, values, fieldType, not));
+SqlBuilder.prototype.from = function(pTable, pTableAlias)
+{
+    this._from = SqlBuilder._getStatement(pTable, "from", pTableAlias);
+    if (typeof(pTable) === "string")
+        this._tableName = pTable;
+    return this;
 }
 
 /**
- * creates a IN-statement out of a field and an array of values.
- * Be carefull with a big number of values. This may have a bad performance.
- * 
- * @param {String | String[]} field the database field as "tablename.columnname"; e.g. "ORGANISATION.NAME" or as array with column-alias: ["ORGANISATION", "NAME", "myorgAlias"]
- * @param {String[]} values the value that shall be set into the prepared statement
- * @param {Numeric | Boolean} [fieldType] SQL-column-type; if the fieldType is not given it's loaded automatically;
- *                              The loaded type is cached if no type is given. So it is also safe to use this in a loop.
- *                              e.g.
- *                              for (...) {
- *                                  cond.andPrepare("SALESPROJECT_CLASSIFICATION.TYPE", entry, "# <> ?")
- *                              }
- * @param {Boolean} [not = undefined] if true, add not before in
- * @return {SqlCondition} current SqlCondition-object
+ * Adds a join clause to the sql.
+ * @param {String|SqlBuilder} pTable
+ * @param {String|String[]|SqlBuilder} pCondition The where condition. This can be
+ *          a string (without the where keyword), a SqlBuilder or an array (for prepared queries).
+ * @param {String} [pTableAlias] table alias
+ * @param {String} [pPrefix] string before the join, for example "left", "right"
+ * @return {SqlBuilder} current SqlBuilder object
  */
-SqlCondition.prototype.orIn = function(field, values, fieldType, not) {
-    return this.orAttachPrepared(this._in(field, values, fieldType, not));
+SqlBuilder.prototype.join = function(pTable, pCondition, pTableAlias, pPrefix)
+{
+    var prefix = "join";
+    if (pPrefix)
+        prefix = pPrefix + " " + prefix;
+    
+    var postfix = "on";
+    if (pTableAlias)
+        postfix = pTableAlias + " " + postfix;
+    
+    var joinPart = SqlBuilder._getStatement(pTable, prefix, postfix);
+    var conditionPart = SqlBuilder._getStatement(pCondition);
+    
+    joinPart._sqlStorage += " " + conditionPart._sqlStorage;
+    joinPart.preparedValues = joinPart.preparedValues.concat(conditionPart.preparedValues);
+    
+    this._joins.push(joinPart)
+    return this;
 }
 
 /**
- * creates a IN-statement out of a field and an array of values.
- * Be carefull with a big number of values. This may have a bad performance.
- * 
- * @param {String | String[]} field the database field as "tablename.columnname"; e.g. "ORGANISATION.NAME" or as array with column-alias: ["ORGANISATION", "NAME", "myorgAlias"]
- * @param {String[]} values the value that shall be set into the prepared statement
- * @param {Numeric | Boolean} [fieldType] SQL-column-type; if the fieldType is not given it's loaded automatically;
- *                              The loaded type is cached if no type is given. So it is also safe to use this in a loop.
- *                              e.g.
- *                              for (...) {
- *                                  cond.andPrepare("SALESPROJECT_CLASSIFICATION.TYPE", entry, "# <> ?")
- *                              }
- * @param {Boolean} [not = undefined] if true, add not before in
- * @return {SqlCondition} current SqlCondition-object
+ * Adds a left join clause to the sql.
+ * @param {String|SqlBuilder} pTable
+ * @param {String|String[]|SqlBuilder} pCondition The where condition. This can be
+ *          a string (without the where keyword), a SqlBuilder or an array (for prepared queries).
+ * @param {String} [pTableAlias] table alias
+ * @return {SqlBuilder} current SqlBuilder object
  */
-SqlCondition.prototype._in = function(field, values, fieldType, not) {
-    if (values && values.length > 0)
-    {
-        if (fieldType == undefined)
-            fieldType = SqlUtils.getSingleColumnType(field, undefined, this.alias);
-        
-        preparedStatement = SqlUtils.getSqlInStatement(field, values, undefined, true, fieldType);
-        if (not)
-            preparedStatement[0] = " not " + preparedStatement[0];
-        return preparedStatement;
-    }
-    
-    return null;
+SqlBuilder.prototype.leftJoin = function(pTable, pCondition, pTableAlias)
+{
+    return this.join(pTable, pCondition, pTableAlias, "left");
 }
 
 /**
- * ready to use string; does not contain a where keyword at the beginning
- * @param {String} [alternativeCond=""] condition that is returned when nothing has been appended.
- * @return {String} concatenated SQL-condition; empty string if nothing has been appended or - if passed - the alternativeCond
+ * Adds a right join clause to the sql.
+ * @param {String|SqlBuilder} pTable
+ * @param {String|String[]|SqlBuilder} pCondition The where condition. This can be
+ *          a string (without the where keyword), a SqlBuilder or an array (for prepared queries).
+ * @param {String} [pTableAlias] table alias
+ * @return {SqlBuilder} current SqlBuilder object
  */
-SqlCondition.prototype.toString = function(alternativeCond) {
-    if (!this.isSet() && alternativeCond)
-        return alternativeCond
-    else
-        return this._sqlStorage;
+SqlBuilder.prototype.rightJoin = function(pTable, pCondition, pTableAlias)
+{
+    return this.join(pTable, pCondition, pTableAlias, "right");
 }
 
 /**
- * ready to use string; does contain a where keyword at the beginning
- * @param {String} [alternativeCond=""] condition that is returned when nothing has been appended.
- * @return {SqlCondition} concatenated SQL-condition; empty string if nothing has been appended or - if passed - the alternativeCond
+ * Sets the where clause of the sql.
+ * 
+ * @param {String|String[]|SqlCondition} pCondition The where condition. This can be
+ *          a string (without the where keyword), a SqlCondition or an array (for prepared queries).
+ *          
+ * @return {SqlBuilder} current SqlBuilder object
  */
-SqlCondition.prototype.toWhereString = function(alternativeCond) {
-    var cond = this.toString(alternativeCond);
-    if (cond)
-        return " where " + cond;
-    else 
-        return cond;
+SqlBuilder.prototype.where = function(pFieldOrCond, pValue, pCond, pFieldType)
+{
+    return this._setWhere(pFieldOrCond, pValue, pCond, pFieldType, this.or);
 }
 
-/**
- * ready to use prepared condition; does not contain a where keyword at the beginning
- * @param {String} [alternativeCond=""] Condition that is returned when nothing has been appended.
- * @return {Array[][][]} Prepared condition with [condition, [[field1, type1], [field2, type2]]]
- */
-SqlCondition.prototype.build = function(alternativeCond) {
-    return [this.toString(alternativeCond), this.preparedValues];
+SqlBuilder.prototype.whereIfSet = function(pFieldOrCond, pValue, pCond, pFieldType)
+{
+    return this._setWhere(pFieldOrCond, pValue, pCond, pFieldType, this.orIfSet);
 }
 
 /**
- * ready to use prepared select
- * @param {String} pBeforeCondition Part of the sql before the condition without where (e.g. "select FIRSTNAME from PERSON")
- * @param {String} [pAlternativeCond=""] Condition that is returned when nothing has been appended.
- * @param {String} [pAfterCondition=""] Part of the sql after the condition (e.g. "order by FIRSTNAME").
- * @param {Boolean} [pWithWere=true] true if where should be added to the bginning
- * @return {Array[][][]} Prepared condition with [condition, [[field1, type1], [field2, type2]]]
+ * helper function for .where and .whereIfSet because they do almost the same
+ *
+ * @private
  */
-SqlCondition.prototype.buildSql = function(pBeforeCondition, pAlternativeCond, pAfterCondition, pWithWere) {
-    if (pAfterCondition == undefined)
-        pAfterCondition = "";
+SqlBuilder.prototype._setWhere = function (pFieldOrCond, pValue, pCond, pFieldType, pAddCondFn)
+{
+    // allow where-call without parameter to just enable where mode
+    if (pFieldOrCond === undefined && pValue === undefined && pCond === undefined && pFieldType === undefined)
+    {
+        this._where._whereWasCalled = true;
+        return this;
+    }
     
-    if (pWithWere == undefined) 
-        pWithWere = true;
+    // where has to be called before all other and / or
+    if (this.hasCondition())
+        throw SqlBuilder.ERROR_WHERE_NOT_FIRST();
     
-    return [pBeforeCondition  + " " + 
-            (pWithWere ? this.toWhereString(pAlternativeCond) : this.toString(pAlternativeCond)) +
-            " " + pAfterCondition, this.preparedValues];
+    // only one where call is allowed
+    if (this._where._whereWasCalled)
+        throw SqlBuilder.ERROR_ONLY_ONE_WHERE();
+    
+    this._where._whereWasCalled = true;
+    return pAddCondFn.call(this, pFieldOrCond, pValue, pCond, pFieldType);
 }
 
 /**
- * translates SqlCondition to plain SQL. Use this if prepared statements are not supported.
- * It resolves all prepared values.
- * @param {String} pAlternativeCond used if the SqlCondition does not contain any condition.
- * @return {String} plain SQL condition
+ *
+ * @private
  */
-SqlCondition.prototype.translate = function(pAlternativeCond) 
+SqlBuilder.prototype._whereCondition = function(pCondition, pMandatory, pAddPreparedConditionCallback, pBrackets)
 {
-    return SqlUtils.translateConditionWithQuotes(this.build(pAlternativeCond, this.alias));
+    if (pCondition === undefined)
+        return this;
+    
+    if (pMandatory === undefined)
+        pMandatory = true;
+    
+    var sql = pCondition;
+    var typeofSql = typeof sql;
+
+    // the field is a simple string -> just add the string, no prepared statement
+    if (typeofSql == "string")
+    {
+        pAddPreparedConditionCallback([sql, []]);
+        return this;
+    }
+
+    // the field is an array -> it is a prepared condition
+    if (Array.isArray(sql))
+    {
+        if (sql[0])
+        {
+            this._where.preparedValues = this._where.preparedValues.concat(sql[1]);
+
+            // add only brackets if needed
+            if (pBrackets)
+                sql[0] = " ( " + sql[0] + " ) ";
+
+            pAddPreparedConditionCallback([sql[0], []], pBrackets)
+            return this;
+        }
+        else if (pMandatory)
+            throw SqlBuilder.ERROR_CONDITION_IS_MANDATORY();
+        
+        return this;
+    }
+
+    // the field is a SqlBuilder -> it is a SqlBuilder which contains a condition -> the condition of the SqlBuilder is added.
+    if (sql instanceof SqlBuilder)
+    {
+        // add only brackets if needed
+        var sqlString = sql._where._sqlStorage;
+        
+        
+        var condString = sqlString;
+        if (condString.trim() != "")
+        {
+            if (pBrackets)
+                condString = " ( " + condString + " ) ";
+            
+            pAddPreparedConditionCallback([condString, sql._where.preparedValues], pBrackets);
+            return this;
+        }
+        else if (pMandatory)
+            throw SqlBuilder.ERROR_CONDITION_IS_MANDATORY();
+        
+        return this;
+    }
+
+    throw SqlBuilder.ERROR_INVALID_CONDITION_VALUE_TYPE();
 }
 
 /**
- * Check if (adito-)variable exists and vars.getString is not empty
- * @param {String} variable the variable name (e.g. "$field.CONTACT_ID")
- * @return {String | Boolean} The value of the field as string OR false if it doesn't exist.
- * 
- * @ignore
+ * @private
  */
-SqlCondition.prototype._checkVars = function(variable) {
-    if (vars.exists(variable)) {
-        var value = vars.getString(variable);
-        if (value) {
-            return value;
-        }
+SqlBuilder.prototype._whereSubquery = function(pSubquery, pMandatory, pCondition, pAddPreparedConditionCallback)
+{
+    if (pSubquery === undefined)
+        return this;
+    
+    if (pMandatory === undefined)
+        pMandatory = true;
+    
+    var sql = pSubquery;
+
+    // the field is an array -> it is a prepared statement which already SHOULD contain exists or another condition
+    // Both can be handled by _prepare
+    if (Array.isArray(sql))
+    {        
+        if (sql[0])
+            pAddPreparedConditionCallback(this._prepare(undefined, sql, pCondition));
+        else if (pMandatory)
+            throw SqlBuilder.ERROR_VALUE_IS_MANDATORY();
+        
+        return this;
     }
-    return false;
+
+    // the field is a SqlBuilder -> it is a SqlBuilder which contains a condition -> the condition of the SqlBuilder is added.
+    if (sql instanceof SqlBuilder)
+    {
+         var subQuery = pSubquery;
+
+        // Without condition this function cannot be used with SqlBuilder object as it cannot contain a condition
+        if (!pCondition)
+            throw SqlBuilder.ERROR_NO_CONDITION();
+        
+        if (subQuery.isFullSelect())
+        {
+            var preparedObj = subQuery.build();
+            pAddPreparedConditionCallback(this._prepare(undefined, preparedObj, pCondition));
+        } 
+        else if (pMandatory)
+            throw SqlBuilder.ERROR_VALUE_IS_MANDATORY();
+        
+        return this;
+    }
+    
+    throw SqlBuilder.ERROR_INVALID_SUBQUERY_TYPE();
 }
 
 /**
- * hidden function for composing preparedStatements
- * @param {String | String[]} field the database field as "tablename.columnname"; e.g. "ORGANISATION.NAME" or as array with column-alias: ["ORGANISATION", "NAME", "myorgAlias"]
- * @param {String} value the value that shall be set into the prepared statement
- * @param {String} cond the strucutre of the SQL condition as preparedString, you can use a number sign "#" as placeholder for you fieldname; 
+ * @param {String | String[]} pFieldOrCond the database field as "tablename.columnname"; e.g. "ORGANISATION.NAME" or as array with column-alias: ["ORGANISATION", "NAME", "myorgAlias"]
+ * @param {String} pValue the value that shall be set into the prepared statement
+ * @param {Boolean} [pMandatory=true] if true: throw error if pValue is null, undefined, "" or an empty jdito-variable
+ * @param {String} [pCond="# = ?"] the strucutre of the SQL condition as preparedString, you can use a number sign "#" as placeholder for you fieldname; 
  *                 e.g. "# > ?"; escaping the number sign is possible with a backslash "\"
- *                 Default is "# = ?" 
- * @param {Numeric | Boolean} [fieldType] SQL-column-type; if the fieldType is not given it's loaded automatically;
+ * @param {Numeric | Boolean} [pFieldType] SQL-column-type; if the fieldType is not given it's loaded automatically;
  *                              The loaded type is cached if no type is given. So it is also safe to use this in a loop.
  *                              e.g.
  *                              for (...) {
  *                                  cond.andPrepare("SALESPROJECT_CLASSIFICATION.TYPE", entry, "# <> ?")
  *                              }
- * @return {String} the replaced SQL-condition string (replace # by the fieldname)
- * @ignore
+ * @return {SqlBuilder} current SqlBuilder object
+ * @private
  */
-SqlCondition.prototype._prepare = function(field, value, cond, fieldType) {
-    if (value == undefined)
-    {
-        throw new Error(translate.withArguments("${SQL_LIB_UNDEFINED_VALUE} field: %0", [field]));
-    }
+SqlBuilder.prototype._addWhere = function(pFieldOrCond, pValue, pMandatory, pCond, pFieldType, pAddPreparedConditionCallback)
+{
+    if (!this._where._whereWasCalled)
+        throw SqlBuilder.ERROR_WHERE_NOT_FIRST();
     
-    if (cond == undefined) {
-        cond = "# = ?"
-    }
+    if (!pMandatory && pFieldOrCond === undefined && pValue === undefined && pCond === undefined && pFieldType === undefined)
+        return this;
 
-    var alias;
-    
-    if (typeof field === 'string')
+    if (pFieldOrCond === undefined && pValue === undefined && pCond === undefined && pFieldType === undefined)
+        throw SqlBuilder.ERROR_NO_PARAMETER_PROVIDED();
+ 
+    // Special case: if only pFieldOrCond is set and we can identify it as a valid field-string (e.g. "Table.Field") we assume that it is not just a condition string.
+    // --> we can check pValue for undefined and also allow simple string-conditions
+    // --> this only works if isFullFieldQualifier() can detect if the supplied string is a valid field-string or if it is some sql. 
+    //     currently it checks for some special characters which should not exist in any field-string but in conditions. 
+    //     If there is a special case missing -> add it to the regexp in isFullFieldQualifier()
+    if (pValue === undefined && pCond === undefined && pFieldType === undefined && typeof pFieldOrCond == "string" && SqlUtils.isFullFieldQualifier(pFieldOrCond))
     {
-        var pointPos = field.indexOf(".");
-        
-        if (pointPos > 0 && pointPos < field.length-1)
-        {
-            alias = field;
-        }
+        if (pMandatory)
+            throw SqlBuilder.ERROR_VALUE_IS_MANDATORY();
         else
-        {
-            throw new Error(translate.withArguments("${SQL_LIB_FIELD_WRONG_FORMAT} field: %0", [field]));
-        }
+            return this;
     }
-    else
+    
+    if (pMandatory === undefined)
+        pMandatory = true;
+  
+    // just call the andCondition function if it is only a Condition
+    if (pFieldOrCond !== undefined && pValue === undefined && pCond === undefined && pFieldType === undefined)
+        return this._whereCondition(pFieldOrCond, pMandatory, pAddPreparedConditionCallback, true);
+    
+    // first check the default-mandatory-cases: null or undefined. everything else such as checking $-variables is done later
+    if (pMandatory && (pValue === null || pValue === undefined))
+        throw SqlBuilder.ERROR_VALUE_IS_MANDATORY();
+    
+    // a field is string or array -> normal case
+    // OR !pFieldOrCond and pValue and pCond is given -> preparedSQL/SqlBuilder can be used without field if pCond is set
+    if((typeof pFieldOrCond == "string" || Array.isArray(pFieldOrCond)) || (!pFieldOrCond && (pCond && pValue instanceof SqlBuilder || !(pValue instanceof SqlBuilder))))
     {
-        if (field.length == 3)
-        {
-            alias = field[2] + "." + field[1];
-            field = field[0] + "." + field[1];
+        var field = pFieldOrCond;
+        var typeofValue = typeof pValue;
+
+        // pValue can be...
+        // ... a SqlBuilder / Prepared statement array -> it is a SqlBuilder containing a complete subquery or an simple array (in statement)
+        if (pValue instanceof SqlBuilder || Array.isArray(pValue) || (typeofValue == "string" && (pFieldOrCond == undefined || pFieldOrCond == null)))
+        {            
+            // check if the array is really a prepared statement or just a value-array for an in
+            if (Array.isArray(pValue) && (pValue.lenght <= 1 || !Array.isArray(pValue[1])))
+            {
+                if (pValue.length == 0)
+                {
+                    if (pMandatory)
+                        throw SqlBuilder.ERROR_VALUE_IS_MANDATORY();
+                    
+                    return this;
+                }
+                
+                if (!pCond)
+                    pCond = "# in ?";
+                
+                if (field != null)
+                {
+                    [alias, parsedField] = SqlUtils.parseField(field)
+                    if (pFieldType === undefined || pFieldType === null)
+                        pFieldType = SqlUtils.getSingleColumnType(parsedField, undefined, this.alias);
+                }
+                                
+                // value-array -> convert it to a prepared statement ["(?, ?, ?)", [[val1, type1], [val2, type2], [val3, type3]]]
+                this._whereCondition(this._prepare(field, SqlUtils.getSqlInStatement(undefined, pValue, undefined, true, pFieldType), pCond, pFieldType, false), undefined, pAddPreparedConditionCallback, true);
+                return this;
+            }
+            
+            if (pFieldOrCond !== null && pFieldOrCond !== undefined)
+            {
+                if (!pCond)
+                    pCond = "# = ?"
+                
+                pCond = SqlUtils.replaceConditionTemplate(pCond, '#', SqlUtils.parseField(pFieldOrCond)[0])
+            }
+            else
+            {
+                if (!pCond)
+                    pCond = "?"
+            }
+            
+            return this._whereSubquery(pValue, pMandatory, pCond, pAddPreparedConditionCallback);
         }
-        else
+
+        if (!pCond)
+            pCond = "# = ?"
+
+        // ... a string starting with $ -> jdito varable which has to be resolved
+        //TODO: this could be not wanted in some cases, what if you want to search for '$'? --> posibility to eycape with a second $
+        if (typeofValue == "string" && pValue[0] == "$")
         {
-            throw new Error(translate.withArguments("${SQL_LIB_FIELD_WRONG_FORMAT} field: %0", [field.toSource()]));
+            pValue = vars.getString(pValue)
+            if (pMandatory && pValue === null)
+                throw SqlBuilder.ERROR_VALUE_IS_MANDATORY_JDITO_VAR();
+            
+            if (pValue == "" || pValue)
+                this._whereCondition(this._prepare(field, pValue, pCond, pFieldType), undefined, pAddPreparedConditionCallback);
+            
+            return this;
         }
-    }
-    
-    var type;
-    
-    if (fieldType == undefined)
-        fieldType = SqlUtils.getSingleColumnType(field, undefined, this.alias);
 
-    //this function looks more complex (and slower) than it actually is
-    /* the following regex looks like this after javascript-escaping of the backslash: (?<!\\)((?:\\\\)*)#
-    the regexp searches for the unescaped character and these characters are replaced by the field name
+        // ... everything else -> just pass it
+        if (pValue === false || pValue === 0 || pValue === "" || pValue)
+        {
+            this._whereCondition(this._prepare(field, pValue, pCond, pFieldType), undefined, pAddPreparedConditionCallback);
+        }
+            
 
-    examples:
-    ---------------------
-    | # --match         |
-    | \# --no-match     |
-    | \\# --match       |
-    | \\\# --no-match   |
-    | \\\\# --match     |
-    ---------------------
-    */
-    //use replaceAll because it's faster and supports negative lookbehinds
-    cond = text.replaceAll(cond, {
-        //manually readd the replaced backslashes by using a group reference, because they a part of the match and therefore replaced by "replaceAll"
-        //since the field COULD contain already a group reference (I think this is extremely uncommon; 
-        //probably that never happens but better stay save): escape that references within the fieldname
-        "(?<!\\\\)((?:\\\\\\\\)*)#": "$1" + text.replaceAll(alias, {
-            "$1": "\\$1"
-        }),
-        //now that we've replaced the correct field placeholder let's replace the escaped number sign "\#" to a normal number sign "#"
-        "\\\\#": "#"
-    });
-    
-    
+        return this;
+    }
     
-    type = fieldType
-    this.preparedValues.push([value.toString(), type]);
-    return cond;
+    throw SqlBuilder.ERROR_UNSUPPORTED_PARAMETER_COMBINATION();
 }
 
-
 /**
- * function that resets the current SqlCondition as if no conditions would have been added
- * this is usefull if you want to reuse the same object over and over
- * @return {null} 
+ * @private
  */
-SqlCondition.prototype.clear = function() {
-    this._sqlStorage = "";
-    this.preparedValues = [];
-    return this;
+SqlBuilder.prototype._and = function(pFieldOrCond, pValue, pMandatory, pCond, pFieldType)
+{
+    var that = this;
+ 
+    return this._addWhere(pFieldOrCond, pValue, pMandatory, pCond, pFieldType, function(pPreparedCondition) 
+    {
+        that._where._previouslyOnlyOr = false;
+        if (pPreparedCondition.length == 2 && typeof pPreparedCondition[0] == "string" && pPreparedCondition[0] != "" && Array.isArray(pPreparedCondition[1]))
+        {
+            if (that.hasCondition())
+                that._where._sqlStorage += " and ";
+            
+            that._where._sqlStorage += pPreparedCondition[0];
+            that._where.preparedValues = that._where.preparedValues.concat(pPreparedCondition[1]);
+        }
+    });
 }
 
 /**
- * hidden function for initializing all properties for the sql conditions
- * @return {null} 
- * 
- * @ignore
+ * @private
  */
-SqlCondition.prototype._init = function() {
-    //init only wraps the clear function to avoid confusion in the constructor (and provide better extensibility)
-    return this.clear();
+SqlBuilder.prototype._or = function(pFieldOrCond, pValue, pMandatory, pCond, pFieldType)
+{
+    var that = this;
+    
+    return this._addWhere(pFieldOrCond, pValue, pMandatory, pCond, pFieldType, function(pPreparedCondition, pAlreadySurroundedByBrackets) 
+    {
+        if (pPreparedCondition.length == 2 && typeof pPreparedCondition[0] == "string" && pPreparedCondition[0] != "" && Array.isArray(pPreparedCondition[1]))
+        {   
+            if (that._where._previouslyOnlyOr)
+            {
+                that._where._sqlStorage = that._where._sqlStorage + " or " + pPreparedCondition[0];
+                that._where._lastWasOr = true;
+            }
+            else if (that.hasCondition())
+            {
+                let cond = pPreparedCondition[0];
+                
+                if (!pAlreadySurroundedByBrackets)
+                    cond = "(" + cond + ")";
+                
+                if (that._where._lastWasOr)
+                    that._where._sqlStorage = that._where._sqlStorage + " or " + cond;
+                else
+                    that._where._sqlStorage = "(" + that._where._sqlStorage + ") or " + cond;
+                
+                that._where._lastWasOr = true;
+            } 
+            else
+            {
+                if (!that.hasCondition())
+                    that._where._previouslyOnlyOr = true;
+                
+                that._where._sqlStorage = pPreparedCondition[0];
+            }
+            that._where.preparedValues = that._where.preparedValues.concat(pPreparedCondition[1]);
+        }
+    });
 }
 
-// some static functions for often used tasks. They are only provided for very simple tasks.
+SqlBuilder.NOT_IN = function()
+{
+    return "# not in ?";
+}
 
-/**
- * pField = pValue
- * @param {String} pField the database field as "tablename.columnname"; e.g. "ORGANISATION.NAME"
- * @param {String} pValue the value that shall be set into the prepared statement
- * @param {String} [pAlternativeCond=""] Condition that is returned when nothing has been appended.
- * @param {String} [pAlias=the current alias] the database alias where the condition shall be executed later (important for column types of preparedStatements)
- * 
- * @return {Array[][][]} Prepared condition with [condition, [[field, type]]]
- */
-SqlCondition.equals = function(pField, pValue, pAlternativeCond, pAlias) {
-    return SqlCondition.begin(pAlias).andPrepare(pField, pValue).build(pAlternativeCond);
+SqlBuilder.IN = function()
+{
+    return "# in ?";
 }
 
-/**
- * pField <> pValue
- * @param {String} pField the database field as "tablename.columnname"; e.g. "ORGANISATION.NAME"
- * @param {String} pValue the value that shall be set into the prepared statement
- * @param {String} [pAlternativeCond=""] Condition that is returned when nothing has been appended.
- * @param {String} [pAlias=the current alias] the database alias where the condition shall be executed later (important for column types of preparedStatements)
- * 
- * @return {Array[][][]} Prepared condition with [condition, [[field, type]]]
- */
-SqlCondition.equalsNot = function(pField, pValue, pAlternativeCond, pAlias) {
-    return SqlCondition.begin(pAlias).andPrepare(pField, pValue, "# <> ?").build(pAlternativeCond);
+SqlBuilder.EXISTS = function()
+{
+    return "exists ?";
+}
+
+SqlBuilder.NOT_EXISTS = function()
+{
+    return "exists ?";
 }
 
+//TODO: more detailed comments with examples
 
 /**
- * Object for building sqls. The main purpose of this is to make it
- * possible to use SqlCondition objects inside join conditions or sub sqls.
- * This can also be useful to build complex sqls where parts should be added
- * dynamically while keeping the code clean.
+ * appends a condition with or
  * 
- * @class
+ * @param {String|SqlBuilder} pFieldOrCond
+ * @param {String|String[]|SqlBuilder} pValue
+ * @param {String} pCond
+ * @param {Number} pFieldType
+ * @return {SqlBuilder} the current SqlBuilder object
  */
-function SqlBuilder ()
+SqlBuilder.prototype.or = function(pFieldOrCond, pValue, pCond, pFieldType)
 {
-    if(!(this instanceof SqlBuilder)) 
-        throw new Error(translate.text("SqlBuilder must be instanciated with 'new'"));
-    this._sqlStr = "";
-    this._select = null;
-    this._from = null;
-    this._joins = [];
-    this._where = null;
-    this._groupBy = null;
-    this._having = null;
-    this._orderBy = null;
-    this._unions = [];
+    return this._or(pFieldOrCond, pValue, true, pCond, pFieldType);
 }
 
 /**
- * Alternative way of creating a new SqlBuilder object that allows to use
- * methods on it directly without having to put brackets around it
- * 
- * @return {SqlBuilder} a new SqlBuilder object
- * 
- * @example 
- * var query = SqlBuilder.begin()
- *   .select("ORGANISATION.NAME, FIRSTNAME, LASTNAME")
- *   .from("PERSON")
- *   .join("CONTACT", "CONTACT.PERSON_ID = PERSON.PERSONID")
- *   .leftJoin("ORGANISATION", SqlCondition.begin()
- *       .and("CONTACT.ORGANISATION_ID = ORGANISATION.ORGANISATIONID")
- *       .andPrepare("ORGANISATION.NAME", "S%", "# like ?")
- *       .build("1=2"))
- *   .where(SqlCondition.begin()
- *       .andPrepare("CONTACT.STATUS", $KeywordRegistry.contactStatus$active())
- *       .build("1=2"));
+ * appends a condition with or if a value is provided
  * 
- * if (getCountry) //changing and adding parts
- * {
- *   query.select("ORGANISATION.NAME, FIRSTNAME, LASTNAME, COUNTRY");
- *   query.leftJoin("ADDRESS", "CONTACT.ADDRESS_ID = ADDRESS.ADDRESSID");
- * }
- *   
- * var data = db.table(query.build());
+ * @param {String|SqlBuilder} pFieldOrCond
+ * @param {String|String[]|SqlBuilder} pValue
+ * @param {String} pCond
+ * @param {Number} pFieldType
+ * @return {SqlBuilder} the current SqlBuilder object
  */
-SqlBuilder.begin = function ()
+SqlBuilder.prototype.orIfSet = function(pFieldOrCond, pValue, pCond, pFieldType)
 {
-    return new SqlBuilder();
+    return this._or(pFieldOrCond, pValue, false, pCond, pFieldType);
 }
 
 /**
- * Builds the sql and uses db.translateStatement to make a string out of it.
- * @return {String} the sql as string
+ * appends a condition with and
+ * 
+ * @param {String|SqlBuilder} pFieldOrCond
+ * @param {String|String[]|SqlBuilder} pValue
+ * @param {String} pCond
+ * @param {Number} pFieldType
+ * @return {SqlBuilder} the current SqlBuilder object
  */
-SqlBuilder.prototype.toString = function ()
+SqlBuilder.prototype.and = function(pFieldOrCond, pValue, pCond, pFieldType)
 {
-    return SqlUtils.translateStatementWithQuotes(this.build());
+    return this._and(pFieldOrCond, pValue, true, pCond, pFieldType);
 }
 
 /**
- * Sets the select clause of the sql.
- * @param {String|String[]} pFields
- * @return {SqlBuilder} current SqlBuilder object
+ * appends a condition with and if a value is provided
+ * 
+ * @param {String|SqlBuilder} pFieldOrCond
+ * @param {String|String[]|SqlBuilder} pValue
+ * @param {String} pCond
+ * @param {Number} pFieldType
+ * @return {SqlBuilder} the current SqlBuilder object
  */
-SqlBuilder.prototype.select = function (pFields)
+SqlBuilder.prototype.andIfSet = function(pFieldOrCond, pValue, pCond, pFieldType)
 {
-    this._select = this._getClause(pFields, "select", true);
-    return this;
+    return this._and(pFieldOrCond, pValue, false, pCond, pFieldType);
 }
 
 /**
- * Sets the select clause of the sql with distinct.
- * @param {String|String[]} pFields
+ * Sets the order by clause of the sql.
+ * @param {String|String[]} pOrderBy
  * @return {SqlBuilder} current SqlBuilder object
  */
-SqlBuilder.prototype.selectDistinct = function (pFields)
+SqlBuilder.prototype.orderBy = function(pOrderBy)
 {
-    this._select = this._getClause(pFields, "select distinct", true);
+    this._orderBy = SqlBuilder._getStatement(pOrderBy, "order by", undefined, true);
     return this;
 }
 
 /**
- * Sets the from clause of the sql.
- * @param {String} pTable
- * @param {String} [pAlias] table alias
+ * Sets the group by clause of the sql.
+ * @param {String|String[]} pFields
  * @return {SqlBuilder} current SqlBuilder object
  */
-SqlBuilder.prototype.from = function (pTable, pAlias)
+SqlBuilder.prototype.groupBy = function(pFields)
 {
-    if (pAlias)
-        pTable += " " + pAlias;
-    this._from = this._getClause(pTable, "from");
+    this._groupBy = SqlBuilder._getStatement(pFields, "group by", undefined, true);
     return this;
 }
 
 /**
- * Adds a join clause to the sql.
- * @param {String} pTable
- * @param {String|String[]|SqlCondition} pCondition The where condition. This can be
- *          a string (without the where keyword), a SqlCondition or an array (for prepared queries).
- * @param {String} [pAlias] table alias
+ * Adds another SqlBuilder object or select string with union.
+ * @param {SqlBuilder|String} pSelect
  * @return {SqlBuilder} current SqlBuilder object
  */
-SqlBuilder.prototype.join = function (pTable, pCondition, pAlias)
+SqlBuilder.prototype.union = function(pSelect)
 {
-    var joinStr = "join " + pTable;
-    if (pAlias)
-        joinStr += " " + pAlias;
-    this._joins.push(this._getClause(pCondition, joinStr + " on"));
+    this._unions.push(SqlBuilder._getStatement(pSelect, "union"));
     return this;
 }
 
 /**
- * Adds a left join clause to the sql.
- * @param {String} pTable
- * @param {String|String[]|SqlCondition} pCondition The where condition. This can be
- *          a string (without the where keyword), a SqlCondition or an array (for prepared queries).
- * @param {String} [pAlias] table alias
+ * Adds another SqlBuilder object or select string with union all.
+ * @param {SqlBuilder|String} pSelect
  * @return {SqlBuilder} current SqlBuilder object
  */
-SqlBuilder.prototype.leftJoin = function (pTable, pCondition, pAlias)
+SqlBuilder.prototype.unionAll = function(pSelect)
 {
-    var joinStr = "left join " + pTable;
-    if (pAlias)
-        joinStr += " " + pAlias;
-    this._joins.push(this._getClause(pCondition, joinStr + " on"));
+    this._unions.push(SqlBuilder._getStatement(pSelect, "union all"));
     return this;
 }
 
 /**
- * Sets the where clause of the sql.
+ * Adds a having clause to the sql.
  * 
- * @param {String|String[]|SqlCondition} pCondition The where condition. This can be
- *          a string (without the where keyword), a SqlCondition or an array (for prepared queries).
+ * @param {String|String[]|SqlBuilder} pCondition The where condition. This can be
+ *          a string (without the where keyword), a SqlBuilder or an array (for prepared queries).
  *          
  * @return {SqlBuilder} current SqlBuilder object
  */
-SqlBuilder.prototype.where = function (pCondition)
+SqlBuilder.prototype.having = function(pCondition)
 {
-    this._where = this._getClause(pCondition, "where");
+    this._having = SqlBuilder._getStatement(pCondition, "having");
     return this;
 }
 
 /**
- * Sets the order by clause of the sql.
- * @param {String} pOrderBy
- * @return {SqlBuilder} current SqlBuilder object
+ * checks if conditions have been added to the object
+ * @return {Boolean} true if conditions have been added, false when not
  */
-SqlBuilder.prototype.orderBy = function (pOrderBy)
-{
-    this.orderBy = this._getClause(pOrderBy, "order by");
-    return this;
+SqlBuilder.prototype.hasCondition = function() {
+    if (this._where._sqlStorage)
+        return true;
+    return false;
 }
 
 /**
- * Sets the group by clause of the sql.
- * @param {String|String[]} pFields
- * @return {SqlBuilder} current SqlBuilder object
+ * checks if conditions have been added to the object
+ * @return {Boolean} true if conditions have been added, false when not
  */
-SqlBuilder.prototype.groupBy = function (pFields)
-{
-    this._groupBy = this._getClause(pFields, "group by", true);
-    return this;
+SqlBuilder.prototype.whereWasCalled = function() {
+    return this._where._whereWasCalled;
 }
 
 /**
- * Adds another SqlBuilder object or select string with union.
- * @param {SqlBuilder|String} pSelect
- * @return {SqlBuilder} current SqlBuilder object
+ * checks if all mandatory parts to execute the select have been added to the object
+ * @return {Boolean} true if select and from have been added, false when not
  */
-SqlBuilder.prototype.union = function (pSelect)
+SqlBuilder.prototype.isFullSelect = function() 
 {
-    this._unions.push(this._getClause(pSelect, "union"));
-    return this;
+    if (!this._select || !this._from)
+        return false;
+    
+    return true;
 }
 
 /**
- * Adds another SqlBuilder object or select string with union all.
- * @param {SqlBuilder|String} pSelect
- * @return {SqlBuilder} current SqlBuilder object
+ * function that resets the current where-condition as if no conditions would have been added
+ * this is usefull if you want to reuse the same Builder over and over again with a different condition
+ * @return {null} 
  */
-SqlBuilder.prototype.unionAll = function (pSelect)
+SqlBuilder.prototype.clearWhere = function() 
 {
-    this._unions.push(this._getClause(pSelect, "union all"));
+    this._where._sqlStorage = "";
+    this._where.preparedValues = [];
     return this;
 }
 
 /**
- * Adds a having clause to the sql.
- * 
- * @param {String|String[]|SqlCondition} pCondition The where condition. This can be
- *          a string (without the where keyword), a SqlCondition or an array (for prepared queries).
- *          
- * @return {SqlBuilder} current SqlBuilder object
+ * hidden function for composing preparedStatements
+ * @param {String | String[]} field the database field as "tablename.columnname"; e.g. "ORGANISATION.NAME" or as array with column-alias: ["ORGANISATION", "NAME", "myorgAlias"]
+ * @param {String} value the value that shall be set into the prepared statement
+ * @param {String} cond the strucutre of the SQL condition as preparedString, you can use a number sign "#" as placeholder for you fieldname; 
+ *                 e.g. "# > ?"; escaping the number sign is possible with a backslash "\"
+ *                 Default is "# = ?" 
+ * @param {Numeric | Boolean} [fieldType] SQL-column-type; if the fieldType is not given it's loaded automatically;
+ *                              The loaded type is cached if no type is given. So it is also safe to use this in a loop.
+ *                              e.g.
+ *                              for (...) {
+ *                                  cond.andPrepare("SALESPROJECT_CLASSIFICATION.TYPE", entry, "# <> ?")
+ *                              }
+ * @return {String} the replaced SQL-condition string (replace # by the fieldname)
+ * @private
  */
-SqlBuilder.prototype.having = function (pCondition)
+SqlBuilder.prototype._prepare = function(field, value, cond, fieldType, pSubselectBrackets) 
 {
-    this._having = this._getClause(pCondition, "having");
-    return this;
+    if (pSubselectBrackets == undefined)
+        pSubselectBrackets = true;
+    
+    if (value == undefined)
+        throw new Error(translate.withArguments("${SQL_LIB_UNDEFINED_VALUE} field: %0", [field]));
+    
+    if (cond == undefined) 
+        cond = "# = ?";
+
+    var alias;
+    if (field != null)
+    {
+        [alias, field] = SqlUtils.parseField(field)
+        if (fieldType == undefined)
+            fieldType = SqlUtils.getSingleColumnType(field, undefined, this.alias);
+    }
+    
+    var values = [];
+
+    // If subselect: replace '?' with the subselect
+    if (Array.isArray(value))
+    {
+        cond = SqlUtils.replaceConditionTemplate(cond, "\\?", (pSubselectBrackets ? " ( " : " ") + value[0] + (pSubselectBrackets ? " ) " : " "));
+        values = value[1];
+    } 
+    else
+    {
+        var type = fieldType;
+        values = [[value.toString(), type]];
+    }
+
+    if (field != null)
+        cond = SqlUtils.replaceConditionTemplate(cond, "#", alias);
+    
+    return [cond, values];
 }
 
 /**
@@ -843,17 +883,18 @@ SqlBuilder.prototype.having = function (pCondition)
  * 
  * @param {String|String[]|SqlBuilder|SqlCondition} pElement the element to append
  * @param {String} [pPrefix] string to be added before pElement
+ * @param {String} [pPostfix] string to be added after pElement
  * @param {Boolean} [pAutoJoin] if this is true and pElement is an array, it will be automatically
  *                               joined together to a string
  * 
  * @private
  */
-SqlBuilder.prototype._getClause = function (pElement, pPrefix, pAutoJoin)
+SqlBuilder._getStatement = function (pElement, pPrefix, pPostfix, pAutoJoin)
 {
     var preparedValues = [];
     if (typeof pElement !== "string")
     {
-        if (pElement.length !== undefined && pAutoJoin) //array of fields
+        if (Array.isArray(pElement) && pElement.length !== undefined && pAutoJoin) //array of fields
         {
             for (let i = 0, l = pElement.length; i < l; i++)
             {
@@ -870,53 +911,111 @@ SqlBuilder.prototype._getClause = function (pElement, pPrefix, pAutoJoin)
 
     if (pPrefix && pElement)
         pElement = pPrefix + " " + pElement;
+    if (pPostfix && pElement)
+        pElement += " " + pPostfix;
     
-    return [pElement.toString(), preparedValues];
-    
+    return {
+        preparedValues: preparedValues,
+        _sqlStorage: pElement.toString()
+    };
+
     function _getElement (element)
     {
-        if (element instanceof SqlBuilder || element instanceof SqlCondition)
+        var isSubQuery = false;
+        if (element instanceof SqlBuilder)
+        {
+            if (element.isFullSelect())
+                isSubQuery = true;
+                
             element = element.build();
+        }
         preparedValues = preparedValues.concat(element[1]);
-        if (element instanceof SqlBuilder || pAutoJoin)
+        if (isSubQuery || pAutoJoin)
             return "(" + element[0] + ")";
         return element[0];
     }
 }
 
+/**
+ * concatenates two prepared statements
+ * 
+ * @param {Array} pStatements array of prepared statements
+ * 
+ * @return {Array} the resultung prepared statement
+ */
+SqlBuilder.concatPreparedStatements = function (pStatements)
+{
+    var sqlStr = "";
+    var preparedVals = [];
+    for (let i = 0, l = pStatements.length; i < l; i++)
+    {
+        let part = pStatements[i];
+        if (part && part.length)
+        {
+            if (sqlStr && part[0])
+                sqlStr += " ";
+            sqlStr += part[0];
+            if (part[1].length)
+                preparedVals = preparedVals.concat(part[1]);
+        }
+    }
+    return [sqlStr, preparedVals];
+}
+
+/**
+ * builds a prepared condition out of the object. Only the condition is used.Select, from, ... are ignored.
+ * 
+ * @return {String[]} prepared condition
+ */
+SqlBuilder.prototype.buildCondition = function()
+{   
+    return [this._where._sqlStorage, this._where.preparedValues];
+}
+
 /**
  * builds a prepared statement out of the object
  * 
  * @return {String[]} prepared statement
  */
-SqlBuilder.prototype.build = function ()
+SqlBuilder.prototype.build = function(pDefaultConditionIfNone)
 {
-    if (!this._select)
-        throw new Error(translate.text("SqlBuilder must contain a select clause!"));
-    if (!this._from)
-        throw new Error(translate.text("SqlBuilder must contain a from clause!"));
+    var wherePrefix = "";
+    
+    if (this.isFullSelect() && this._where._sqlStorage)
+        wherePrefix = "where ";
+    
+    var whereSql = this._where._sqlStorage;
+    
+    if (!this.hasCondition() && pDefaultConditionIfNone)
+        whereSql = "where " + pDefaultConditionIfNone;
+    
+    var whereObj = {
+        _sqlStorage : wherePrefix + whereSql,
+        preparedValues : this._where.preparedValues
+    }
     
-    var sqlStr = "";
-    var preparedVals = [];
     var allParts = [
         this._select,
-        this._from
+        this._from,
         ].concat(this._joins).concat([
-        this._where,
+        whereObj,
         this._groupBy,
         this._having,
         this._orderBy
         ]).concat(this._unions);
         
+    var sqlStr = "";
+    var preparedVals = [];
     for (let i = 0, l = allParts.length; i < l; i++)
     {
         let part = allParts[i];
-        if (part && part.length)
+        if (part)
         {
-            if (sqlStr)
+            if (sqlStr && part._sqlStorage)
                 sqlStr += " ";
-            sqlStr += part[0];
-            preparedVals = preparedVals.concat(part[1]);
+            sqlStr += part._sqlStorage;
+            if (part.preparedValues.length)
+                preparedVals = preparedVals.concat(part.preparedValues);
         }
     }
     return [sqlStr, preparedVals];
@@ -928,12 +1027,247 @@ SqlBuilder.prototype.build = function ()
  * It resolves all prepared values.
  * @param {String} [pAlias=undefined] the alias to use for db.translateStatement
  * @return {String} plain SQL statement
+ * 
+ * @deprecated use .toString()
+ */
+SqlBuilder.prototype.translate = function(pDefaultConditionIfNone)
+{
+    return this.toString(pDefaultConditionIfNone);
+}
+
+/**
+ * Updates data in the database.
+ * 
+ * @param {Boolean} [pExecuteOnlyIfConditionExists=true] If true, the update is only done if there is a condition.
+ *      <strong>If this is set to false and there is no condition, every row in the table will be updated!</strong>
+ * @param {Array} pColumns
+ * @param {Array} [pColumnTypes]
+ * @param {Array} pValues
+ * @param {String} [pTableName] The table for updating data. If omitted, the from part of the SqlBuilder will be used.
+ * @param {Number} [pTimeout=-1]
+ * @return {Number} the number of rows affected
+ * @throws {Error} if no table is provided
+ */
+SqlBuilder.prototype.updateData = function(pExecuteOnlyIfConditionExists, pColumns, pColumnTypes, pValues, pTableName, pTimeout)
+{
+    if (this._checkForUpdate(pExecuteOnlyIfConditionExists))
+    {
+        if (!pTableName && !this._from)
+            throw SqlBuilder.ERROR_NO_TABLE();
+        
+        return db.updateData(
+            (pTableName ? pTableName : this._tableName),
+            pColumns,
+            pColumnTypes,
+            pValues,
+            this.buildCondition(),
+            (this.alias ? this.alias : db.getCurrentAlias()),
+            (pTimeout ? pTimeout : -1));
+    }
+    
+    return 0;
+}
+
+/**
+ * Deletes data from the database.
+ * 
+ * @param {Boolean} [pExecuteOnlyIfConditionExists=true] If true, the deletion is only done if there is a condition.
+ *      <strong>If this is set to false and there is no condition, every row in the table will be deleted!</strong>
+ * @param {String} [pTableName] The table for deleting data. If omitted, the from part of the SqlBuilder will be used.
+ * @param {Number} [pTimeout=-1]
+ * @return {Number} the number of rows affected
+ * @throws {Error} if no table is provided
+ */
+SqlBuilder.prototype.deleteData = function(pExecuteOnlyIfConditionExists, pTableName, pTimeout)
+{
+    if (this._checkForUpdate(pExecuteOnlyIfConditionExists))
+    {
+        if (!pTableName && !this._from)
+            throw SqlBuilder.ERROR_NO_TABLE();
+        
+        return db.deleteData(
+            (pTableName ? pTableName : this._tableName),
+            this.buildCondition(),
+            (this.alias ? this.alias : db.getCurrentAlias()),
+            (pTimeout ? pTimeout : -1));
+    }
+    else
+    {
+        return 0;
+    }
+}
+
+/**
+ * Executes the SQL using db.cell and returns the result.
+ * 
+ * @param {Boolean} [pExecuteOnlyIfConditionExists=false] if true and there is no condition, "" is returned
+ * @return {String} the result of the query
+ */
+SqlBuilder.prototype.cell = function(pExecuteOnlyIfConditionExists, pFallbackValue)
+{
+    if (this._checkForSelect(pExecuteOnlyIfConditionExists))
+    {
+        return db.cell(this.build(),
+            (this.alias ? this.alias : db.getCurrentAlias()));
+    }
+    else
+    {
+        return (pFallbackValue ? pFallbackValue : "");
+    }
+}
+
+/**
+ * Executes the SQL using db.array(db.ROW, ...) and returns the result.
+ * 
+ * @param {Boolean} [pExecuteOnlyIfConditionExists=false] if true and there is no condition, [] is returned
+ * @param {Number} [pMaxRows=0]
+ * @param {Number} [pTimeout=-1]
+ * @return {String[]} the result of the query
+ */
+SqlBuilder.prototype.arrayRow = function (pExecuteOnlyIfConditionExists, pMaxRows, pTimeout)
+{
+    return this.array(db.ROW, pExecuteOnlyIfConditionExists, pMaxRows, pTimeout);
+}
+
+/**
+ * Executes the SQL using db.array(db.COLUMN, ...) and returns the result.
+ * 
+ * @param {Boolean} [pExecuteOnlyIfConditionExists=false] if true and there is no condition, [] is returned
+ * @param {Number} [pMaxRows=0]
+ * @param {Number} [pTimeout=-1]
+ * @return {String[]} the result of the query
+ */
+SqlBuilder.prototype.arrayColumn = function (pExecuteOnlyIfConditionExists, pMaxRows, pTimeout)
+{
+    return this.array(db.COLUMN, pExecuteOnlyIfConditionExists, pMaxRows, pTimeout);
+}
+
+/**
+ * Executes the SQL using db.array and returns the result.
+ * 
+ * @param {Number} pType db.ROW or db.COLUMN
+ * @param {Boolean} [pExecuteOnlyIfConditionExists=false] if true and there is no condition, [] is returned
+ * @param {Number} [pMaxRows=0]
+ * @param {Number} [pTimeout=-1]
+ * @return {String[]} the result of the query
+ */
+SqlBuilder.prototype.array = function(pType, pExecuteOnlyIfConditionExists, pMaxRows, pTimeout)
+{
+    if (this._checkForSelect(pExecuteOnlyIfConditionExists))
+    {
+        return db.array(pType, this.build(),
+            (this.alias ? this.alias : db.getCurrentAlias()),
+            (pMaxRows ? pMaxRows : 0),
+            (pTimeout ? pTimeout : -1));
+    }
+    else
+    {
+        return [];
+    }
+}
+
+/**
+ * Executes the SQL using db.arrayPage and returns the result.
+ * 
+ * @param {Number} pType db.ROW or db.COLUMN
+ * @param {Number} pStartIndex
+ * @param {Number} pRowCount
+ * @param {Boolean} [pExecuteOnlyIfConditionExists=false] if true and there is no condition, [] is returned
+ * @param {Number} [pTimeout=-1]
+ * @return {String[]} the result of the query
+ */
+SqlBuilder.prototype.arrayPage = function(pType, pStartIndex, pRowCount, pExecuteOnlyIfConditionExists, pTimeout)
+{
+    if (this._checkForSelect(pExecuteOnlyIfConditionExists))
+    {
+        return db.arrayPage(pType, this.build(),
+            (this.alias ? this.alias : db.getCurrentAlias()),
+            pStartIndex,
+            pRowCount,
+            (pTimeout ? pTimeout : -1));
+    }
+    else
+    {
+        return [];
+    }
+}
+
+/**
+ * Executes the SQL using db.table and returns the result.
+ * 
+ * @param {Boolean} [pExecuteOnlyIfConditionExists=false] if true and there is no condition, [] is returned
+ * @param {Number} [pMaxRows=0]
+ * @param {Number} [pTimeout=-1]
+ * @return {String[][]} the result of the query
+ */
+SqlBuilder.prototype.table = function(pExecuteOnlyIfConditionExists, pMaxRows, pTimeout)
+{
+    if (this._checkForSelect(pExecuteOnlyIfConditionExists))
+    {
+        return db.table(this.build(),
+            (this.alias ? this.alias : db.getCurrentAlias()),
+            (pMaxRows ? pMaxRows : 0),
+            (pTimeout ? pTimeout : -1));
+    }
+    else
+    {
+        return [];
+    }
+}
+
+/**
+ * Executes the SQL using db.tablePage and returns the result.
+ * 
+ * @param {Number} pStartIndex
+ * @param {Number} pRowCount
+ * @param {Boolean} [pExecuteOnlyIfConditionExists=false] if true and there is no condition, [] is returned
+ * @param {Number} [pTimeout=-1]
+ * @return {String[][]} the result of the query
+ */
+SqlBuilder.prototype.tablePage = function(pStartIndex, pRowCount, pExecuteOnlyIfConditionExists, pTimeout)
+{   
+    if (this._checkForSelect(pExecuteOnlyIfConditionExists))
+    {
+        return db.tablePage(this.build(),
+            (this.alias ? this.alias : db.getCurrentAlias()),
+            pStartIndex,
+            pRowCount,
+            (pTimeout ? pTimeout : -1));
+    }
+    else
+    {
+        return [];
+    }
+}
+
+/**
+ * @private
  */
-SqlBuilder.prototype.translate = function(pAlias)
+SqlBuilder.prototype._checkForUpdate = function(pExecuteOnlyIfConditionExists) 
 {
-    return SqlUtils.translateStatementWithQuotes(this.build(), pAlias);
+    if (pExecuteOnlyIfConditionExists == undefined)
+        pExecuteOnlyIfConditionExists = true;
+    
+    return !pExecuteOnlyIfConditionExists || this.hasCondition();
 }
 
+/**
+ * @private
+ */
+SqlBuilder.prototype._checkForSelect = function(pExecuteOnlyIfConditionExists) 
+{
+    if (pExecuteOnlyIfConditionExists == undefined)
+        pExecuteOnlyIfConditionExists = false;
+    
+    if (this.isFullSelect())
+    {
+        return !pExecuteOnlyIfConditionExists || this.hasCondition();
+    }
+    else
+    {
+        throw SqlBuilder.ERROR_INCOMPLETE_SELECT();
+    }
+}
 
 /**
  *provides functions for masking sql functions
@@ -950,7 +1284,7 @@ function SqlMaskingUtils(alias) {
             if (v != null)
                 this._dbType = db.getDatabaseType(this._alias);
         },
-        get: function (){
+        get: function(){
             return this._alias;
         }
     });
@@ -961,7 +1295,7 @@ function SqlMaskingUtils(alias) {
             this._alias = null;
             this._dbType = v;
         },
-        get: function (){
+        get: function(){
             return this._dbType;
         }
     });
@@ -1060,7 +1394,7 @@ SqlMaskingUtils.prototype.min = function(field)
  *
  * @return {String} sql part to be included in sql-statements
  */
-SqlMaskingUtils.prototype.cast = function (field, targetDatatype, targetLength) {
+SqlMaskingUtils.prototype.cast = function(field, targetDatatype, targetLength) {
     /* Some informations if you want to add supported databaseTypes or dataTypes:
      * You should consider using the _mapDefaults function-expression (details in the functions doc)
      * However you shouldn't use the function in a "default"-Block of a switch-case because of the following behaviour:
@@ -1077,7 +1411,7 @@ SqlMaskingUtils.prototype.cast = function (field, targetDatatype, targetLength)
      * @param {Number} dataType input as a value of "SQLTYPES." that will be mapped to a string
      * @return {String} the mapped dataType for using in a sql-statement
      */
-    _mapDefaults = function (dataType) {
+    _mapDefaults = function(dataType) {
         var res;
         switch(dataType) {
             case SQLTYPES.CHAR:
@@ -1505,6 +1839,7 @@ function SqlUtils() {}
 *                                   <br/> 1. the name of the table if also a pColumnName is specified 
 *                                   <br/> 2. the name of the table and columname as "tablename.columnname" (e.g. "ORGANISATION.NAME") if no pColumnName is specified
 *                                   <br/> 3. an array with 2 elements: [tablename, columnname] (e.g. ["ORGANISATION", "NAME"]) if no pColumnName is specified
+*                                   <br/> 4. an array with 3 elements: [tablename, columnname, tablealias] (e.g. ["ORGANISATION", "NAME", "org"]) if no pColumnName is specified
 *                                   <br/> Everything else will raise an error
 *                                   
 * @param {String} [pColumnName] depending on pFieldOrTableName this should be undefined/null or the name of a column
@@ -1512,13 +1847,22 @@ function SqlUtils() {}
 * @return {Object|TypeError} TypeError if something wrong has been passed or returns a object with these properties: 
 *                           1. "table" which is the tablename
 *                           2. "column" which is the columnname
-*                           e.g. {table: "ORGANISATION", column: "NAME"}
+*                           3. "tableAlias" which is the tableAlias if it exists. else it is also the table
+*                           e.g. {table: "ORGANISATION", column: "NAME", tableAlias: "org"}
 * 
 *
 */
 SqlUtils._parseFieldQualifier = function(pFieldOrTableName, pColumnName) 
 {
-    var tableName, columnName;
+    var fnName = "SqlUtils._parseFieldQualifier";//for return errors
+
+    if (typeof pFieldOrTableName == "string")
+    {
+        if (pFieldOrTableName.search(/[\s=\(\)<>!]/) != -1)
+            return new TypeError(translate.withArguments("[%0]%1 has to be a string without empty spaces, (, ), =, <, >  but it contains at least one of them", [fnName, "pFieldOrTableName"]));
+    }
+    
+    var tableName, columnName, tableAlias;
     if (pColumnName != undefined)
     {
         tableName = pFieldOrTableName;
@@ -1526,7 +1870,6 @@ SqlUtils._parseFieldQualifier = function(pFieldOrTableName, pColumnName)
     }
     else
     {
-        var fnName = "SqlUtils._parseFieldQualifier";//for return errors
         var fieldVarType = typeof(pFieldOrTableName);
         if (fieldVarType == "string") 
         {
@@ -1538,28 +1881,43 @@ SqlUtils._parseFieldQualifier = function(pFieldOrTableName, pColumnName)
                 fieldVarType]));
         }
 
-        if (pFieldOrTableName.hasOwnProperty("length")) 
+        if (Array.isArray(pFieldOrTableName)) 
         {
-            if (pFieldOrTableName.length != 2) 
-                return new TypeError(translate.withArguments("[%0]has now an incorrect length; estimated 2 elements but got %1", [
-                        fnName, pFieldOrTableName.length ]));
-
-            tableName = pFieldOrTableName[0];
-            columnName = pFieldOrTableName[1];
+            if (pFieldOrTableName.length == 3)
+            {
+                tableName = pFieldOrTableName[0];
+                columnName = pFieldOrTableName[1];
+                tableAlias = pFieldOrTableName[2];
+            }
+            else if (pFieldOrTableName.length == 2) 
+            {
+                tableName = pFieldOrTableName[0];
+                columnName = pFieldOrTableName[1];
+            }
+            else
+            {
+                return new TypeError(translate.withArguments("[%0]has now an incorrect length; estimated 2 or 3 elements but got %1", [fnName, pFieldOrTableName.length ]));
+            }            
         }
         else //check for object happens since there exists JavaArrays and JavaScript arrays which are both valid
             return  new TypeError(translate.withArguments("[%0]%1 is an object but seems not to be a valid array or array-like", [
                     fnName, "pFieldOrTableName"]));
     }
 
+    if (!tableAlias)
+        tableAlias = tableName;
+
     if (typeof(columnName) != "string")
         return  new TypeError(translate.withArguments("[%0]the columnName is not a string after interpreting", [fnName]));
     if (typeof(tableName) != "string")
         return  new TypeError(translate.withArguments("[%0]the tableName is not a string after interpreting", [fnName]));
+    if (typeof(tableAlias) != "string")
+        return  new TypeError(translate.withArguments("[%0]the tableAlias is not a string after interpreting", [fnName]));
 
     return {
         table: tableName,
-        column: columnName
+        column: columnName,
+        tableAlias: tableAlias
     };
 };
 
@@ -1571,6 +1929,7 @@ SqlUtils._parseFieldQualifier = function(pFieldOrTableName, pColumnName)
 *                                   <br/> 1. the name of the table if also a pColumnName is specified 
 *                                   <br/> 2. the name of the table and columname as "tablename.columnname" (e.g. "ORGANISATION.NAME") if no pColumnName is specified
 *                                   <br/> 3. an array with 2 elements: [tablename, columnname] (e.g. ["ORGANISATION", "NAME"]) if no pColumnName is specified
+*                                   <br/> 4. an array with 3 elements: [tablename, columnname, tablealias] (e.g. ["ORGANISATION", "NAME", "org"]) if no pColumnName is specified
 *                                   <br/> Everything else will raise an error
 *                                   
 * @param {String} [pColumnName] depending on pFieldOrTableName this should be undefined/null or the name of a column
@@ -1593,6 +1952,7 @@ SqlUtils.isFullFieldQualifier = function(pFieldOrTableName, pColumnName)
 *                                   <br/> 1. the name of the table if also a pColumnName is specified 
 *                                   <br/> 2. the name of the table and columname as "tablename.columnname" (e.g. "ORGANISATION.NAME") if no pColumnName is specified
 *                                   <br/> 3. an array with 2 elements: [tablename, columnname] (e.g. ["ORGANISATION", "NAME"]) if no pColumnName is specified
+*                                   <br/> 4. an array with 3 elements: [tablename, columnname, tablealias] (e.g. ["ORGANISATION", "NAME", "org"]) if no pColumnName is specified
 *                                   <br/> Everything else will raise an error
 *                                   
 * @param {String} [pColumnName] depending on pFieldOrTableName this should be undefined/null or the name of a column
@@ -1603,7 +1963,8 @@ SqlUtils.isFullFieldQualifier = function(pFieldOrTableName, pColumnName)
 * @return {Number} returns the corresponding SQLTYPES-value
 *
 */
-SqlUtils.getSingleColumnType = function(pFieldOrTableName, pColumnName, pAlias) {
+SqlUtils.getSingleColumnType = function(pFieldOrTableName, pColumnName, pAlias) 
+{
     var fields = SqlUtils._parseFieldQualifier(pFieldOrTableName, pColumnName);
     if (fields instanceof TypeError)
         throw fields;
@@ -1643,7 +2004,7 @@ SqlUtils.getSingleColumnType = function(pFieldOrTableName, pColumnName, pAlias)
 *
 * var allRows = +db.cell("select count(*) from ORGANISATION");
 *
-* sqlPageData(sql, blockSize, function (pData, pRunNo){
+* sqlPageData(sql, blockSize, function(pData, pRunNo){
 *     var j = pData.length;//pData is the current block with data
 *     logMsg(pRunNo.toString() + "#" + j);//pRunNo is the amount how often the func. has been already called
 *     //you can calculate the progress easily by: progress = (blockSize* (pRunNo-1) + pData.length) / (allRows - startOffset)
@@ -1665,7 +2026,8 @@ SqlUtils.getSingleColumnType = function(pFieldOrTableName, pColumnName, pAlias)
 * logging.show(letValues);//contains orgnames
 * logging.show(varValues);//contains orgnames
 */
-SqlUtils.pageTableData = function(sqlStatement, blockSize, callbackFn, dbAlias, timeout, startOffset) {
+SqlUtils.pageTableData = function(sqlStatement, blockSize, callbackFn, dbAlias, timeout, startOffset) 
+{
     return SqlUtils._pageData(null, sqlStatement, blockSize, callbackFn, dbAlias, timeout, startOffset);
 };
 
@@ -1691,27 +2053,32 @@ SqlUtils.pageTableData = function(sqlStatement, blockSize, callbackFn, dbAlias,
 * @example
 * similar to sqlTablePageData -> take a look at the example there
 */
-SqlUtils.pageColumnData = function(sqlStatement, blockSize, callbackFn, dbAlias, timeout, startOffset) {
+SqlUtils.pageColumnData = function(sqlStatement, blockSize, callbackFn, dbAlias, timeout, startOffset) 
+{
     return SqlUtils._pageData(db.COLUMN, sqlStatement, blockSize, callbackFn, dbAlias, timeout, startOffset);
 };
 
 //internal function for paging through data; for description take a look at sqlArrayPageData
-SqlUtils._pageData = function(sqlType ,sqlStatement, blockSize, callbackFn, dbAlias, timeout, startOffset) {
+SqlUtils._pageData = function(sqlType ,sqlStatement, blockSize, callbackFn, dbAlias, timeout, startOffset) 
+{
     if (dbAlias == undefined)
         dbAlias = db.getCurrentAlias();
     if (startOffset == undefined)
         startOffset = 0;
 
     var count = 0;
-    while (startOffset > -1) {
+    while (startOffset > -1) 
+    {
         var data;
-        if (sqlType == null) {
+        if (sqlType == null) 
+        {
             if (timeout == undefined)
                 data = db.tablePage(sqlStatement, dbAlias, startOffset, blockSize);
             else
                 data = db.tablePage(sqlStatement, dbAlias, startOffset, blockSize, timeout);
         }
-        else {
+        else 
+        {
             if (timeout == undefined)
                 data = db.arrayPage(sqlType, sqlStatement, dbAlias, startOffset, blockSize);
             else
@@ -1763,7 +2130,8 @@ SqlUtils.getSystemAlias = function()
      *
      * @return {String|Array} SQL condition: where VALS in (1,2,3) OR as prepared Statement if pAsPrepared is true ["VALS in (1,2,3)", [...]
      */
-SqlUtils.getSqlInStatement = function(pFieldname, pData, pQuoteSymbol, pAsPrepared, pPreparedDbType) {
+SqlUtils.getSqlInStatement = function(pFieldname, pData, pQuoteSymbol, pAsPrepared, pPreparedDbType) 
+{
     if (pData.length == 0)
         return " 1 = 2 ";
 
@@ -1775,9 +2143,7 @@ SqlUtils.getSqlInStatement = function(pFieldname, pData, pQuoteSymbol, pAsPrepar
     {
         preparedValues = [];
         if (!pPreparedDbType)
-        {
             throw new Error(translate.text("SqlUtils.getSqlInStatement: if pAsPrepared is true, pPreparedDbType has to be filld with the correct db type"));
-        }
     }
 
     var MAX_COUNT = 1000;
@@ -1792,7 +2158,7 @@ SqlUtils.getSqlInStatement = function(pFieldname, pData, pQuoteSymbol, pAsPrepar
         
         if (pAsPrepared) 
         {
-            res += pFieldname + " in (";
+            res += (pFieldname ? pFieldname + " in " : "") + "(";
             var subData = pData.slice(i * MAX_COUNT, i * MAX_COUNT + MAX_COUNT);
             
             subData.forEach(function(pVal, pIndex) {
@@ -1805,7 +2171,7 @@ SqlUtils.getSqlInStatement = function(pFieldname, pData, pQuoteSymbol, pAsPrepar
         }
         else
         {
-            res += pFieldname + " in (" + qs + pData.slice(i * MAX_COUNT, i * MAX_COUNT + MAX_COUNT)
+            res += (pFieldname ? pFieldname + " in " : "") + "(" + qs + pData.slice(i * MAX_COUNT, i * MAX_COUNT + MAX_COUNT)
                     .join(qs + ", " + qs) + qs + ") ";
         }
     }
@@ -1866,19 +2232,21 @@ SqlUtils.getResolvingCaseWhen = function(pKeyValueArray, pDbFieldName, pLocale)
  * @param {([String, String[]]) => String} pExecutionCallback A function which must return the final SQL.
  * @return The SQL, same as the result of db.translateStatement.
  */
-SqlUtils.translateWithQuotes = function (pStatement, pExecutionCallback) {
+SqlUtils.translateWithQuotes = function(pStatement, pExecutionCallback) 
+{
     // Validate type of incoming paramter.
-    if (!(pStatement instanceof Array))
+    if (!Array.isArray(pStatement))
         return null;
 
     // The second element of the array has to be an array.
-    if (!(pStatement[1] instanceof Array))
+    if (!Array.isArray(pStatement[1]))
         return null;
 
     // As the second element represents the prepared statements we need to map it...
-    var preparedStatements = pStatement[1].map(function (pValue) {
+    var preparedStatements = pStatement[1].map(function(pValue) 
+    {
         // Just in case as a fallback value..
-        if (!(pValue instanceof Array))
+        if (!(Array.isArray(pValue)))
             return pValue;
 
         // As the first element represents the value it will be quoted here.
@@ -1893,8 +2261,15 @@ SqlUtils.translateWithQuotes = function (pStatement, pExecutionCallback) {
  * @param {[String, String[]]} pStatement Same as the first parameter of db.translateStatement.
  * @returns {String} The SQL, same as the result of db.translateStatement.
  */
-SqlUtils.translateStatementWithQuotes = function (pStatement) {
-    return SqlUtils.translateWithQuotes(pStatement, function(pValue) {return db.translateStatement(pValue)});
+SqlUtils.translateStatementWithQuotes = function(pStatement, pAlias) 
+{
+    return SqlUtils.translateWithQuotes(pStatement, function(pValue) 
+    {
+        if (pAlias)
+            return db.translateStatement(pValue, pAlias)
+        else
+            return db.translateStatement(pValue)
+    });
 }
 
 /**
@@ -1902,6 +2277,72 @@ SqlUtils.translateStatementWithQuotes = function (pStatement) {
  * @param {[String, String[]]} pStatement Same as the first parameter of db.translateCondition.
  * @returns {String} The SQL, same as the result of db.translateCondition.
  */
-SqlUtils.translateConditionWithQuotes = function (pStatement) {
-    return SqlUtils.translateWithQuotes(pStatement, function(pValue) {return db.translateCondition(pValue)});
+SqlUtils.translateConditionWithQuotes = function(pStatement, pAlias) 
+{
+    return SqlUtils.translateWithQuotes(pStatement, function(pValue) 
+    {
+        if (pAlias)
+            return db.translateCondition(pValue, pAlias)
+        else
+            return db.translateCondition(pValue)
+    });
+}
+
+SqlUtils.parseField = function(pField)
+{
+    var alias = "";
+    if (typeof pField === 'string')
+    {
+        var pointPos = pField.indexOf(".");
+
+        if (pointPos > 0 && pointPos < pField.length-1)
+            alias = pField;
+        else
+            throw new Error(translate.withArguments("${SQL_LIB_FIELD_WRONG_FORMAT} field: %0", [pField]));
+    }
+    else
+    {
+        if (pField.length == 2)
+            pField.push(pField[0]);
+        
+        if (pField.length == 3)
+        {
+            alias = pField[2] + "." + pField[1];
+            pField = pField[0] + "." + pField[1];
+        }
+        else
+            throw new Error(translate.withArguments("${SQL_LIB_FIELD_WRONG_FORMAT} field: %0", [field.toSource()]));
+    }
+    return [alias, pField]
+}
+
+SqlUtils.replaceConditionTemplate = function(pCond, pPlaceholder, pReplacement) 
+{
+    //SqlUtils.replaceConditionTemplate(pCond, '#', SqlUtils.parseField(pFieldOrCond).join("."))
+    
+    //this function looks more complex (and slower) than it actually is
+    /* the following regex looks like this after javascript-escaping of the backslash: (?<!\\)((?:\\\\)*)#
+    the regexp searches for the unescaped character and these characters are replaced by the field name
+
+    examples:
+    ---------------------
+    | # --match         |
+    | \# --no-match     |
+    | \\# --match       |
+    | \\\# --no-match   |
+    | \\\\# --match     |
+    ---------------------
+    */
+    //use replaceAll because it's faster and supports negative lookbehinds
+    replacements = {};
+    //manually readd the replaced backslashes by using a group reference, because they a part of the match and therefore replaced by "replaceAll"
+    //since the field COULD contain already a group reference (I think this is extremely uncommon; 
+    //probably that never happens but better stay save): escape that references within the fieldname
+    replacements["(?<!\\\\)((?:\\\\\\\\)*)" + pPlaceholder] = "$1" + text.replaceAll(pReplacement, {
+        "$1": "\\$1"
+    })
+     //now that we've replaced the correct field placeholder let's replace the escaped placeholder sign "\#" to a normal placeholder sign "#"
+    replacements["\\\\" + pPlaceholder] = pPlaceholder
+    
+    return text.replaceAll(pCond, replacements);
 }
\ No newline at end of file
diff --git a/process/Ticket_lib/process.js b/process/Ticket_lib/process.js
index 489382722ae4ddbef7c253c161e6e08d31e56af7..38b8f4d08157393021ef3448c9b8c5f83f50ac20 100644
--- a/process/Ticket_lib/process.js
+++ b/process/Ticket_lib/process.js
@@ -76,10 +76,14 @@ TicketUtils.prototype.hasTickets = function(pRowId, pObjectType)
 {
     if (pRowId != "" && pObjectType != "")
     {
-        var cond = SqlCondition.begin().andPrepare("TASKLINK.OBJECT_TYPE", pObjectType)
-                                       .andPrepare("TASKLINK.OBJECT_ROWID", pRowId)
-                                       .andPrepareVars("TICKET.TICKETTYPE", this.type);
-        var taskCount = db.cell(cond.buildSql("select count(*) from TASKLINK join TICKET on TICKET.TASK_ID = TASKLINK.TASK_ID"));
+        var taskCount = newSelect("count(*)")
+                            .from("TASKLINK")
+                            .join("TICKET", "TICKET.TASK_ID = TASKLINK.TASK_ID")
+                            .where("TASKLINK.OBJECT_TYPE", pObjectType)
+                            .and("TASKLINK.OBJECT_ROWID", pRowId)
+                            .andIfSet("TICKET.TICKETTYPE", this.type)
+                            .cell(true, "0");
+
         if (taskCount != "0")
             return true;
         else 
diff --git a/process/Timetracking_lib/process.js b/process/Timetracking_lib/process.js
index 0a6ef6264e03313ebc8d2c4d0533ab9ae04fdb81..515d922a39f50ec7da63cf26ca307ed2df3d34ad 100644
--- a/process/Timetracking_lib/process.js
+++ b/process/Timetracking_lib/process.js
@@ -21,10 +21,11 @@ function Timetracking() {}
 Timetracking.getTotalTrackingTime = function (pRowId)
 {
     var objectId = ContextUtils.getCurrentContextId();
-    var totalMinutes = db.cell(SqlCondition.begin()
-        .andPrepare("TIMETRACKING.OBJECT_ID", objectId)
-        .andPrepare("TIMETRACKING.ROW_ID", pRowId)
-        .buildSql("select sum(TRACKINGMINUTES) from TIMETRACKING", "1=0"));
+    var totalMinutes = newSelect("sum(TRACKINGMINUTES)")
+                            .from("TIMETRACKING")
+                            .where("TIMETRACKING.OBJECT_ID", objectId)
+                            .and("TIMETRACKING.ROW_ID", pRowId)
+                            .cell();
     
     return Number(totalMinutes);
 }
diff --git a/process/Turnover_lib/process.js b/process/Turnover_lib/process.js
index a38c64f62c4960defc71568d15d0b72373491380..14080be4ee9b533ea4a1c88331e3d6f45f64f364 100644
--- a/process/Turnover_lib/process.js
+++ b/process/Turnover_lib/process.js
@@ -31,20 +31,19 @@ TurnoverUtil.getTurnoverData = function (pMaxYear, pYearCount, pSalesprojectId)
     var minYear = pMaxYear - pYearCount + 1;
         
     // load data
-    var data = db.table(SqlCondition.begin()
-                                    .and("SALESORDER.ORDERTYPE = 'ORDTYPEINVO'")
-                                    .and("SALESORDER.ORDERSTATUS = 1")
-                                    .and("SALESORDER.CANCELLATION <> 1")
-                                    .and("SALESORDERITEM.OPTIONAL <> 1")
-                                    .andPrepare("SALESORDER.SALESORDERDATE", pMaxYear, "year(#) <= ?", SQLTYPES.INTEGER)
-                                    .andPrepare("SALESORDER.SALESORDERDATE", minYear, "year(#) >= ?", SQLTYPES.INTEGER)
-                                    .andPrepareIfSet("SALESORDER.SALESPROJECT_ID", pSalesprojectId)
-                                    .buildSql("select '" + turnoverCategory + "', year(SALESORDERDATE) yearNum, month(SALESORDERDATE) monthNum, SALESORDERITEM.DISCOUNT discount, SALESORDERITEM.VAT vat, SALESORDERITEM.PRICE price, sum(SALESORDERITEM.QUANTITY) quantity, SALESORDERITEM.GROUPCODEID prodGroup, (" + KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.productGroupcode(), "SALESORDERITEM.GROUPCODEID") + ") prodGroupName \n\
-                                                from SALESORDER  \n\
-                                                join SALESORDERITEM on SALESORDERITEM.SALESORDER_ID = SALESORDER.SALESORDERID", "1=2", "group by year(SALESORDERDATE), month(SALESORDERDATE), SALESORDERITEM.GROUPCODEID, SALESORDERITEM.DISCOUNT, SALESORDERITEM.VAT, SALESORDERITEM.PRICE \n\
-                                                order by yearNum, monthNum "));
-    
-    return data;
+    return newSelect("'" + turnoverCategory + "', year(SALESORDERDATE) yearNum, month(SALESORDERDATE) monthNum, SALESORDERITEM.DISCOUNT discount, SALESORDERITEM.VAT vat, SALESORDERITEM.PRICE price, sum(SALESORDERITEM.QUANTITY) quantity, SALESORDERITEM.GROUPCODEID prodGroup, (" + KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.productGroupcode(), "SALESORDERITEM.GROUPCODEID") + ") prodGroupName")
+                    .from("SALESORDER")
+                    .join("SALESORDERITEM", "SALESORDERITEM.SALESORDER_ID = SALESORDER.SALESORDERID")
+                    .where("SALESORDER.ORDERTYPE = 'ORDTYPEINVO'")
+                    .and("SALESORDER.ORDERSTATUS = 1")
+                    .and("SALESORDER.CANCELLATION <> 1")
+                    .and("SALESORDERITEM.OPTIONAL <> 1")
+                    .and("SALESORDER.SALESORDERDATE", pMaxYear, "year(#) <= ?", SQLTYPES.INTEGER)
+                    .and("SALESORDER.SALESORDERDATE", minYear, "year(#) >= ?", SQLTYPES.INTEGER)
+                    .andIfSet("SALESORDER.SALESPROJECT_ID", pSalesprojectId)
+                    .groupBy("year(SALESORDERDATE), month(SALESORDERDATE), SALESORDERITEM.GROUPCODEID, SALESORDERITEM.DISCOUNT, SALESORDERITEM.VAT, SALESORDERITEM.PRICE")
+                    .orderBy("yearNum, monthNum")
+                    .table();
 }
 
 /**
@@ -63,16 +62,20 @@ TurnoverUtil.getForecastData = function (pMaxYear, pYearCount, pSalesprojectId)
     var minYear = pMaxYear - pYearCount + 1;
 
     // load data
-    var cond = SqlCondition.begin()
-                .andPrepare("FORECAST.DATE_START", pMaxYear, "year(#) <= ?", SQLTYPES.INTEGER)
-                .andPrepare("FORECAST.DATE_START", minYear, "year(#) >= ?", SQLTYPES.INTEGER)
+    var forecastSelect = newSelect("'" + forecastCategory + "', year(DATE_START) yearNum, month(DATE_START) monthNum, 0 discount, 0 vat, sum(VOLUME) price, 1 quantity, GROUPCODE prodGroup, (" + KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.productGroupcode(), "GROUPCODE") + ") prodGroupName")
+                            .from("FORECAST")
+                            .where("FORECAST.DATE_START", pMaxYear, "year(#) <= ?", SQLTYPES.INTEGER)
+                            .and("FORECAST.DATE_START", minYear, "year(#) >= ?", SQLTYPES.INTEGER)
     if (pSalesprojectId)
     {
-        cond.andPrepare("FORECAST.OBJECT_TYPE", 'Salesproject')
-        cond.andPrepare("FORECAST.OBJECT_ROWID", pSalesprojectId)
+        forecastSelect.and("FORECAST.OBJECT_TYPE", 'Salesproject')
+                      .and("FORECAST.OBJECT_ROWID", pSalesprojectId)
     }   
-                                        
-    return db.table(cond.buildSql("select '" + forecastCategory + "', year(DATE_START) yearNum, month(DATE_START) monthNum, 0 discount, 0 vat, sum(VOLUME) price, 1 quantity, GROUPCODE prodGroup, (" + KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.productGroupcode(), "GROUPCODE") + ") prodGroupName from FORECAST", "1=2", " group by year(DATE_START), month(DATE_START), GROUPCODE order by yearNum, monthNum"));
+    
+    forecastSelect.groupBy("year(DATE_START), month(DATE_START), GROUPCODE")
+                  .orderBy("yearNum, monthNum");
+                  
+    return forecastSelect.table();
 }
 
 /**
diff --git a/process/UnitTest_lib/UnitTest_lib.aod b/process/UnitTest_lib/UnitTest_lib.aod
new file mode 100644
index 0000000000000000000000000000000000000000..7e4e53c003a18b1526abd9381f3a4e5f4026ed90
--- /dev/null
+++ b/process/UnitTest_lib/UnitTest_lib.aod
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<process xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.2.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/process/1.2.1">
+  <name>UnitTest_lib</name>
+  <majorModelMode>DISTRIBUTED</majorModelMode>
+  <process>%aditoprj%/process/UnitTest_lib/process.js</process>
+  <variants>
+    <element>LIBRARY</element>
+  </variants>
+</process>
diff --git a/process/UnitTest_lib/process.js b/process/UnitTest_lib/process.js
new file mode 100644
index 0000000000000000000000000000000000000000..160855b0c280e8e1aa82373c56a0213ae2907323
--- /dev/null
+++ b/process/UnitTest_lib/process.js
@@ -0,0 +1,139 @@
+import("system.logging");
+
+function TestSuite(pTests, pPreAll, pPreTest, pPostTest, pPostAll)
+{
+    this.tests = pTests;
+    this.preAll = (pPreAll ? pPreAll : function() {});
+    this.preTest = (pPreTest ? pPreTest : function() {});
+    this.postTest = (pPostTest ? pPostTest : function() {});
+    this.postAll = (pPostAll ? pPostAll : function() {});
+}
+
+function Tester(pCollectionName) 
+{
+    this.collectionName = pCollectionName;
+    this.testResults = [];
+    
+    // if no assert was called during a test, no test-message would be added. -> Add a success message that no error occoured.
+    this.currentTestHadAlreadyAssert = false;
+}
+
+Tester.prototype.assert = function (pExpect, pActual, pTestDescription)
+{
+    this.currentTestHadAlreadyAssert = true;
+    
+    var res = pActual === pExpect;
+    
+    this.testResults.push([
+        this._currentTest,
+        pTestDescription,
+        res,
+        pExpect,
+        pActual
+    ]);
+}
+
+Tester.prototype.test = function (pTestSuite)
+{
+    pTestSuite.preAll(this);
+    
+    pTestSuite.tests.forEach(function(pTest) {
+        logging.log("Testing " + pTest[0]);
+        
+        this.currentTestHadAlreadyAssert = false;
+
+        this._currentTest = pTest[0];
+        pTestSuite.preTest(this);
+        
+        if (pTest.length >= 3)
+        {
+            var errorThrowed = false;
+            
+            try {
+                pTest[1](this);
+            } catch (ex) {
+                errorThrowed = true;
+                
+                if (ex.toSource() == pTest[2].toSource())
+                {
+                    this.testResults.push([
+                        this._currentTest,
+                        "Expected error throwed",
+                        true,
+                        pTest[2].toSource(),
+                        ex.toSource()
+                    ]);
+
+                    // don't throw as it's expected and no detailed stacktrace is needed
+                }
+                else
+                {
+                    this.testResults.push([
+                        this._currentTest,
+                        "Expected error throwed",
+                        false,
+                        pTest[2].toSource(),
+                        ex.toSource()
+                    ]);
+                    
+                    logging.log("Expected error: " + pTest[2].toSource() + ", but wrong error occoured.\nRunning test again without try catch to get detailed error stack trace")
+                    
+                    pTestSuite.preTest(this);
+                    pTest[1](this);
+                    pTestSuite.postTest(this);
+                    return;
+                }
+            }
+            
+            if (!errorThrowed)
+            {
+                // if it didn't fail
+                this.testResults.push([
+                    this._currentTest,
+                    "Expected error throwed",
+                    false,
+                    pTest[2].toSource(),
+                    "no error"
+                ]);
+            }
+        }
+        else
+        {
+            // run without try catch as no error expected
+            pTest[1](this);
+        }
+        
+        if (!this.currentTestHadAlreadyAssert && pTest.length < 3) // only add message if no error expected
+        {
+            this.testResults.push([
+                    this._currentTest,
+                    "Expected no error",
+                    true,
+                    "no error",
+                    "no error"
+                ]);
+        }
+            
+        pTestSuite.postTest(this);
+    }, this);
+    
+    pTestSuite.postAll(this);
+}
+
+Tester.prototype.printResults = function ()
+{
+    var lastTestDescription = "";
+    logging.log("Test results for \"" + this.collectionName + "\"")
+    this.testResults.forEach(function(pResult) {
+        
+        if (lastTestDescription != pResult[0])
+        {
+            logging.log("Test \"" + pResult[0] + "\":");
+        }
+        
+        var message = (pResult[1] ? " - " + pResult[1] : " - Test result ") + ": " + (pResult[2] ? "success" : "fail\nexpected: " + JSON.stringify(pResult[3], null, "\t") + "\nactual: " + JSON.stringify(pResult[4], null, "\t"));
+        
+        logging.log(message);
+        lastTestDescription = pResult[0];
+    }, this);
+}
\ No newline at end of file
diff --git a/process/Util_lib/process.js b/process/Util_lib/process.js
index 250a95ee13ddaee794ae0aee7592e8c6a8bbff6e..68579728967175ded3f2a3d604a396cbcf416761 100644
--- a/process/Util_lib/process.js
+++ b/process/Util_lib/process.js
@@ -607,9 +607,10 @@ function ConsecutiveCodeUtils () {}
  */
 ConsecutiveCodeUtils.setCode = function(pId, pTable, pIdCol, pCodeCol)
 {
-    var max = db.cell("select max(" + pCodeCol + ") from " + pTable);
+    var max = newSelect("max(" + pCodeCol + ")").from(pTable).cell();
     if (!max)
         max = -1;
     
-    db.updateData(pTable, [pCodeCol], null, [parseInt(max)+1], SqlCondition.equals(pTable + "." + pIdCol, pId, "1=2"));
+    newWhereIfSet(pTable + "." + pIdCol, pId)
+        .updateData(true, [pCodeCol], null, [parseInt(max)+1], pTable);
 }
\ No newline at end of file
diff --git a/process/buildSerialLetter_serverProcess/process.js b/process/buildSerialLetter_serverProcess/process.js
index 9b34df62172d03ad3627fef3f0554941815a4921..020a33e42494ce416a69b813610e1762b19d9e8e 100644
--- a/process/buildSerialLetter_serverProcess/process.js
+++ b/process/buildSerialLetter_serverProcess/process.js
@@ -11,19 +11,22 @@ import("DocumentTemplate_lib");
 var letterId = vars.get("$local.serialLetterId");
 var recipientIds = JSON.parse(vars.get("$local.recipientIds"));
 
-var templateId = db.cell(SqlCondition.begin()
-    .andPrepare("SERIALLETTER.SERIALLETTERID", letterId)
-    .buildSql("select DOCUMENTTEMPLATE_ID from SERIALLETTER", "1=2"));
+var templateId = newSelect("DOCUMENTTEMPLATE_ID")
+                    .from("SERIALLETTER")
+                    .where("SERIALLETTER.SERIALLETTERID", letterId)
+                    .cell(true);
 
 var template = SerialLetterUtils.getSerialLetterTemplate(letterId, templateId);
-var condition = SqlCondition.begin()
-    .andPrepare("LETTERRECIPIENT.SERIALLETTER_ID", letterId)
-    .andSqlCondition(ContactUtils.getCommRestrictionCondition($KeywordRegistry.communicationMediumCampaign$letter(), true));
+var contactIdsSelect = newSelect("CONTACT_ID")
+                    .from("LETTERRECIPIENT")
+                    .join("CONTACT", newWhere("LETTERRECIPIENT.CONTACT_ID = CONTACT.CONTACTID"))
+                    .where("LETTERRECIPIENT.SERIALLETTER_ID", letterId)
+                    .andIfSet(ContactUtils.getCommRestrictionCondition($KeywordRegistry.communicationMediumCampaign$letter(), true));
     
 if (recipientIds && recipientIds.length > 0)
-    condition.andIn("LETTERRECIPIENT.LETTERRECIPIENTID", recipientIds);
+    contactIdsSelect.and("LETTERRECIPIENT.LETTERRECIPIENTID", recipientIds, SqlBuilder.IN());
     
-var contactIds = db.table(condition.buildSql("select CONTACT_ID from LETTERRECIPIENT join CONTACT on LETTERRECIPIENT.CONTACT_ID = CONTACT.CONTACTID", "1=2"));
+var contactIds = contactIdsSelect.table();
 var document = template.getSerialLetterByContactIds(contactIds);
  
 if (document)
diff --git a/process/ctiServerEvents/process.js b/process/ctiServerEvents/process.js
index 0375f23402be095c7856026594d7ed536cb87f36..1bde4b2f4197d078a6ecf844e494c815110a9da8 100644
--- a/process/ctiServerEvents/process.js
+++ b/process/ctiServerEvents/process.js
@@ -74,15 +74,20 @@ var talkingHandlerFn = function()
 {
     var cols = ["DATE_EDIT", "ANSWERMODE"];
     var vals = [datetime.date(), $KeywordRegistry.callAnswerMode$accepted()];
-    db.updateData("AB_CTILOG", cols, null, vals, SqlCondition.begin().andPrepare("AB_CTILOG.CALLID", this.callData.callId).build());
-//do not notify here since the user _should_ know when he accepts a call
+    
+    newWhereIfSet("AB_CTILOG.CALLID", this.callData.callId)
+        .updateData(true, cols, null, vals, "AB_CTILOG");
+        
+    //do not notify here since the user _should_ know when he accepts a call
 };
     
 var disconnectingHandlerFn = function()
 {
     var callEndTime = datetime.date();
-    var sqlCond = SqlCondition.begin().andPrepare("AB_CTILOG.CALLID", this.callData.callId);
-    var lastCallData = db.array(db.ROW, sqlCond.buildSql("select AB_CTILOG.ANSWERMODE, AB_CTILOG.DATE_NEW from AB_CTILOG"));
+    var lastCallData = newSelect("AB_CTILOG.ANSWERMODE, AB_CTILOG.DATE_NEW")
+                        .from("AB_CTILOG")
+                        .whereIfSet("AB_CTILOG.CALLID", this.callData.callId)
+                        .arrayRow(true);
     if (lastCallData.length == 0)
         return null;
 
diff --git a/process/emailWrite/process.js b/process/emailWrite/process.js
index d69b5720af1f95d2c213a0ae7c42b94dacc1680b..f8848c3cad7b67eeea40d6a24160698384424eda 100644
--- a/process/emailWrite/process.js
+++ b/process/emailWrite/process.js
@@ -13,10 +13,10 @@ var uid = vars.get("$local.uid");
 
 if (entity == "Communication_entity")
 {
-    var contactSql = SqlCondition.begin()
-                                 .andPrepare("COMMUNICATION.COMMUNICATIONID", uid)
-                                 .buildSql("select COMMUNICATION.CONTACT_ID from COMMUNICATION");
-    var contactId = db.cell(contactSql)
+    var contactId = newSelect("COMMUNICATION.CONTACT_ID")
+                            .from("COMMUNICATION")
+                            .where("COMMUNICATION.COMMUNICATIONID", uid)
+                            .cell();
     EmailWritingUtils.openNewMail(contactId, address);
 }
 else
diff --git a/process/mailbridge/mailbridge.aod b/process/mailbridge/mailbridge.aod
index 3ba8b0af554cc587cf3e18db05978fbb26ea8d55..254ff35492e5ce5eccb03b1d7a55c4ced626e8a1 100644
--- a/process/mailbridge/mailbridge.aod
+++ b/process/mailbridge/mailbridge.aod
@@ -5,4 +5,7 @@
   <documentation>%aditoprj%/process/mailbridge/documentation.adoc</documentation>
   <process>%aditoprj%/process/mailbridge/process.js</process>
   <alias>Data_alias</alias>
+  <variants>
+    <element>EXECUTABLE</element>
+  </variants>
 </process>
diff --git a/process/sendBulkMail_serverProcess/process.js b/process/sendBulkMail_serverProcess/process.js
index 6a68f3deaaa3dc0b3ef04025b4d395920228145f..711120feb205e4b00a1fbda8afdea68708681fca 100644
--- a/process/sendBulkMail_serverProcess/process.js
+++ b/process/sendBulkMail_serverProcess/process.js
@@ -15,10 +15,11 @@ var res = BulkMailUtils.sendBulkMail(bulkMailId, testRecipients);
 
 if (user && !testRecipients)
 {
-    var mailName = db.cell(SqlCondition.begin()
-        .andPrepare("BULKMAIL.BULKMAILID", bulkMailId)
-        .buildSql("select NAME from BULKMAIL")
-    );
+    var mailName = newSelect("NAME")
+                        .from("BULKMAIL")
+                        .whereIfSet("BULKMAIL.BULKMAILID", bulkMailId)
+                        .cell(true);
+                        
     var message = translate.withArguments("Bulk mail \"%0\" was sent!", [mailName]);
     var description = translate.withArguments("%0 mails sent sucessfully, %1 mails failed. Process took %2 s.", 
         [res.sucessful, res.failed, Math.round((datetime.date() - startTime) / datetime.ONE_SECOND)]);