{"id":5898,"date":"2017-12-12T18:42:30","date_gmt":"2017-12-12T18:42:30","guid":{"rendered":"https:\/\/alt2.minisoft.com\/support\/?p=5898"},"modified":"2020-07-01T14:06:28","modified_gmt":"2020-07-01T21:06:28","slug":"sql-lookup","status":"publish","type":"post","link":"https:\/\/alt2.minisoft.com\/support\/sql-lookup\/","title":{"rendered":"SQL Lookup"},"content":{"rendered":"<p>The purpose of an SQL Lookup is to return additional data to an eFORMz project based upon a value in a data file. Normally this value is an indexed item to a table in a database.<\/p>\n<h2>Step One: Setting up the Connection<\/h2>\n<div id=\"attachment_3316\" style=\"width: 310px\" class=\"wp-caption alignright\"><a href=\"https:\/\/alt2.minisoft.com\/support\/wp-content\/uploads\/2015\/06\/ConfigDBConn.jpg\"><img aria-describedby=\"caption-attachment-3316\" decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-3316\" src=\"https:\/\/alt2.minisoft.com\/support\/wp-content\/uploads\/2015\/06\/ConfigDBConn-300x281.jpg\" alt=\"The Configure database connection window\" width=\"300\" height=\"281\" srcset=\"https:\/\/alt2.minisoft.com\/support\/wp-content\/uploads\/2015\/06\/ConfigDBConn-300x281.jpg 300w, https:\/\/alt2.minisoft.com\/support\/wp-content\/uploads\/2015\/06\/ConfigDBConn-150x141.jpg 150w, https:\/\/alt2.minisoft.com\/support\/wp-content\/uploads\/2015\/06\/ConfigDBConn-250x234.jpg 250w, https:\/\/alt2.minisoft.com\/support\/wp-content\/uploads\/2015\/06\/ConfigDBConn-192x180.jpg 192w, https:\/\/alt2.minisoft.com\/support\/wp-content\/uploads\/2015\/06\/ConfigDBConn-320x300.jpg 320w, https:\/\/alt2.minisoft.com\/support\/wp-content\/uploads\/2015\/06\/ConfigDBConn.jpg 446w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-3316\" class=\"wp-caption-text\">The Configure database connection window<\/p><\/div>\n<p>1. If you haven\u2019t done so already, from the Project Properties &gt; Database tab add a new database reference by selecting New.<\/p>\n<p>2. The Configure Database Connection dialog box displays. Enter the <code>database name<\/code>, <code>driver class<\/code>, and <code>url<\/code>.<\/p>\n<p>3. Once the database has been configured select Test to confirm the connection. Once complete, click OK.<\/p>\n<p>For more information, view the following tutorial: <a href=\"\/support\/index.php\/where-to-set-up-your-database-connection\/\">Where to set up your database connection<\/a><br \/>\nA the list of\u00a0supported databases and their URLs is available here: <a href=\"\/support\/index.php\/database-url-and-driver-classes\/\">Supported URL and Driver Classes<\/a><br \/>\nTo troubleshoot a connection, view the following reference: <a href=\"\/support\/index.php\/troubleshooting-a-database-connection\/\">Troubleshooting a Database Connection<\/a><\/p>\n<h2>Step Two: Implement SQL Lookup<\/h2>\n<p>4. The database name will display on the Project Properties &gt; Database tab. Select Activate so that the information from the database becomes \u201creal-time\u201d data. Once complete, click OK.<\/p>\n<p>5. Create a variable containing the value you want to find in your database.<\/p>\n<p>6. Add the <a href=\"\/support\/index.php\/right-left-trim\/\">Right Trim and Left Trim<\/a>\u00a0function to the variable. This removes any possible leading and trailing spaces that would cause your lookup to fail.\u00a0<em>TIP: To confirm the value, view the results in the Variables Viewer window.<\/em><\/p>\n<p>7. Create a second variable to be populated by the first item in your SELECT statement. If more than one column of data will be returned create those variables now. From the Variables placeholder in the Project window, right click and select Variables &gt; By Position.<\/p>\n<p>8. Give your new variable a name and then select OK.<\/p>\n<p>9. Select your newly created variable, right-click, and select Function &gt; SQL Lookup.<\/p>\n<p>10. The SQL Lookup dialog box appears. In the database dropdown box, select the database you want to access.<\/p>\n<p>11. Enter the SQL Statement you want executed. Use \u201c?\u201d as replacement characters for parameters you want to pass to the statement.<\/p>\n<p>12. Add parameters in the order you want the \u201c?\u201d replaced in your statement.<\/p>\n<p>13. If you are returning more than one column of data, add the additional columns, selecting the variable you want the returned value stored in the \u2018Additional columns assigned to\u2019 field.\u00a0<em>NOTE: For complex queries write a stored procedure and execute it. The stored procedure must return a result set, not just a value.<\/em><\/p>\n<h3>Additional Resources on Databases<\/h3>\n<p><a href=\"\/support\/index.php\/eformz-table-lookup\/\">eFORMz Table Lookup<\/a><br \/>\n<a href=\"\/support\/index.php\/loading-multiple-rows-with-sql-load\/\">Loading Multiple Rows with SQL Load<\/a><br \/>\n<a href=\"\/support\/index.php\/calling-database-stored-procedures\/\">Calling Database Stored Procedures<\/a><br \/>\n<a href=\"\/support\/index.php\/calling-database-functions\/\">Calling Database Functions<\/a><br \/>\n<a href=\"\/support\/index.php\/troubleshooting-sql-database-error-the-statement-did-not-return-a-result-set\/\">Troubleshooting: SQL Error &#8211; The Statement Didn&#8217;t Return a Result Set<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The purpose of an SQL Lookup is to return additional data to an eFORMz project based upon a value in a data file. Normally this value is an indexed item to a table in a database. Step One: Setting up the Connection 1. If you haven\u2019t done so already, from the Project Properties &gt; Database [&hellip;]<\/p>\n","protected":false},"author":75,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[91,10],"tags":[84,338],"_links":{"self":[{"href":"https:\/\/alt2.minisoft.com\/support\/wp-json\/wp\/v2\/posts\/5898"}],"collection":[{"href":"https:\/\/alt2.minisoft.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alt2.minisoft.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alt2.minisoft.com\/support\/wp-json\/wp\/v2\/users\/75"}],"replies":[{"embeddable":true,"href":"https:\/\/alt2.minisoft.com\/support\/wp-json\/wp\/v2\/comments?post=5898"}],"version-history":[{"count":7,"href":"https:\/\/alt2.minisoft.com\/support\/wp-json\/wp\/v2\/posts\/5898\/revisions"}],"predecessor-version":[{"id":8176,"href":"https:\/\/alt2.minisoft.com\/support\/wp-json\/wp\/v2\/posts\/5898\/revisions\/8176"}],"wp:attachment":[{"href":"https:\/\/alt2.minisoft.com\/support\/wp-json\/wp\/v2\/media?parent=5898"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alt2.minisoft.com\/support\/wp-json\/wp\/v2\/categories?post=5898"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alt2.minisoft.com\/support\/wp-json\/wp\/v2\/tags?post=5898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}