{"id":849,"date":"2011-03-25T02:30:03","date_gmt":"2011-03-25T07:30:03","guid":{"rendered":"http:\/\/www.dpriver.com\/blog\/?page_id=849"},"modified":"2012-01-29T02:44:13","modified_gmt":"2012-01-29T07:44:13","slug":"add-remove-and-modify-condition-in-where-clause-net-version","status":"publish","type":"page","link":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/add-remove-and-modify-condition-in-where-clause-net-version\/","title":{"rendered":"Add, remove and modify condition in where clause(.NET version)"},"content":{"rendered":"<p>This article shows how to use General SQL Parser to add, remove and modify condition in where clause, this feature enables your .NET(C#, VB.NET) application manipulate expression in where clause dynamically and create your own filter to fetch desired data set from database. <\/p>\n<h4><strong>Add a condition<\/strong><\/h4>\n<pre>\r\nSELECT clientid,\r\n       phone\r\nFROM   client\r\nWHERE  clientid IN ( 1, 2, 3)\r\n<\/pre>\n<p>After executing this C# code, we can add a new condition &#8220;ClientID > 2&#8221; to where clause.<\/p>\n<pre>\r\nTSelectSqlStatement select = (TSelectSqlStatement)sqlparser.SqlStatements[0];\r\nwhereCondition w = new whereCondition(select.WhereClause);\r\nw.add(conditionType.and, \"ClientID > 2\");\r\n<\/pre>\n<p>Now, the SQL become this, easy and clean:<\/p>\n<pre>\r\nSELECT clientid,\r\n       phone\r\nFROM   client\r\nWHERE  clientid IN ( 1, 2, 3) AND ClientID > 2\r\n<\/pre>\n<h4><strong>Remove a condition<\/strong><\/h4>\n<pre>\r\nSELECT clientid,\r\n       phone\r\nFROM   client\r\nWHERE  clientid IN ( 1, 2, 3) AND ClientID > 2\r\n<\/pre>\n<p>After executing this C# code, we can remove condition &#8220;ClientID > 2&#8221; from the where clause.<\/p>\n<pre>\r\nTSelectSqlStatement select = (TSelectSqlStatement)sqlparser.SqlStatements[0];\r\nwhereCondition w = new whereCondition(select.WhereClause);\r\nw.remove(\"ClientID > 2\");\r\n<\/pre>\n<p>Now, the SQL becomes this, easy and clean:<\/p>\n<pre>\r\nSELECT clientid,\r\n       phone\r\nFROM   client\r\nWHERE  clientid IN ( 1, 2, 3)\r\n<\/pre>\n<h4><strong>Replace\/modify a condition<\/strong><\/h4>\n<pre>\r\nSELECT clientid,\r\n       phone\r\nFROM   client\r\nWHERE  clientid IN ( 1, 2, 3) AND ClientID > 2\r\n<\/pre>\n<p>After executing this C# code, we can replace condition &#8220;ClientID > 2&#8221; with &#8220;ClientID > 3&#8221; in the where clause.<\/p>\n<pre>\r\nTSelectSqlStatement select = (TSelectSqlStatement)sqlparser.SqlStatements[0];\r\nwhereCondition w = new whereCondition(select.WhereClause);\r\nw.replace(\"ClientID > 2\", \"ClientID > 3\");\r\n<\/pre>\n<p>Now, the SQL becomes this, easy and clean:<\/p>\n<pre>\r\nSELECT clientid,\r\n       phone\r\nFROM   client\r\nWHERE  clientid IN ( 1, 2, 3) AND ClientID > 3\r\n<\/pre>\n<p>expressions in where clause was organized as a binary tree structure, and can be <a href=\"http:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/sql-expression-parse-tree-traversal-in-preorderinorderpostorder\/\">visited in preorder\/inorder\/postorder<\/a>. you can anything you like by iterate this expression binary tree.<\/p>\n<p>Here is another article <a href=\"http:\/\/www.sqlparser.com\/docs\/How_to_use_expression.html\">had a detailed explanation about the expression structure<\/a>.<\/p>\n<p>Download this demo: <a href=\"http:\/\/www.dpriver.com\/gsp\/demos\/csharp\/modifyexpression\/modifyexpression.zip\">C# version<\/a>, <a href=\"http:\/\/www.dpriver.com\/gsp\/demos\/java\/removeCondition\/removeCondition.zip\">Java version<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article shows how to use General SQL Parser to add, remove and modify condition in where clause, this feature enables your .NET(C#, VB.NET) application manipulate expression in where clause dynamically and create your own filter to fetch desired data set from database. Add a condition SELECT clientid, phone FROM client WHERE clientid IN ( 1, 2, 3) After executing this C# code, we can add a new condition &#8220;ClientID > 2&#8221; to where clause. TSelectSqlStatement select = (TSelectSqlStatement)sqlparser.SqlStatements[0]; whereCondition w = new whereCondition(select.WhereClause); w.add(conditionType.and, &#8220;ClientID > 2&#8221;); Now, the SQL become this, easy and clean: SELECT clientid, phone FROM\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":235,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"gsp_feature_page_tt.php","meta":[],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":5}},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Help you to make better use of General SQL Parser<\/title>\n<meta name=\"description\" content=\"Add, remove and modify condition in where clause(.NET version)\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/add-remove-and-modify-condition-in-where-clause-net-version\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Help you to make better use of General SQL Parser\" \/>\n<meta property=\"og:description\" content=\"Add, remove and modify condition in where clause(.NET version)\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/add-remove-and-modify-condition-in-where-clause-net-version\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL and Data Blog\" \/>\n<meta property=\"article:modified_time\" content=\"2012-01-29T07:44:13+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.dpriver.com\/blog\/#organization\",\"name\":\"SQL and Data Blog\",\"url\":\"https:\/\/www.dpriver.com\/blog\/\",\"sameAs\":[],\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.dpriver.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.dpriver.com\/blog\/wp-content\/uploads\/2022\/07\/sqlpp-character.png\",\"contentUrl\":\"https:\/\/www.dpriver.com\/blog\/wp-content\/uploads\/2022\/07\/sqlpp-character.png\",\"width\":251,\"height\":72,\"caption\":\"SQL and Data Blog\"},\"image\":{\"@id\":\"https:\/\/www.dpriver.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dpriver.com\/blog\/#website\",\"url\":\"https:\/\/www.dpriver.com\/blog\/\",\"name\":\"SQL and Data Blog\",\"description\":\"SQL related blog for database professional\",\"publisher\":{\"@id\":\"https:\/\/www.dpriver.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dpriver.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/add-remove-and-modify-condition-in-where-clause-net-version\/\",\"url\":\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/add-remove-and-modify-condition-in-where-clause-net-version\/\",\"name\":\"Help you to make better use of General SQL Parser\",\"isPartOf\":{\"@id\":\"https:\/\/www.dpriver.com\/blog\/#website\"},\"datePublished\":\"2011-03-25T07:30:03+00:00\",\"dateModified\":\"2012-01-29T07:44:13+00:00\",\"description\":\"Add, remove and modify condition in where clause(.NET version)\",\"breadcrumb\":{\"@id\":\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/add-remove-and-modify-condition-in-where-clause-net-version\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/add-remove-and-modify-condition-in-where-clause-net-version\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/add-remove-and-modify-condition-in-where-clause-net-version\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.dpriver.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"List of demos illustrate how to use general sql parser\",\"item\":\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Add, remove and modify condition in where clause(.NET version)\"}]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Help you to make better use of General SQL Parser","description":"Add, remove and modify condition in where clause(.NET version)","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/add-remove-and-modify-condition-in-where-clause-net-version\/","og_locale":"en_US","og_type":"article","og_title":"Help you to make better use of General SQL Parser","og_description":"Add, remove and modify condition in where clause(.NET version)","og_url":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/add-remove-and-modify-condition-in-where-clause-net-version\/","og_site_name":"SQL and Data Blog","article_modified_time":"2012-01-29T07:44:13+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Organization","@id":"https:\/\/www.dpriver.com\/blog\/#organization","name":"SQL and Data Blog","url":"https:\/\/www.dpriver.com\/blog\/","sameAs":[],"logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dpriver.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.dpriver.com\/blog\/wp-content\/uploads\/2022\/07\/sqlpp-character.png","contentUrl":"https:\/\/www.dpriver.com\/blog\/wp-content\/uploads\/2022\/07\/sqlpp-character.png","width":251,"height":72,"caption":"SQL and Data Blog"},"image":{"@id":"https:\/\/www.dpriver.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"WebSite","@id":"https:\/\/www.dpriver.com\/blog\/#website","url":"https:\/\/www.dpriver.com\/blog\/","name":"SQL and Data Blog","description":"SQL related blog for database professional","publisher":{"@id":"https:\/\/www.dpriver.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dpriver.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/add-remove-and-modify-condition-in-where-clause-net-version\/","url":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/add-remove-and-modify-condition-in-where-clause-net-version\/","name":"Help you to make better use of General SQL Parser","isPartOf":{"@id":"https:\/\/www.dpriver.com\/blog\/#website"},"datePublished":"2011-03-25T07:30:03+00:00","dateModified":"2012-01-29T07:44:13+00:00","description":"Add, remove and modify condition in where clause(.NET version)","breadcrumb":{"@id":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/add-remove-and-modify-condition-in-where-clause-net-version\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/add-remove-and-modify-condition-in-where-clause-net-version\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/add-remove-and-modify-condition-in-where-clause-net-version\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.dpriver.com\/blog\/"},{"@type":"ListItem","position":2,"name":"List of demos illustrate how to use general sql parser","item":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/"},{"@type":"ListItem","position":3,"name":"Add, remove and modify condition in where clause(.NET version)"}]}]}},"_links":{"self":[{"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/pages\/849"}],"collection":[{"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/comments?post=849"}],"version-history":[{"count":17,"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/pages\/849\/revisions"}],"predecessor-version":[{"id":1323,"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/pages\/849\/revisions\/1323"}],"up":[{"embeddable":true,"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/pages\/235"}],"wp:attachment":[{"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/media?parent=849"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}