{"id":20447,"date":"2024-02-19T12:30:09","date_gmt":"2024-02-19T11:30:09","guid":{"rendered":"https:\/\/help.openbee.com\/open-bee-portal\/administrators-guide\/sql-connectivity-module\/sql-queries\/"},"modified":"2024-06-07T10:52:31","modified_gmt":"2024-06-07T08:52:31","slug":"sql-queries","status":"publish","type":"page","link":"https:\/\/help.openbee.com\/en\/open-bee-portal\/administrators-guide\/sql-connectivity-module\/sql-queries\/","title":{"rendered":"SQL queries"},"content":{"rendered":"<div id=\"main-content\" class=\"wiki-content group\">\n<p>The &#8220;SQL Queries&#8221; screen allows you to create and configure queries that will retrieve data from your existing database to populate Open Bee\u2122 Portal metadata.<\/p>\n<p>To add a query, click &#8220;<strong>+&#8221;.<\/strong><\/p>\n<p><img decoding=\"async\" class=\"confluence-embedded-image\" src=\"https:\/\/help.openbee.com\/wp-content\/uploads\/2026\/03\/273355725-translated.png\" data-image-src=\"https:\/\/help.openbee.com\/wp-content\/uploads\/2026\/03\/273355725-translated.png\"><\/p>\n<p><strong>Name<\/strong> : the name of The SQL query name,<\/p>\n<p><strong>Ranking rule :<\/strong> The ranking rule or form that will be used to trigger the query.<\/p>\n<p>SQL Connection: The <strong>SQL<\/strong> connection defined in the first tab to use.<\/p>\n<p><strong>SQL Query<\/strong><\/p>\n<p>In this block, you can enter your SELECT query.<br \/>\nIn the WHERE clause of your query, you can call <strong>a single metadata<\/strong> by putting it between  <strong>&lt; &gt;<\/strong>.<\/p>\n<p>Example:<\/p>\n<div class=\"code panel pdl\" style=\"border-width: 1px;\">\n<div class=\"codeContent panelContent pdl\">\n<pre class=\"theme: Confluence; brush: java; gutter: false\" style=\"font-size: 12px;\">SELECT nom, prenom, email \nFROM ma_table \nWHERE ref_contrat = &lt;Num\u00e9ro de contrat&gt;<\/pre>\n<\/div>\n<\/div>\n<p>In this example, when the user enters the value of the metadata &#8220;Contract number&#8221; the request will be executed and 3 pieces of information will be retrieved, the last name, first name and email.<\/p>\n<p>Example of a request to an xls file:<\/p>\n<div class=\"code panel pdl\" style=\"border-width: 1px;\">\n<div class=\"codeContent panelContent pdl\">\n<pre class=\"theme: Confluence; brush: java; gutter: false\" style=\"font-size: 12px;\">SELECT [Ent\u00eate_de_ma_colonne_r\u00e9sultat] \nFROM [Nom_de_la_feuille$] \nWHERE [Ent\u00eate_de_ma_colonne_source] = '&lt;M\u00e9tadonn\u00e9e_de_d\u00e9clenchement&gt;'<\/pre>\n<\/div>\n<\/div>\n<p><strong>In&nbsp;an&nbsp;xls file&nbsp;,&nbsp; please&nbsp;put&nbsp;a&nbsp; $&nbsp; after&nbsp;the&nbsp;&nbsp;sheet name&nbsp;&nbsp;.<\/strong><\/p>\n<p>Another example of a request to a csv file:<\/p>\n<div class=\"code panel pdl\" style=\"border-width: 1px;\">\n<div class=\"codeContent panelContent pdl\">\n<pre class=\"theme: Confluence; brush: java; gutter: false\" style=\"font-size: 12px;\">SELECT [COL1] FROM fichier.csv WHERE [COL2] LIKE '&lt;Nom_index&gt;'<\/pre>\n<\/div>\n<\/div>\n<div class=\"aui-message problem shadowed information-macro\">\n<div class=\"message-content\">\n<p>When configuring the query, you must choose whether the query will return one or more rows of results.<br \/>\nThis choice is important because it conditions the storage of the data we are trying to recover.<\/p>\n<\/div>\n<\/div>\n<p>Here, we can assume that &#8220;<strong>This query returns a single result row<\/strong>&#8220;. Indeed, by entering a contract number, a unique reference, one expects to receive a unique record.<\/p>\n<p>Consider the following example:<\/p>\n<div class=\"code panel pdl\" style=\"border-width: 1px;\">\n<div class=\"codeContent panelContent pdl\">\n<pre class=\"theme: Confluence; brush: java; gutter: false\" style=\"font-size: 12px;\">SELECT nom, prenom, email FROM ma_table WHERE client = &lt;Nom du client&gt;<\/pre>\n<\/div>\n<\/div>\n<p>Let&#8217;s say we want to retrieve a customer&#8217;s sales contacts, so we can expect to receive multiple rows of results,<br \/>\nIn this case, it is important to choose &#8220;<strong>This query returns several rows of results<\/strong>&#8221; because the storage will have to be done in a metadata of type Tableau.<\/p>\n<p>Once the query has been entered, click on the &#8220;<strong>Perform association&nbsp;<\/strong><strong>&#8221; button to test the query and verify that the columns mentioned in the SELECT query are correctly returned.<\/strong><\/p>\n<p><img decoding=\"async\" class=\"confluence-embedded-image\" src=\"https:\/\/help.openbee.com\/wp-content\/uploads\/2026\/03\/273355726-translated.png\" data-image-src=\"https:\/\/help.openbee.com\/wp-content\/uploads\/2026\/03\/273355726-translated.png\"><\/p>\n<p>In this example, the columns of the SELECT query are displayed after clicking &#8220;<strong>Perform Association<\/strong>&#8220;.<br \/>\nThen, for each column, we choose a metadata of the classification rule or the form that will receive the data.<br \/>\nYou can&#8217;t leave a column unassociated.<\/p>\n<div class=\"aui-message problem shadowed information-macro\">\n<div class=\"message-content\">\n<p>If your query returns multiple rows of results, for consistency you won&#8217;t be able to choose just any type of metadata.<br \/>\nThis is because you will need to use a metadata of type Table, List, or Multiple Field.<br \/>\nIn addition, some types of metadata cannot be used in the association, such as File, Image, Annotation, or Signature because they are incompatible.<br \/>\nBut also the Users and Groups type, Lists with the &#8220;Multiple&#8221; option and Sublists.<\/p>\n<\/div>\n<\/div>\n<p><strong><br \/>\nExecution mode<\/strong> : Choose when The SQL query name will run either when you add a document, or change a metadata, or both.<br \/>\nPossible values are: Add a document, Edit a document, Add or edit a document.<\/p>\n<p>Once the request is configured, save by clicking on &#8220;<strong>Validate<\/strong>&#8220;.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The &#8220;SQL Queries&#8221; screen allows you to create and configure queries that will retrieve data from your existing database to populate Open Bee\u2122 Portal metadata. To add a query, click &#8220;+&#8221;. Name : the name of The SQL query name, Ranking rule : The ranking rule or form that will be used to trigger the [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"parent":20409,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"templates\/ob-help-products.php","meta":{"footnotes":""},"class_list":["post-20447","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/pages\/20447","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/comments?post=20447"}],"version-history":[{"count":4,"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/pages\/20447\/revisions"}],"predecessor-version":[{"id":22478,"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/pages\/20447\/revisions\/22478"}],"up":[{"embeddable":true,"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/pages\/20409"}],"wp:attachment":[{"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/media?parent=20447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}