Quickly Integrate Custom SQL Queries With SharePoint

This Web Part will perform a custom SQL query with a custom display. Unlike previous examples, this will require you to provide your SQL connection string and query and make replacements inside the template itself to make it match the results of the query.

  • Step 1: Ensure the RSSBus Web Part is installed.
  • Step 2: Make sure you have a valid SQL connection string and query. If you are using another type of database, that will work as well � there are many different database connectors in the RSSBus Connector library.
  • Step 3: Add the RSSBus Web Part to your page and paste the following template into its source editor, but do not click "Apply" yet.
    <rsb:info>
       <input name="conn" default="server=***;database=***;User ID=***;Password=***" />
       <input name="query" default="SELECT TOP 20 * YourTable ORDER BY YourDateColumn" />
    </rsb:info>
    
    <rsb:import lib="RSSBus.SqlOps"/>
    
    <table width="100%">
      <tr> 
        <th style="background-color:LightGrey; white-space:nowrap">Name</th> 
        <th style="background-color:LightGrey; white-space:nowrap">Company</th> 
        <th style="background-color:LightGrey; white-space:nowrap">Product</th> 
        <th style="background-color:LightGrey; white-space:nowrap">Date/Time</th> 
      </tr> 
      <rsb:call op="sqlQuery">  
        <tr> 
          <td><a href="mailto:[sql:customeremail]">[sql:customername]</a></td>  
          <td>[sql:company]</td> 
          <td>[sql:productcode]</td> 
          <td>[sql:time]</td> 
        </tr> 
      </rsb:call>
    </table>
  • Step 4: Modify this template so that it works for your SQL server. There are a few things to change:
    1. On line 2 and 3, conn and query. Provide the connection string and query for your SQL query.
    2. On lines 10�13, modify the column header names to match the values coming back from your query. You can add others as well.
    3. On lines 18-21, change the outputs to match the outputs coming out of your query � these will match the column names. In this example the name, company, part, and time column values have been outputted for each query result.

As always, you can customize the HTML in the template or leave it as is.

Advanced Tip: Did you know that the RSSBus Web Part has YUI formatting capabilities built-in? Try the example below to format the output of the rsb:call as a YUI Table (modify the YUI script to match your own connection string, query, and column names).

<rsb:info> 
  <input name="conn" default="server=***;database=***;User ID=***;Password=***" /> 
  <input name="query" default="SELECT TOP 20 * FROM YourTable ORDER BY YourDateColumn DESC" /> 
</rsb:info> 

<rsb:import lib="RSSBus.SqlOps"/>

<rsb:set attr='_meta.YUIDataColDefs' value='DataDefsDown'/> 
<rsb:set attr='_meta.YUIDataFields' value='DataFieldsDown'/> 
<rsb:call op="sqlQuery" format=ToYuiTable/>  

<script> var DataDefsDown = [
  {key:"sql:customername",label:"Name",sortable:false,resizeable:true},
  {key:"sql:productcode",label:"Part#",sortable:false,resizeable:true},
  {key:"sql:time",label:"Date",sortable:false,resizeable:true},
  {key:"sql:company",label:"Company",sortable:false,resizeable:true},
  {key:"sql:title",label:"JobTitle",sortable:false,resizeable:true}
];
 
var DataFieldsDown = [
  {key:"sql:customername"},
  {key:"sql:productcode"},
  {key:"sql:time"},
  {key:"sql:company"},
  {key:"sql:title"}
];
</script>