<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>T-Sql on Matt Thornton</title>
    <link>https://matt-thornton.net/tags/t-sql/</link>
    <description>Recent content in T-Sql on Matt Thornton</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Fri, 30 Nov 2012 11:11:01 +0000</lastBuildDate><atom:link href="https://matt-thornton.net/tags/t-sql/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>The OLE DB provider Microsoft.Ace.OLEDB.12.0 for linked server (null) reported an error. Access denied.</title>
      <link>https://matt-thornton.net/tech/databases/the-ole-db-provider-microsoft-ace-oledb-12-0-for-linked-server-null-reported-an-error-access-denied/</link>
      <pubDate>Fri, 30 Nov 2012 11:11:01 +0000</pubDate>
      
      <guid>https://matt-thornton.net/tech/databases/the-ole-db-provider-microsoft-ace-oledb-12-0-for-linked-server-null-reported-an-error-access-denied/</guid>
      
        <description>&lt;p&gt;I&amp;rsquo;m noting this here primarily because I&amp;rsquo;m almost certain to trip over this again in the future. If you want to use the ACE or JET providers to read an e.g., Excel spreadsheet to an e.g., SQL Server table, then something like this is possible. Assuming you had a simple Excel workbook (Book1.xlsx) and in Sheet1 you had&lt;/p&gt;
&lt;p&gt;Col1 Col2&lt;br&gt;
Test Test2&lt;/p&gt;
&lt;p&gt;You could use this to load it:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;SELECT * INTO #tmpTable FROM OPENROWSET(&#39;Microsoft.ACE.OLEDB.12.0&#39;,&#39;Excel 12.0 Xml;HDR=YES;Database=C:TempBook1.xlsx&#39;,&#39;SELECT * FROM [Sheet1$]&#39;)&amp;lt;br /&amp;gt; GO&amp;lt;br /&amp;gt; SELECT * from #tmpTable&amp;lt;br /&amp;gt; &lt;/code&gt;&lt;/p&gt;</description>
      
    </item>
    
    <item>
      <title>Auto generate SQL audit tables and database triggers</title>
      <link>https://matt-thornton.net/tech/databases/auto-generate-sql-audit-tables-and-database-triggers/</link>
      <pubDate>Wed, 28 Nov 2012 15:56:48 +0000</pubDate>
      
      <guid>https://matt-thornton.net/tech/databases/auto-generate-sql-audit-tables-and-database-triggers/</guid>
      
        <description>&lt;p&gt;One approach to monitoring version history of items in SQL tables is to use an _Audit table version with database triggers. However, the creation and maintenance of the tables and triggers can be time consuming. &lt;a href=&#34;http://www.geekzilla.co.uk/ViewECBC0CC3-1C7E-4E7E-B243-F2F259A5C920.htm&#34;&gt;This post&lt;/a&gt; provided a nice script to automate the creation but unfortunately it suffered a few issues. In the comments, someone posted a sproc version of the script - but unfortunately this was also broken.&lt;/p&gt;
&lt;p&gt;So I have tidied it up and fixed the issues. My host doesn&amp;rsquo;t let me post SQL in these posts, so you can view the file &lt;a href=&#34;https://matt-thornton.net/images/posts/createtriggers.txt&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;</description>
      
    </item>
    
    <item>
      <title>Quick tip: Use OVER to get row numbers in subsets</title>
      <link>https://matt-thornton.net/tech/databases/quick-tip-use-over-to-get-row-numbers-in-subsets/</link>
      <pubDate>Fri, 10 Dec 2010 14:38:27 +0000</pubDate>
      
      <guid>https://matt-thornton.net/tech/databases/quick-tip-use-over-to-get-row-numbers-in-subsets/</guid>
      
        <description>&lt;p&gt;Consider the following. You have a set of data. Within the data are multiple subsets that share an identifier. WIthin your main set, you need to number the subsets for each item within it, e.g.,&lt;/p&gt;
&lt;p&gt;Data&lt;/p&gt;
&lt;p&gt;ID SubsetID Name Lots more columns&amp;hellip;&lt;br&gt;
———- ———-&lt;br&gt;
1 ABC Dave&lt;br&gt;
2 DEF Trev&lt;br&gt;
3 DEF Bob&lt;br&gt;
4 DEF Steve&lt;br&gt;
5 HIJ Jim&lt;br&gt;
6 HIJ Bilbo&lt;/p&gt;
&lt;p&gt;and you want something like&lt;/p&gt;
&lt;p&gt;ID SubsetID SubsetPosition Name Lots more columns&amp;hellip;&lt;br&gt;
———- ———-&lt;br&gt;
1 ABC 1 Dave&lt;br&gt;
2 DEF 1 Trev&lt;br&gt;
3 DEF 2 Bob&lt;br&gt;
4 DEF 3 Steve&lt;br&gt;
5 HIJ 1 Jim&lt;br&gt;
6 HIJ 2 Bilbo&lt;/p&gt;</description>
      
    </item>
    
  </channel>
</rss>