{"id":333,"date":"2010-07-21T04:24:39","date_gmt":"2010-07-21T09:24:39","guid":{"rendered":"http:\/\/www.dpriver.com\/blog\/?page_id=333"},"modified":"2012-01-29T02:37:46","modified_gmt":"2012-01-29T07:37:46","slug":"remove-sql-variables-in-where-clause-without-broken-condition-expression","status":"publish","type":"page","link":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/remove-sql-variables-in-where-clause-without-broken-condition-expression\/","title":{"rendered":"Remove SQL\/user defined variables in where clause without broken condition expression"},"content":{"rendered":"<p>Sometimes you want to modify condition expression in where clause, such as remove a SQL variable in where condition without broken that condition expression or remove all where clause if necessary.<\/p>\n<p>Take this SQL for example, you want to remove @var1 in where condition, only delete it from where clause doesn&#8217;t work, that will make this statement syntax invalid.<\/p>\n<pre>\r\nselect f from tb\r\nwhere f1 between 1 and @var1\r\n<\/pre>\n<p>Illegal statement after remove @var1<\/p>\n<pre>\r\nselect f from tb\r\nwhere f1 between 1 and \r\n<\/pre>\n<p>Desired statement after remove @var1, should remove all where clause.<\/p>\n<pre>\r\nselect f from tb\r\n<\/pre>\n<p>\nHere is another sample, if you want to remove @var2 in where condition, only delete it from where clause doesn&#8217;t work, that will make this statement syntax invalid.\n<\/p>\n<pre>\r\nselect f from tb\r\nwhere f1>10 and (@var1+1 between a and @var2)\r\n<\/pre>\n<p>Illegal statement after remove @var1<\/p>\n<pre>\r\nselect f from tb\r\nwhere f1>10 and (@var1+1 between a and )\r\n<\/pre>\n<p>Desired statement after remove @var2<\/p>\n<pre>\r\nselect f from tb\r\nwhere f1>10\r\n<\/pre>\n<p>\nDownload this demo: <a href=\"http:\/\/www.dpriver.com\/gsp\/demos\/csharp\/removevars\/removevars.cs\">C# version<\/a>, <a href=\"http:\/\/www.dpriver.com\/gsp\/demos\/java\/removeCondition\/removeCondition.zip\">Java version<\/a>\n<\/p>\n<h4><strong>update or remove a user defined variable<\/strong><\/h4>\n<p>Take this sql for example:<\/p>\n<pre>\r\nSELECT SUM (d.amt) \r\nFROM   summit.cntrb_detail d \r\nWHERE  d.id = summit.mstr.id \r\n       AND d.system_gift_type IN ( 'OG', 'PLP', 'PGP' ) \r\n       AND d.fund_coll_attrb IN ( '$Institute$' ) \r\n       AND d.fund_acct IN ( '$Fund$' ) \r\n       AND d.cntrb_date >= '$From_Date$' \r\n       AND d.cntrb_date <= '$Thru_Date$' \r\nGROUP  BY d.id \r\n<\/pre>\n<p>\nIn this query, values between two $ e.g '$XXX$' represents some run time fields which user enter. For example '$Fund$' will be replaced with some user entered vale as '0000001'. <\/p>\n<p>Now our requirement is that we need to remove complete join in case user has not entered value specific to  $XXX$ run time field.<\/p>\n<p>Consider example as if user has not entered  '$Fund$' value the we should remove complete join  \"and d.FUND_ACCT in    (   '$Fund$'    )  \" from this query.<\/p>\n<p>General SQL Parser can help you to achieve this quite easily with <a href=\"http:\/\/www.dpriver.com\/gsp\/demos\/java\/removeCondition\/removeCondition.zip\">this demo<\/a>. And even better, this demo can remove \"Where\" clause if and only if single run time condition is presented and user has not provided any input for it.\n<\/p>\n<p>\nDownload this demo: <a href=\"http:\/\/www.dpriver.com\/gsp\/demos\/csharp\/removevars\/removevars.cs\">C# version<\/a>, <a href=\"http:\/\/www.dpriver.com\/gsp\/demos\/java\/removeCondition\/removeCondition.zip\">Java version<\/a>\n<\/p>\n<p>\nHere is <a href=\"http:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/sql-expression-parse-tree-traversal-in-preorderinorderpostorder\/\">another example<\/a> that illustrate how to iterate expression in pre-order, in-order and post-order.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you want to modify condition expression in where clause, such as remove a SQL variable in where condition without broken that condition expression or remove all where clause if necessary. Take this SQL for example, you want to remove @var1 in where condition, only delete it from where clause doesn&#8217;t work, that will make this statement syntax invalid. select f from tb where f1 between 1 and @var1 Illegal statement after remove @var1 select f from tb where f1 between 1 and Desired statement after remove @var1, should remove all where clause. select f from tb Here is another\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=\"Remove SQL\/user defined variables in where clause without broken condition expression\" \/>\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\/remove-sql-variables-in-where-clause-without-broken-condition-expression\/\" \/>\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=\"Remove SQL\/user defined variables in where clause without broken condition expression\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/remove-sql-variables-in-where-clause-without-broken-condition-expression\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL and Data Blog\" \/>\n<meta property=\"article:modified_time\" content=\"2012-01-29T07:37:46+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\/remove-sql-variables-in-where-clause-without-broken-condition-expression\/\",\"url\":\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/remove-sql-variables-in-where-clause-without-broken-condition-expression\/\",\"name\":\"Help you to make better use of General SQL Parser\",\"isPartOf\":{\"@id\":\"https:\/\/www.dpriver.com\/blog\/#website\"},\"datePublished\":\"2010-07-21T09:24:39+00:00\",\"dateModified\":\"2012-01-29T07:37:46+00:00\",\"description\":\"Remove SQL\/user defined variables in where clause without broken condition expression\",\"breadcrumb\":{\"@id\":\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/remove-sql-variables-in-where-clause-without-broken-condition-expression\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/remove-sql-variables-in-where-clause-without-broken-condition-expression\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/remove-sql-variables-in-where-clause-without-broken-condition-expression\/#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\":\"Remove SQL\/user defined variables in where clause without broken condition expression\"}]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Help you to make better use of General SQL Parser","description":"Remove SQL\/user defined variables in where clause without broken condition expression","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\/remove-sql-variables-in-where-clause-without-broken-condition-expression\/","og_locale":"en_US","og_type":"article","og_title":"Help you to make better use of General SQL Parser","og_description":"Remove SQL\/user defined variables in where clause without broken condition expression","og_url":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/remove-sql-variables-in-where-clause-without-broken-condition-expression\/","og_site_name":"SQL and Data Blog","article_modified_time":"2012-01-29T07:37:46+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\/remove-sql-variables-in-where-clause-without-broken-condition-expression\/","url":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/remove-sql-variables-in-where-clause-without-broken-condition-expression\/","name":"Help you to make better use of General SQL Parser","isPartOf":{"@id":"https:\/\/www.dpriver.com\/blog\/#website"},"datePublished":"2010-07-21T09:24:39+00:00","dateModified":"2012-01-29T07:37:46+00:00","description":"Remove SQL\/user defined variables in where clause without broken condition expression","breadcrumb":{"@id":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/remove-sql-variables-in-where-clause-without-broken-condition-expression\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/remove-sql-variables-in-where-clause-without-broken-condition-expression\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/remove-sql-variables-in-where-clause-without-broken-condition-expression\/#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":"Remove SQL\/user defined variables in where clause without broken condition expression"}]}]}},"_links":{"self":[{"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/pages\/333"}],"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=333"}],"version-history":[{"count":20,"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/pages\/333\/revisions"}],"predecessor-version":[{"id":1320,"href":"https:\/\/www.dpriver.com\/blog\/wp-json\/wp\/v2\/pages\/333\/revisions\/1320"}],"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=333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}