<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>SQL Tips &amp; Tricks — mibuso.com</title>
        <link>https://forum.mibuso.com/</link>
        <pubDate>Wed, 13 May 2026 09:38:43 +0000</pubDate>
        <language>en</language>
            <description>SQL Tips &amp; Tricks — mibuso.com</description>
    <atom:link href="https://forum.mibuso.com/categories/sql-tips-tricks/feed.rss" rel="self" type="application/rss+xml"/>
    <item>
        <title>I can&#39;t complete the connection between the tables</title>
        <link>https://forum.mibuso.com/discussion/78022/i-cant-complete-the-connection-between-the-tables</link>
        <pubDate>Sat, 18 May 2024 10:33:23 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>mazheika</dc:creator>
        <guid isPermaLink="false">78022@/discussions</guid>
        <description><![CDATA[HELLO! Can someone please advise on how to now link to the purchase invoice? How to complete this chain?<br /><br /><br />
SELECT *<br />
FROM [Training$Sales Invoice Header$437] AS sih<br />
LEFT JOIN [Training$Sales Invoice Line$437] AS sil ON sil.[Document No_] = sih.[No_]<br />
JOIN [Training$Value Entry$437] AS ve ON  ve.[Document No_] = sih.[No_] AND sil.[Line No_] = ve.[Document Line No_]<br />
JOIN [dbo].[Training$Item Ledger Entry$437] AS ile ON ve.[Item Ledger Entry No_] = ile.[Entry No_]<br />
WHERE ve.[Source Code] != 'INVTADJMT'<br />
Categories:<br />]]>
        </description>
    </item>
    <item>
        <title>how to clear all entries and transaction from Navision 2016 using sql query</title>
        <link>https://forum.mibuso.com/discussion/77416/how-to-clear-all-entries-and-transaction-from-navision-2016-using-sql-query</link>
        <pubDate>Tue, 20 Dec 2022 06:02:09 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>rajiv05</dc:creator>
        <guid isPermaLink="false">77416@/discussions</guid>
        <description><![CDATA[if any one have sql query for deleting all the entries from navision --- i have to create one company so i copied it from preivious company but along with all entries copied ,,<br /><br />
i only need master data]]>
        </description>
    </item>
    <item>
        <title>sys.sysobjvalues</title>
        <link>https://forum.mibuso.com/discussion/77087/sys-sysobjvalues</link>
        <pubDate>Sun, 26 Jun 2022 15:41:23 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>ChowdaryK</dc:creator>
        <guid isPermaLink="false">77087@/discussions</guid>
        <description><![CDATA[Hi,<br />
I am getting this error.<br />
The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object name 'sys.sysobjvalues' and the index name 'clst'. The duplicate key value is (60, 808494059, 1, 0).<br />
I have restored the database in different servers but no use.<br /><br />
DAC is giving a big problem<br />
Does anyone help to remote duplicated values in the sys object tables<br /><br />
Please.<br /><br />
Thanks in Advance<br /><br />
Kris<br />]]>
        </description>
    </item>
    <item>
        <title>Business Central Telemetry</title>
        <link>https://forum.mibuso.com/discussion/75281/business-central-telemetry</link>
        <pubDate>Mon, 18 May 2020 11:49:55 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>TESDeveloper</dc:creator>
        <guid isPermaLink="false">75281@/discussions</guid>
        <description><![CDATA[Hello,<br /><br />
I would like to better understand Telemetry capabilities within Business Central. Does anyone have any useful resources I could read / watch to get this information.<br /><br />
Thank you!]]>
        </description>
    </item>
    <item>
        <title>Updating Data in a SQL-Database with DotNet DataAdapter and Data Rows</title>
        <link>https://forum.mibuso.com/discussion/74199/updating-data-in-a-sql-database-with-dotnet-dataadapter-and-data-rows</link>
        <pubDate>Fri, 13 Sep 2019 17:13:36 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>FragenFrager</dc:creator>
        <guid isPermaLink="false">74199@/discussions</guid>
        <description><![CDATA[Hello,<br />
I'm provided with the task to update a programm that transfers data to a SQL-Database. It is from an older version and uses ADO recordsets, which simply does not work with NAV Business Central any more.<br />
So, I wanted to use System.Data.SqlClient.SqlDataAdapter, System.Data.DataTable, System.Data.DataRow and so on.<br />
Reading data into DataAdapter works fine, but I simply do not get how to transfer data into SQL Database with it.<br />
I tried to put Data into a DataRow  ( System.Data.DataRow), but it is not even possible to identify the column with its name  (e.g. DotNetSQLDataRow.Item('Name') ).  Identifying it with the integer-value of the column works, okay, but then I simply cannot put a value into it. A simple DotNetSQLDataRow.Item(0) := NewValue is allready denied by the compiler.<br />
The examples dealing with this only refer to C# or VB.net. I simply could not find any examples using C\SIDE-Code.<br />
I would be very, very glad If anyone can help me.<br /><br />
With kind regards<br />
FF]]>
        </description>
    </item>
    <item>
        <title>Using Transparent Data Encryption (TDE) with Dynamics NAV</title>
        <link>https://forum.mibuso.com/discussion/71373/using-transparent-data-encryption-tde-with-dynamics-nav</link>
        <pubDate>Thu, 26 Apr 2018 20:52:46 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>kennie</dc:creator>
        <guid isPermaLink="false">71373@/discussions</guid>
        <description><![CDATA[In case you have an urgent need for encryption at rest for your Dynamics NAV installation, we just declare support for Transparent Data Encryption...<br /><br /><a rel="nofollow" href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=https%3A%2F%2Fblogs.msdn.microsoft.com%2Fnav%2F2018%2F04%2F26%2Fusing-sql-server-transparent-data-encryption-tde-with-dynamics-nav%2F">https://blogs.msdn.microsoft.com/nav/2018/04/26/using-sql-server-transparent-data-encryption-tde-with-dynamics-nav/</a>]]>
        </description>
    </item>
    <item>
        <title>Quickly read company specific table data for each company with SQL</title>
        <link>https://forum.mibuso.com/discussion/71132/quickly-read-company-specific-table-data-for-each-company-with-sql</link>
        <pubDate>Fri, 09 Mar 2018 15:52:39 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>RemkoD</dc:creator>
        <guid isPermaLink="false">71132@/discussions</guid>
        <description><![CDATA[Sometimes I need to check table data from a company specific table in each company. A quick lookup from MSSQL can make live easier. I've made an easy query for this.<br /><br />
In this example I want a quick overview from all the job queues and entries in the NAV database.<br /><pre spellcheck="false" tabindex="0">DECLARE @TableName varchar (50) = 'Job Queue'&#13;
DECLARE @TableName2 varchar (50) = 'Job Queue Entry'&#13;
&#13;
SELECT &#13;
	'SELECT ''' + [Name] + ''' AS "NAV Company ('+ [Name] +')", * FROM [dbo].[' + REPLACE([Name], '.', '_') + '$' + @TableName + ']' AS "Generated Query 1", &#13;
	'SELECT ''' + [Name] + ''' AS "NAV Company ('+ [Name] +')", * FROM [dbo].[' + REPLACE([Name], '.', '_') + '$' + @TableName2 + ']' AS "Generated Query 2"&#13;
FROM [dbo].[Company]
</pre>
<br />
This query generates new queries.<br /><br /><img src="https://us.v-cdn.net/5022383/uploads/editor/j4/vd3fddy82ut3.png" alt="vd3fddy82ut3.png" srcset="https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=300, width=300/5022383/uploads/editor/j4/vd3fddy82ut3.png 300w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=600, width=600/5022383/uploads/editor/j4/vd3fddy82ut3.png 600w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=800, width=800/5022383/uploads/editor/j4/vd3fddy82ut3.png 800w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=1200, width=1200/5022383/uploads/editor/j4/vd3fddy82ut3.png 1200w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=1600, width=1600/5022383/uploads/editor/j4/vd3fddy82ut3.png 1600w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=2000, width=2000/5022383/uploads/editor/j4/vd3fddy82ut3.png 2000w, https://us.v-cdn.net/5022383/uploads/editor/j4/vd3fddy82ut3.png" sizes="100vw" /><br /><br />
You can execute all generated queries to get the table data from all the companies. If you change the table name in the declare statement you can use this query for other tables as well. ]]>
        </description>
    </item>
    <item>
        <title>BackUp Automatically DATABASE NAV</title>
        <link>https://forum.mibuso.com/discussion/70659/backup-automatically-database-nav</link>
        <pubDate>Wed, 27 Dec 2017 16:41:02 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>souoik</dc:creator>
        <guid isPermaLink="false">70659@/discussions</guid>
        <description><![CDATA[Hi<br />
am working in NAV 2017 and i need to saved database automatically ? how can do this ?]]>
        </description>
    </item>
    <item>
        <title>How I can data copy from one table to another table in vidual studio 2010</title>
        <link>https://forum.mibuso.com/discussion/70540/how-i-can-data-copy-from-one-table-to-another-table-in-vidual-studio-2010</link>
        <pubDate>Fri, 08 Dec 2017 09:15:28 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>Deepansh_Saini25</dc:creator>
        <guid isPermaLink="false">70540@/discussions</guid>
        <description><![CDATA[How I can data copy from one table to another table in vidual studio 2010 by navision database]]>
        </description>
    </item>
    <item>
        <title>Updated MSDN documentation on SQL Server setup and configuration</title>
        <link>https://forum.mibuso.com/discussion/69195/updated-msdn-documentation-on-sql-server-setup-and-configuration</link>
        <pubDate>Thu, 11 May 2017 08:46:07 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>kennie</dc:creator>
        <guid isPermaLink="false">69195@/discussions</guid>
        <description><![CDATA[We updated the MSDN documentation on SQL Server setup and configuration two months ago:<br /><br /><a rel="nofollow" href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Fdynamics-nav%2Finstallation-considerations-for-microsoft-sql-server">https://msdn.microsoft.com/en-us/dynamics-nav/installation-considerations-for-microsoft-sql-server</a><br /><br />
Hopefully, this covers most of the topics you need to consider when optimizing a SQL Server instance for optimal performance for Dynamics NAV workloads]]>
        </description>
    </item>
    <item>
        <title>Import between Dynamics nav databases</title>
        <link>https://forum.mibuso.com/discussion/66007/import-between-dynamics-nav-databases</link>
        <pubDate>Tue, 16 Feb 2016 01:59:29 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>ariuka</dc:creator>
        <guid isPermaLink="false">66007@/discussions</guid>
        <description><![CDATA[Hello all,<br />
I need an advise from our experienced and valuable members, we have a task exchange data between sql servers.<br />
1. From server /MS SQL 2012 standard/to POS database import basic information like customer, item, sales price etc. /no updates on POS/<br />
2. From 4-5 POS databases /MS SQL 2012 express/ to the server database import sales header and line. /no updates on server side/<br /><br />
We are planning to use merge replication for this task. The question is:<br />
- Could MS SQL Replication is proper solution?<br />
- If not, what else would be?]]>
        </description>
    </item>
    <item>
        <title>MySQL Database!!!</title>
        <link>https://forum.mibuso.com/discussion/59336/mysql-database</link>
        <pubDate>Thu, 17 Oct 2013 18:10:10 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>jessepit</dc:creator>
        <guid isPermaLink="false">59336@/discussions</guid>
        <description><![CDATA[If I decide to make a website with a database, why would I need to know SQL but not just knowing how to use MySQL?]]>
        </description>
    </item>
    <item>
        <title>Using ADO.Net to Read and Update an External Table</title>
        <link>https://forum.mibuso.com/discussion/62921/using-ado-net-to-read-and-update-an-external-table</link>
        <pubDate>Tue, 25 Nov 2014 14:39:43 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>shrekut</dc:creator>
        <guid isPermaLink="false">62921@/discussions</guid>
        <description><![CDATA[I am trying to read and update a table in an external SQL Server. I am able to read the data ok, but I have not been able to figure out how to update the record I read from that table. I am including the Code Example I'm using to read. The statement to update the record is also included. Can someone please help me with an example of code that will execute the update statement?<br /><pre spellcheck="false" tabindex="0">OBJECT Codeunit 50006 ADO.Net External Table
{
  OBJECT-PROPERTIES
  {
    Date=11/25/14;
    Time=[ 9:23:03 AM];
    Modified=Yes;
    Version List=;
  }
  PROPERTIES
  {
    OnRun=BEGIN
            SRSetup.GET;
            CLEAR(SQLReader);
            CLEAR(SQLCommand);
            CLEAR(SQLConnection);

            SQLConnection := SQLConnection.SqlConnection('Server=' + SRSetup."SQL Server Name" + ';'
                                                         + 'Database=' + SRSetup."SQL Database Name" + ';'
                                                         + 'User ID=' + SRSetup."SQL Login ID" + ';'
                                                         + 'Password=' + SRSetup."SQL Password" + ';');


            SQLString := 'SELECT * FROM tNavisionOrders WHERE ImportStatus = ' + '''' + 'Pending' + '''' + ';';
            SQLConnection.Open;
            SQLCommand := SQLConnection.CreateCommand();
            SQLCommand.CommandText := SQLString;
            SQLReader := SQLCommand.ExecuteReader;

            SQLReader.Read();
            DateStr := SQLReader.GetSqlValue(1);
            EVALUATE(TestDate,COPYSTR(DateStr,3,2) + '/' + COPYSTR(DateStr,1,2) + '/' + COPYSTR(DateStr,5,4));

            RemoteRefNo := SQLReader.GetSqlValue(0);

            ImportStatus := SQLReader.GetSqlValue(46);

            MESSAGE( 'Reading %1 || %2 || %3',RemoteRefNo,TestDate,ImportStatus);


            SQLString := 'UPDATE tNavisionOrders SET ImportStatus = ' + '''' + 'Imported' + ''''
                       + ' WHERE ImportStatus = ' + '''' + 'Pending' + ''''
                       + ' AND OrderNo = ' + '''' + RemoteRefNo + '''' + ';';

            // Need code to Update the above record (RemoteRefNo) with ImportStatus := 'Imported'

            SQLConnection.Close;
          END;

  }
  CODE
  {
    VAR
      SQLConnection@1000000009 : DotNet "'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Data.SqlClient.SqlConnection";
      SQLCommand@1000000008 : DotNet "'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Data.SqlClient.SqlCommand";
      SQLReader@1000000007 : DotNet "'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Data.SqlClient.SqlDataReader";
      SQLString@1000000005 : Text[1000];
      SRSetup@1000000004 : Record 311;
      TestDate@1000000003 : Date;
      DateStr@1000000002 : Text[250];
      RemoteRefNo@1000000001 : Text[250];
      ImportStatus@1000000000 : Text[250];

    EVENT SQLCommand@1000000008::StatementCompleted@57(sender@1000000001 : Variant;e@1000000000 : DotNet "'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Data.StatementCompletedEventArgs");
    BEGIN
    END;

    EVENT SQLCommand@1000000008::Disposed@58(sender@1000000001 : Variant;e@1000000000 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.EventArgs");
    BEGIN
    END;

    EVENT SQLConnection@1000000009::InfoMessage@48(sender@1000000001 : Variant;e@1000000000 : DotNet "'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Data.SqlClient.SqlInfoMessageEventArgs");
    BEGIN
    END;

    EVENT SQLConnection@1000000009::StateChange@49(sender@1000000001 : Variant;e@1000000000 : DotNet "'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Data.StateChangeEventArgs");
    BEGIN
    END;

    EVENT SQLConnection@1000000009::Disposed@50(sender@1000000001 : Variant;e@1000000000 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.EventArgs");
    BEGIN
    END;

    BEGIN
    END.
  }
}

</pre>
]]>
        </description>
    </item>
    <item>
        <title>Deny object changes in NAV</title>
        <link>https://forum.mibuso.com/discussion/54522/deny-object-changes-in-nav</link>
        <pubDate>Fri, 24 Aug 2012 14:15:31 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>Waldo</dc:creator>
        <guid isPermaLink="false">54522@/discussions</guid>
        <description><![CDATA[<span>I blogged about it <a href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Fdynamicsuser.net%2Fblogs%2Fwaldo%2Farchive%2F2012%2F08%2F01%2Fdeny-object-changes-in-sql-server.aspx" rel="nofollow">here</a>, but I came accross this forum, so why not just post it here as well :-).</span><br /><br />
Internally at iFacto, we have been working quite heavily on our infrastructure. And if I say "heavily" .. I mean unbefreakinglievable heavily. In a way: we threw everything out .. and we placed a lot in. But we only did this after going very deep in pre-defining about everything we could predefine: user security, SQL security, How to set up and maintain development databases, QA databases, Internal stuff, what do we back up, how much, .. . You know, the usual. And probably you also know that doing that as an IT partner, isn't that easy to do: you have to foresee IT for yourself, and for your customer's IT (at least - for its developents..), for products .. Releasemanagement, product management and sh&lt;bleep&gt;t … .<br /><br />
Anyway … it would take me too long to explain everything (although, I'm willing to expand on this if you want .. just drop me a comment). It's just .. by doing this, we created a lot of scripts, tips and tricks .. which I'm going to share over the few months of blogging..<br /><br />
When we were thinking about how to deny the object changes for released databases, we were thinking about how it was usually done: write some kind of trigger on the object table, and go from there.. . Or what I also heard: make a database "Read Only" in SQL Server.<br /><br />
But there is a much cleaner solution for doing something like this. With setting simple SQL Server Permissions, you can "Deny" object changes simply by setting GRANTing and DENYing the right permissions on the Object Table.<br /><br />
In our case, after setting up our new domain, we only grant permissions (all kinds of permissions) to User Groups (which is going to bite us in our *ss with NAV2013 (it seems) .. but anyway..). In this case, all users that have access to the database, are part of the windows group "RC-NAV-TECHNICAL".<br /><br />
Only thing we have to do, is to execute this "script" to the database that we don't want users to change objects:<br /><pre spellcheck="false" tabindex="0">GRANT CONTROL ON [dbo].[Object] TO [IFACTO\RC-NAV-TECHNICAL] 
GRANT SELECT ON [dbo].[Object] TO [IFACTO\RC-NAV-TECHNICAL] 
GRANT VIEW CHANGE TRACKING ON [dbo].[Object] TO [IFACTO\RC-NAV-TECHNICAL] 
GRANT VIEW DEFINITION ON [dbo].[Object] TO [IFACTO\RC-NAV-TECHNICAL] 
DENY ALTER ON [dbo].[Object] TO [IFACTO\RC-NAV-TECHNICAL] 
DENY DELETE ON [dbo].[Object] TO [IFACTO\RC-NAV-TECHNICAL] 
DENY INSERT ON [dbo].[Object] TO [IFACTO\RC-NAV-TECHNICAL] 
DENY REFERENCES ON [dbo].[Object] TO [IFACTO\RC-NAV-TECHNICAL] 
DENY TAKE OWNERSHIP ON [dbo].[Object] TO [IFACTO\RC-NAV-TECHNICAL] 
DENY UPDATE ON [dbo].[Object] TO [IFACTO\RC-NAV-TECHNICAL]
</pre>
If you're not that familiar with T-SQL, you can use your SQL Server Management Studio to set up the permissions. Just select your database, go to security, double click the user (or group), select securables, click "Search", select "Specific Objects" and click OK. Graphically:<br /><br /><img src="http://users.telenet.be/waldo1001/080112_0545_Denyobjectc1.png" alt="080112_0545_Denyobjectc1.png" srcset="https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=300, width=300/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc1.png 300w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=600, width=600/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc1.png 600w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=800, width=800/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc1.png 800w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=1200, width=1200/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc1.png 1200w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=1600, width=1600/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc1.png 1600w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=2000, width=2000/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc1.png 2000w, http://users.telenet.be/waldo1001/080112_0545_Denyobjectc1.png" sizes="100vw" /><br /><br />
Next, select "Tables" from the Object Types, and try to find the Object-table:<br /><br /><img src="http://users.telenet.be/waldo1001/080112_0545_Denyobjectc2.png" alt="080112_0545_Denyobjectc2.png" srcset="https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=300, width=300/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc2.png 300w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=600, width=600/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc2.png 600w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=800, width=800/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc2.png 800w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=1200, width=1200/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc2.png 1200w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=1600, width=1600/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc2.png 1600w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=2000, width=2000/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc2.png 2000w, http://users.telenet.be/waldo1001/080112_0545_Denyobjectc2.png" sizes="100vw" /><br /><br />
Now, it's all about DENY-ing and GRANT-ing the different permissions you have available for your Object Table. In my opinion, this is the right setup:<br /><br /><img src="http://users.telenet.be/waldo1001/080112_0545_Denyobjectc3.png" alt="080112_0545_Denyobjectc3.png" srcset="https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=300, width=300/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc3.png 300w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=600, width=600/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc3.png 600w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=800, width=800/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc3.png 800w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=1200, width=1200/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc3.png 1200w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=1600, width=1600/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc3.png 1600w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=2000, width=2000/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc3.png 2000w, http://users.telenet.be/waldo1001/080112_0545_Denyobjectc3.png" sizes="100vw" /><br /><br />
When you generate a script from this, you'll see you get the same as I showed above.<br /><br />
So, what happens if I do try to change an object?<br /><br />
Well, as you would expect, you get this SQL Server Permission Error:<br /><br /><img src="http://users.telenet.be/waldo1001/080112_0545_Denyobjectc4.png" alt="080112_0545_Denyobjectc4.png" srcset="https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=300, width=300/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc4.png 300w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=600, width=600/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc4.png 600w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=800, width=800/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc4.png 800w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=1200, width=1200/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc4.png 1200w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=1600, width=1600/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc4.png 1600w, https://us.v-cdn.net/cdn-cgi/image/quality=80, format=auto, fit=scale-down, height=2000, width=2000/http://users.telenet.be/waldo1001/080112_0545_Denyobjectc4.png 2000w, http://users.telenet.be/waldo1001/080112_0545_Denyobjectc4.png" sizes="100vw" /><br /><br />
Same for insert or deleting an object.<br /><br />
I particularly like this way of denying permissions, not only because it makes most sense, but also: I'm still able to work with data in the database (post invoices and such - this won't be possible in a "Read Only" database), and I don't need complex triggers to figure out why something is denied or not.<br /><br />
Are there no buts?<br /><br />
Sure. You can only do this on the entire Object table. You have to keep that in mind when you're implementing this. For example, users won't be able to update a menu suite.<br /><br />
Probably most of you figured this already out. We actually never cared until our infrastructural change .. and I couldn't find a decent solution online .. so I thought: "let's share!" ;-).<br /><br />
Enjoy!]]>
        </description>
    </item>
    <item>
        <title>&amp;quot;Nicely&amp;quot; formatted dates in SQL queries</title>
        <link>https://forum.mibuso.com/discussion/34817/nicely-formatted-dates-in-sql-queries</link>
        <pubDate>Tue, 02 Jun 2009 23:06:44 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>rsaritzky</dc:creator>
        <guid isPermaLink="false">34817@/discussions</guid>
        <description><![CDATA[I would expect that many of us wish formatting dates (to remove the "time" portion of the date field) in Transact-SQL or other queries to the NAV database was easier.  I found that a commonly-quoted solution of using<br /><br />
convert(varchar, &lt;datefield&gt; ,101)<br /><br />
causes problems in Excel if you are querying the SQL databae directly from Excel - the above function converts the date to a varchar (text) field in Excel, so you can't sort by date if your standard date format is dd/mm/yyyy - all the "January" dates sort together regardless of year.<br /><br />
Well, I received an email from Database Journal today, and they had a link to the following article<br /><br /><a href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Fwww.databasejournal.com%2Ffeatures%2Fmssql%2Farticle.php%2F3820771%2FFormatted-date-in-SQL-Server-2008.htm" rel="nofollow">http://www.databasejournal.com/features ... r-2008.htm</a><br /><br />
The contributor published a function that converts dates to date fields with formats similar to the way NAV formats work (not exactly but it reminded me of NAV).  For example, to return a date in format mm/dd/yyyy, the function<br /><br />
format_date(&lt;datefield&gt;,'MM/DD/YYYY')<br /><br />
returns the date field as a date field in the format MM/DD/YYYY<br /><br />
Similarly, you can pull any part of the date off, e.g.<br /><br />
format_date(&lt;datefield&gt;,'MM') returns just the month<br /><br />
and<br /><br />
format_date(&lt;datefield&gt;,'MONTH') returns the name of the month.<br /><br />
Lots of formats in this great function!:<br />
YYYY  - Year in YYYY Format including century<br />
Yr  - Year in YY format<br />
QQ  - Display Quarter<br />
MM  - Display Month<br />
WW  - Diplay Week<br />
DD  - Display day<br />
24HH  - Display hour in 24 hr format<br />
12HH  - Display hour in 12 hr format<br />
MI  - Display minutes<br />
SS  - Display seconds<br />
MS  - Display Milliseconds<br />
MCS  - Display MicroSeconds<br />
NS  - Display NanoSeconds<br />
DAY  - Display day name example: Monday<br />
MONTH-  - Display Month name example: August<br />
MON  - Display short month name example: Aug<br />
AMPM  - Display AM / PM for 12 hr format<br />
TZ  - Display time offset<br />
UNIXPOSIX  - Display unix posix time. Number of seconds from 1/1/1970  (disabled in this version)<br />
UCASE  - Display the result in upper case<br />
LCASE  - Display the result in lower case<br /><br />
CAVEAT:  The UNIXPOSIX format (number of seconds since 1/1/1970) doesn't work for dates prior to 12/14/1901, so 'empty' dates in NAV that are stored as 1/1/1753 cause the function to fail.  I simply removed 2 lines of code to eliminate that format since I had no use for it.  There are also 3 other formats that work only in SQL 2008, so if you're running SQL 2005 or earlier you have to remove another 6 lines from the function.  Just read the full comment thread below the article and it will document the changes you need to make.]]>
        </description>
    </item>
    <item>
        <title>log file backup</title>
        <link>https://forum.mibuso.com/discussion/49367/log-file-backup</link>
        <pubDate>Tue, 27 Sep 2011 16:41:37 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>Horse06</dc:creator>
        <guid isPermaLink="false">49367@/discussions</guid>
        <description><![CDATA[Hi expert, is there any way to schedule the automatic back up for the log file from the SQL server enterprise manager? Please adivse! Appreciate it!]]>
        </description>
    </item>
    <item>
        <title>How to rename a database including db files</title>
        <link>https://forum.mibuso.com/discussion/49814/how-to-rename-a-database-including-db-files</link>
        <pubDate>Wed, 26 Oct 2011 08:27:40 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>ta5</dc:creator>
        <guid isPermaLink="false">49814@/discussions</guid>
        <description><![CDATA[Hi<br />
After renaming a sql db in the ssms, the data files are not affected. What is the best approach do rename also the data files. In our case, it wouldnt be a problem if the database is not online during the rename.<br />
Thanks in advance<br />
Thomas]]>
        </description>
    </item>
    <item>
        <title>KILL inactive users</title>
        <link>https://forum.mibuso.com/discussion/48550/kill-inactive-users</link>
        <pubDate>Tue, 26 Jul 2011 08:17:46 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>SBokhorst</dc:creator>
        <guid isPermaLink="false">48550@/discussions</guid>
        <description><![CDATA[Because active users are quite expensive, I prefer to kill sessions of idle users<br />
I first log the user activity.<br />
I only kill sessions when they are close to our limmit of 33 concurrent users.<br />
and because some users are working with batches that may not be killed we can exlude them..<br />
and the script is limmitted to 5 kill actions.<br />
I start the script with a maintanace plan but it can be started manualy as well<br /><br />
Regards.<br /><br />
USE master<br />
GO<br /><br />
INSERT INTO USDB_MDNAV40SP3_D.dbo.ActivityUserMonitor<br />
SELECT GETDATE() as now, spid, loginame, lastwaittype, dbid, uid, login_time, last_batch, open_tran, status, hostname, Program_name, Hostprocess, cmd, net_library,  (GETDATE()-last_batch) AS inactivetime from sys.sysprocesses<br />
WHERE --(GETDATE()-last_batch)&gt; '1900-01-01 00:30:00.000' AND –- LAATSTE STUKJE KUN JE AAN ZETTEN DAN LOG JE ALLEEN DE MENSEN LANGER DAN 30 MIN.<br />
net_library = 'TCP/IP' AND loginame &lt;&gt; 'bpmone' AND loginame &lt;&gt; 'user.to_exclude'<br />
order by inactivetime<br />
GO<br /><br />
IF ((SELECT COUNT(*) FROM sys.sysprocesses WHERE net_library = 'TCP/IP' AND loginame &lt;&gt; 'user.to_exclude' AND loginame &lt;&gt; 'user.to_exclude') &gt; '28')<br />
BEGIN<br /><br />
DECLARE <a href="https://forum.mibuso.com/profile/tokill" rel="nofollow">@tokill</a> smallint;<br />
DECLARE <a href="https://forum.mibuso.com/profile/counter" rel="nofollow">@counter</a> int;<br />
DECLARE <a href="https://forum.mibuso.com/profile/CMD1" rel="nofollow">@CMD1</a> varchar(80)<br /><br />
SET <a href="https://forum.mibuso.com/profile/counter" rel="nofollow">@counter</a> = 1<br /><br /><br />
WHILE(SELECT count(*) from sysprocesses<br />
WHERE (GETDATE()-last_batch)&gt; '1900-01-01 00:30:00.000'<br />
AND net_library = 'TCP/IP'<br />
AND loginame &lt;&gt; 'user.to_exclude1'<br />
AND loginame &lt;&gt; 'user.to_exclude2'<br />
AND loginame &lt;&gt; 'user.to_exclude3'<br />
AND loginame &lt;&gt; 'user.to_exclude4'<br />
AND loginame &lt;&gt; 'user.to_exclude5'<br />
OR<br />
(GETDATE()-last_batch)&gt; '1900-01-01 00:45:00.000'<br />
AND net_library = 'TCP/IP'<br />
AND loginame &lt;&gt; 'user.to_exclude1'<br />
AND loginame &lt;&gt; 'user.to_exclude2'<br />
AND loginame &lt;&gt; 'user.to_exclude3'<br />
AND loginame &lt;&gt; 'user.to_exclude4') &gt; 0 AND <a href="https://forum.mibuso.com/profile/counter" rel="nofollow">@counter</a> &lt; 5<br />
BEGIN<br />
SET <a href="https://forum.mibuso.com/profile/counter" rel="nofollow">@counter</a> = <a href="https://forum.mibuso.com/profile/counter" rel="nofollow">@counter</a> + 1 ;<br />
SET <a href="https://forum.mibuso.com/profile/tokill" rel="nofollow">@tokill</a> = (SELECT max(spid) from sysprocesses<br />
WHERE (GETDATE()-last_batch)&gt; '1900-01-01 00:30:00.000'<br />
AND net_library = 'TCP/IP'<br />
AND loginame &lt;&gt; 'user.to_exclude1'<br />
AND loginame &lt;&gt; 'user.to_exclude2'<br />
AND loginame &lt;&gt; 'user.to_exclude3'<br />
AND loginame &lt;&gt; 'user.to_exclude4'<br />
AND loginame &lt;&gt; 'user.to_exclude5'<br />
OR<br />
(GETDATE()-last_batch)&gt; '1900-01-01 00:45:00.000'<br />
AND net_library = 'TCP/IP'<br />
AND loginame &lt;&gt; 'user.to_exclude1'<br />
AND loginame &lt;&gt; 'user.to_exclude2'<br />
AND loginame &lt;&gt; 'user.to_exclude3'<br />
AND loginame &lt;&gt; 'user.to_exclude4') ;<br /><br />
SET <a href="https://forum.mibuso.com/profile/CMD1" rel="nofollow">@CMD1</a> = 'KILL ' + CAST(<a href="https://forum.mibuso.com/profile/tokill" rel="nofollow">@tokill</a> AS varchar(5))<br /><br />
PRINT <a href="https://forum.mibuso.com/profile/CMD1" rel="nofollow">@CMD1</a><br />
EXEC (<a href="https://forum.mibuso.com/profile/CMD1%29" rel="nofollow">@CMD1)</a><br />
WAITFOR DELAY '00:00:20';<br /><br />
CONTINUE<br />
END<br />
END<br />
ELSE<br />
PRINT 'ONDER DE 28']]>
        </description>
    </item>
    <item>
        <title>SQL Server Query Hash Statistics</title>
        <link>https://forum.mibuso.com/discussion/47176/sql-server-query-hash-statistics</link>
        <pubDate>Tue, 26 Apr 2011 12:37:10 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>kriki</dc:creator>
        <guid isPermaLink="false">47176@/discussions</guid>
        <description><![CDATA[In short:<br />
-it is a new feature in SQL2008 that came in late and therefore generated little fuss.<br />
-It has very little impact on SQL server performance but can give you a lot of info about slow queries.<br />
-there is a tool to monitor Hash stats on 1 or more SQL servers.<br /><br />
Here are some links with more detailed info:<br />
-<a rel="nofollow" href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Farchive.msdn.microsoft.com%2FQueryHashStatistics%2FWiki%2FView.aspx%3Ftitle%3DQhsQuickStart%26referringTitle%3DHome">http://archive.msdn.microsoft.com/QueryHashStatistics/Wiki/View.aspx?title=QhsQuickStart&amp;referringTitle=Home</a><br />
-<a rel="nofollow" href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Farchive.msdn.microsoft.com%2FQueryHashStatistics%2FRelease%2FProjectReleases.aspx%3FReleaseId%3D5272">http://archive.msdn.microsoft.com/QueryHashStatistics/Release/ProjectReleases.aspx?ReleaseId=5272</a><br />
-<a rel="nofollow" href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Fblogs.msdn.com%2Fb%2Fbartd%2Farchive%2F2008%2F09%2F03%2Fquery-fingerprints-and-plan-fingerprints_3a00_-the-best-new-sql-2008-feature-you_2700_ve-never-heard-of.aspx">http://blogs.msdn.com/b/bartd/archive/2008/09/03/query-fingerprints-and-plan-fingerprints_3a00_-the-best-new-sql-2008-feature-you_2700_ve-never-heard-of.aspx</a><br />
-<a rel="nofollow" href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Fwww.sqlmag.com%2Farticle%2Fperformance-tuning%2Fsql-server-query-hash-statistics-129828%3Futm_source%3Dfeedburner%26utm_medium%3Dfeed%26utm_campaign%3DFeed%253A%2Bwindowsitpro%252FPtva%2B%2528SQL%253EArticles%253ETop%2BStories%2529">http://www.sqlmag.com/article/performance-tuning/sql-server-query-hash-statistics-129828?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed:+windowsitpro/Ptva+(SQL&gt;Articles&gt;Top+Stories)</a>]]>
        </description>
    </item>
    <item>
        <title>Free eBook on SQL Server Maintenance Plans from Brad M. McGe</title>
        <link>https://forum.mibuso.com/discussion/42904/free-ebook-on-sql-server-maintenance-plans-from-brad-m-mcge</link>
        <pubDate>Sat, 31 Jul 2010 14:09:12 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>kriki</dc:creator>
        <guid isPermaLink="false">42904@/discussions</guid>
        <description><![CDATA[I downloaded it and read it. Definitely a good book for beginning DBA's.<br /><br />
You can download it here: <a href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Fwww.bradmcgehee.com%2F2010%2F01%2Ffree-ebook-on-sql-server-maintenance-plans-now-available%2F" rel="nofollow">http://www.bradmcgehee.com/2010/01/free-ebook-on-sql-server-maintenance-plans-now-available/</a>]]>
        </description>
    </item>
    <item>
        <title>Poor performance Dynamics NAV 500SP1 + SQL Server 2008</title>
        <link>https://forum.mibuso.com/discussion/41988/poor-performance-dynamics-nav-500sp1-sql-server-2008</link>
        <pubDate>Fri, 11 Jun 2010 09:08:05 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>jsoage</dc:creator>
        <guid isPermaLink="false">41988@/discussions</guid>
        <description><![CDATA[After migrating SQL Server from 2000 to 2008 I had a lot of problems with performance and locks.  ](*,)<br /><br />
I found some information that helped me to solve this problems \:D/  and hope it can help any others.<br /><br /><b>First I needed to identify the resources consuming queries</b>:
<pre spellcheck="false" tabindex="0">SELECT TOP 30 -- You can change number of lines
  st.text,
  qs.last_execution_time,
  SUBSTRING(st.text, (qs.statement_start_offset/2) + 1, ((CASE statement_end_offset 
                                                            WHEN -1 THEN DATALENGTH(st.text)
                                                            ELSE qs.statement_end_offset END 
                                                          - qs.statement_start_offset)/2) + 1) as statement_text,
  execution_count,
  case  
    when execution_count = 0 then null
    else total_logical_reads/execution_count 
  end as avg_logical_reads, 
  last_logical_reads,
  min_logical_reads,
  max_logical_reads,
  case  
    when execution_count = 0 then null
    else total_logical_writes/execution_count 
  end as avg_logical_writes, 
  last_logical_writes,
  min_logical_writes,
  max_logical_writes,
  max_elapsed_time  
FROM sys.dm_exec_query_stats as qs
  CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as st
WHERE qs.last_execution_time &gt;= dateadd(day, -1, getdate()) -- You can change the datepart and number
ORDER BY max_logical_reads DESC -- You can change to max_logical_writes
</pre>
<br /><b>And then tell Dynamics NAV when to force SQL to use an specific index</b><br />
You can find this information in Dynamics NAV documentation (w1w1adg.pdf - Performance / 30.4 Keys, Queries and Performance (Index hinting))<br />
or in <a href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fdd355052.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/dd355052.aspx</a><br /><br />
Hope it helps]]>
        </description>
    </item>
    <item>
        <title>Import Object - SQL Error 15333 -</title>
        <link>https://forum.mibuso.com/discussion/16723/import-object-sql-error-15333</link>
        <pubDate>Thu, 22 Feb 2007 22:55:16 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>danl</dc:creator>
        <guid isPermaLink="false">16723@/discussions</guid>
        <description><![CDATA[Hi All,<br /><br />
I am trying to import an object to Navsion but I encountered a below error.<br /><br />
“The following SQL server error(s) occurred while accessing the AvailabilityTable:<br /><br />
15333, “42000”, [Microsoft][ODBC SQL Server Driver][SQL Server] Error: the qualified <a href="https://forum.mibuso.com/profile/oldname" rel="nofollow">@oldname</a> references database (Databasename) other than the current database.”<br /><br />
Thank you in advance the help.]]>
        </description>
    </item>
    <item>
        <title>Some useful links on SQL-installation, disk-configurati, SAN</title>
        <link>https://forum.mibuso.com/discussion/41131/some-useful-links-on-sql-installation-disk-configurati-san</link>
        <pubDate>Sat, 17 Apr 2010 15:23:20 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>kriki</dc:creator>
        <guid isPermaLink="false">41131@/discussions</guid>
        <description><![CDATA[<a href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Fsqlblog.com%2Fblogs%2Fjoe_chang%2Farchive%2F2008%2F03%2F04%2Fstorage-performance-for-sql-server.aspx" rel="nofollow">http://sqlblog.com/blogs/joe_chang/archive/2008/03/04/storage-performance-for-sql-server.aspx</a><br /><a href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Fsqlcat.com%2Ftop10lists%2Farchive%2F2007%2F11%2F21%2Fstorage-top-10-best-practices.aspx" rel="nofollow">http://sqlcat.com/top10lists/archive/2007/11/21/storage-top-10-best-practices.aspx</a><br /><a href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Fkendalvandyke.blogspot.com%2F2009%2F02%2Fdisk-performance-hands-on-series-recap.html" rel="nofollow">http://kendalvandyke.blogspot.com/2009/02/disk-performance-hands-on-series-recap.html</a><br /><a href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Fwww.sql-server-performance.com%2Farticles%2Faudit%2F2005_audit_hardware_checklist_p2.aspx" rel="nofollow">http://www.sql-server-performance.com/articles/audit/2005_audit_hardware_checklist_p2.aspx</a><br /><a href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fdd758814.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/dd758814.aspx</a><br /><a href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Fsqlblog.com%2Fblogs%2Fmerrill_aldrich%2Farchive%2F2009%2F07%2F26%2Fsan-disk-array-performance-beware-lun-concatenation.aspx" rel="nofollow">http://sqlblog.com/blogs/merrill_aldrich/archive/2009/07/26/san-disk-array-performance-beware-lun-concatenation.aspx</a><br /><a href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Ftechnet.microsoft.com%2Fen-us%2Flibrary%2Fcc966412.aspx" rel="nofollow">http://technet.microsoft.com/en-us/library/cc966412.aspx</a><br /><a href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Fitknowledgeexchange.techtarget.com%2Fsql-server%2Fgiving-your-virtual-sql-server-direct-access-to-your-storage-array%2F" rel="nofollow">http://itknowledgeexchange.techtarget.com/sql-server/giving-your-virtual-sql-server-direct-access-to-your-storage-array/</a><br /><a href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Fsqlblog.com%2Fblogs%2Fjonathan_kehayias%2Farchive%2F2010%2F03%2F22%2Fsql-server-installation-checklist.aspx" rel="nofollow">http://sqlblog.com/blogs/jonathan_kehayias/archive/2010/03/22/sql-server-installation-checklist.aspx</a>]]>
        </description>
    </item>
    <item>
        <title>Using ADO to kick-off SQL jobs from NAV</title>
        <link>https://forum.mibuso.com/discussion/35843/using-ado-to-kick-off-sql-jobs-from-nav</link>
        <pubDate>Fri, 17 Jul 2009 20:55:48 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>bbrown</dc:creator>
        <guid isPermaLink="false">35843@/discussions</guid>
        <description><![CDATA[The sample code below is an example of how ADO can be used to kick-off a SQL Agent job from NAV.  This can be helpful when you need to run things but they don't fit into a fixed schedule.  This particular code is called from Adjust Cost, but I'm sure there are other uses.  It allows us to run nightly SQL maintenance following the completion of Adjust Cost.<br /><br /><pre spellcheck="false" tabindex="0">Name	                     DataType	        Subtype	        Length
ADOConnection	        Automation	        'Microsoft ActiveX Data Objects 2.8 Library'.Connection	
GLSetup	                     Record	        General Ledger Setup	
ADOCommand	        Automation	        'Microsoft ActiveX Data Objects 2.8 Library'.Command	
ADOParameter	        Automation	         'Microsoft ActiveX Data Objects 2.8 Library'.Parameter	
lvarActiveConnection      Variant		


OnRun()
IF ISCLEAR(ADOConnection) THEN;
  CREATE(ADOConnection);

ADOConnection.ConnectionString := GetConnectionString;
ADOConnection.Open;

IF ISCLEAR(ADOCommand) THEN
  CREATE(ADOCommand);

lvarActiveConnection := ADOConnection;
ADOCommand.ActiveConnection := lvarActiveConnection;

ADOCommand.CommandText := 'sp_start_job';
ADOCommand.CommandType := 4;
ADOCommand.CommandTimeout := 0;

ADOParameter := ADOCommand.CreateParameter('@job_name', 200, 1, 50, GLSetup."Index Job Name");
ADOCommand.Parameters.Append(ADOParameter);
ADOCommand.Execute;

ADOConnection.Close;
---------------------

GetConnectionString() : Text[1024]
GLSetup.GET;
GLSetup.TESTFIELD("Server Name");
GLSetup.TESTFIELD("Index Job Name");

ConnectString := 'Driver={SQL Native Client};'
      + 'Server=' + GLSetup."Server Name" + ';'
      + 'Database=msdb;Trusted_Connection=yes;';
EXIT(ConnectString);

</pre>
]]>
        </description>
    </item>
    <item>
        <title>Backup compression in SQL Server 2008 R2 Standard</title>
        <link>https://forum.mibuso.com/discussion/38613/backup-compression-in-sql-server-2008-r2-standard</link>
        <pubDate>Sat, 28 Nov 2009 16:11:49 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>kriki</dc:creator>
        <guid isPermaLink="false">38613@/discussions</guid>
        <description><![CDATA[Backup compression is available in SQL Sever 2008 R2 Standard!<br /><br />
Read more : <a href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Fwww.microsoft.com%2Fsqlserver%2F2008%2Fen%2Fus%2FR2-editions.aspx" rel="nofollow">http://www.microsoft.com/sqlserver/2008/en/us/R2-editions.aspx</a>]]>
        </description>
    </item>
    <item>
        <title>NAV Date table in SQL-statement</title>
        <link>https://forum.mibuso.com/discussion/38482/nav-date-table-in-sql-statement</link>
        <pubDate>Fri, 20 Nov 2009 17:04:53 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>kriki</dc:creator>
        <guid isPermaLink="false">38482@/discussions</guid>
        <description><![CDATA[And now that I am busy with recursion:<br /><pre spellcheck="false" tabindex="0">-- recursive CTE to generate numbers like the NAV date table

DECLARE @from AS DATE;
DECLARE @to AS DATE;

SET @from = '2009-01-16';
SET @to = '2009-03-20';


WITH DateTable ([The Date]) AS
(SELECT @to

 UNION ALL
  
 SELECT DATEADD(DAY,-1,[The Date])
 FROM DateTable
 WHERE DATEADD(DAY,-1,[The Date]) &gt;= @from
)
SELECT *
FROM DateTable
ORDER BY [The Date]
OPTION (MAXRECURSION 0)
</pre>
<br />
See also <a href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Fmibuso.com%2Fblogs%2Fkriki%2F2009%2F11%2F20%2Fnav-date-table-in-sql-statement%2F" rel="nofollow">http://mibuso.com/blogs/kriki/2009/11/20/nav-date-table-in-sql-statement/</a>]]>
        </description>
    </item>
    <item>
        <title>NAV integer table in SQL-statement</title>
        <link>https://forum.mibuso.com/discussion/38481/nav-integer-table-in-sql-statement</link>
        <pubDate>Fri, 20 Nov 2009 16:35:10 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>kriki</dc:creator>
        <guid isPermaLink="false">38481@/discussions</guid>
        <description><![CDATA[If we want to loop on integers in NAV, we can use the integer table and put some filters on it.<br />
The problem is that in SQL, we don't have such a table.<br /><br />
It is possible to create the table with a recursive CTE (Common Table Expression).<br /><br />
If you want, you can also put the select into a stored procedure and use it.<br /><br />
This is the select:
<pre spellcheck="false" tabindex="0">-- recursive CTE to generate numbers like the NAV Integer table

DECLARE @from AS INTEGER;
DECLARE @to AS INTEGER;

SET @from = -100;
SET @to = 10;

WITH numbertable ([The Integer]) AS
(SELECT @to

 UNION ALL
  
 SELECT [The Integer] - 1
 FROM numbertable
 WHERE [The Integer] - 1 &gt;= @from
)
SELECT *
FROM numbertable
ORDER BY [The Integer]
OPTION (MAXRECURSION 0)
</pre>
<br />
See also : <a href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Fmibuso.com%2Fblogs%2Fkriki%2F2009%2F11%2F20%2Fnav-integer-table-in-sql-statement%2F" rel="nofollow">http://mibuso.com/blogs/kriki/2009/11/20/nav-integer-table-in-sql-statement/</a>]]>
        </description>
    </item>
    <item>
        <title>How to find out if you have sufficient memory on sql server</title>
        <link>https://forum.mibuso.com/discussion/37620/how-to-find-out-if-you-have-sufficient-memory-on-sql-server</link>
        <pubDate>Fri, 09 Oct 2009 15:45:24 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>ara3n</dc:creator>
        <guid isPermaLink="false">37620@/discussions</guid>
        <description><![CDATA[I saw this blog that had the query.<br /><br /><a href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Fblog.sqlauthority.com%2F2009%2F10%2F09%2Fsql-server-queries-waiting-for-memory-allocation-to-execute%2F" rel="nofollow">http://blog.sqlauthority.com/2009/10/09 ... o-execute/</a><br /><blockquote>

<div>SELECT TEXT, query_plan, requested_memory_kb,<br />
granted_memory_kb,used_memory_kb, wait_order<br />
FROM sys.dm_exec_query_memory_grants MG<br />
CROSS APPLY sys.dm_exec_sql_text(sql_handle)<br />
CROSS APPLY sys.dm_exec_query_plan(MG.plan_handle)</div>
</blockquote>
]]>
        </description>
    </item>
    <item>
        <title>Get I/O Stats directly from the SQLServer</title>
        <link>https://forum.mibuso.com/discussion/36656/get-i-o-stats-directly-from-the-sqlserver</link>
        <pubDate>Tue, 25 Aug 2009 07:47:37 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>garak</dc:creator>
        <guid isPermaLink="false">36656@/discussions</guid>
        <description><![CDATA[Here two little scripts, to get some I/O Stats from the SQLServer2005.<br />
For the script we use the "sys.dm_io_virtual_file_stats" which provides I/O statistics about database file<br /><br />
The two little script are based on this article --&gt; <a href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Fwww.sqlmag.com%2FArticles%2FPrint.cfm%3FArticleID%3D93327" rel="nofollow">http://www.sqlmag.com/Articles/Print.cf ... leID=93327</a><br /><br />
The First script calcs. the Percentage of I/O for every Database on your server<br /><pre spellcheck="false" tabindex="0">//we build us a temp. reultset
WITH IO_Stats_per_DB
AS
(
  SELECT
    DB_NAME(database_id) AS database_name,
    CAST(SUM(num_of_bytes_read + num_of_bytes_written) / 1048576.
         AS DECIMAL(12, 2)) AS io_in_mb
  FROM sys.dm_io_virtual_file_stats(NULL, NULL) AS DM_IO_Stats
  GROUP BY database_id
)

SELECT
  ROW_NUMBER() OVER(ORDER BY io_in_mb DESC) AS row_num, //we "create" a rowID
  database_name, io_in_mb, CAST(io_in_mb / SUM(io_in_mb) OVER() * 100  AS DECIMAL(5, 2)) AS pct //we create a percent coloumn
FROM IO_Stats_per_DB //we use the temp. reultset
ORDER BY row_num;
</pre>
<br />
The second script is to get the I/O stats by Drive. So you can find out, which disc is producing the most I/O. This could help to know, which database should remove to a other disk.<br /><pre spellcheck="false" tabindex="0">With IO_Stats_per_Drive as
(
  select db_name(mf.database_id) as database_name, mf.physical_name,
           left(mf.physical_name, 1) as drive_letter,
           vfs.num_of_writes,
           vfs.num_of_bytes_written as BYTESWRITTEN,
           vfs.io_stall_write_ms,
           mf.type_desc, 
           vfs.num_of_reads, 
           vfs.num_of_bytes_read, 
           vfs.io_stall_read_ms,
           vfs.io_stall, 
           vfs.size_on_disk_bytes
  from 
    sys.master_files mf
  join 
    sys.dm_io_virtual_file_stats(NULL, NULL) vfs
  on 
    mf.database_id=vfs.database_id and mf.file_id=vfs.file_id
)

select database_name,drive_letter, BYTESWRITTEN,
         Percentage = RTRIM(CONVERT(DECIMAL(5,2),
         BYTESWRITTEN*100.0/(SELECT SUM(BYTESWRITTEN) FROM IO_Stats_per_Drive))) + '%'
from 
  IO_Stats_per_Drive
order by 
  BYTESWRITTEN desc
</pre>
<br />
Regards]]>
        </description>
    </item>
    <item>
        <title>sql server introduction to joins basic of joins</title>
        <link>https://forum.mibuso.com/discussion/36599/sql-server-introduction-to-joins-basic-of-joins</link>
        <pubDate>Thu, 20 Aug 2009 07:08:06 +0000</pubDate>
        <category>SQL Tips &amp; Tricks</category>
        <dc:creator>kriki</dc:creator>
        <guid isPermaLink="false">36599@/discussions</guid>
        <description><![CDATA[This <a href="https://forum.mibuso.com/home/leaving?allowTrusted=1&amp;target=http%3A%2F%2Fblog.sqlauthority.com%2F2009%2F04%2F13%2Fsql-server-introduction-to-joins-basic-of-joins%2F" rel="nofollow">link</a> gives you a good overview what the different joins do.]]>
        </description>
    </item>
   </channel>
</rss>
