<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Dave's Blog</title><link>http://teachmenav.com/blogs/dave/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/teachmenav/dave" /><feedburner:info uri="teachmenav/dave" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.0/</creativeCommons:license><image><link>http://creativecommons.org/licenses/by-nc-sa/2.0/</link><url>http://creativecommons.org/images/public/somerights20.gif</url><title>Some Rights Reserved</title></image><item><title>Config File Gotcha</title><link>http://feedproxy.google.com/~r/teachmenav/dave/~3/tXpT71eHbsM/config-file-gotcha.aspx</link><pubDate>Fri, 03 Feb 2012 10:08:44 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:851</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/gotcha_5F00_2FD475BB.jpg"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="gotcha" border="0" alt="gotcha" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/gotcha_5F00_thumb_5F00_123274EF.jpg" width="244" height="184" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I came across something that was a bit weird in an implementation where every user in a Citrix deployed RoleTailored client suddenly connected to the TEST system instead of the LIVE system. I thought I’d share this gotcha to save others from making the same mistake.&lt;/p&gt;  &lt;p&gt;When you start Dynamics NAV 2009’s RoleTailored client, there are a three ways for the client to determine which server to connect to. This is handy to know because most people want to have a live system and a test system shortcut on their desktop and it’s nice to know where you’re going when you start the client.&lt;/p&gt;  &lt;h3&gt;Default ClientUserSettings.config&lt;/h3&gt;  &lt;p&gt;The first method is the default method where the system simply reads your settings from the ClientUserSettings.config file which you can find in &lt;/p&gt;  &lt;p&gt;%ProgramData%\Microsoft\Microsoft Dynamics NAV\&lt;/p&gt;  &lt;p&gt;That’s pretty easy because you don’t need to do anything. The file gets created automatically and if you connect to a different server, the new value gets saved in the file. Not very useful for switching between Live and Test though.&lt;/p&gt;  &lt;h3&gt;Startup .config file&lt;/h3&gt;  &lt;p&gt;This one’s pretty neat. When you start the client, you can add a command line parameter to specify the location of the config file you want to use. The parameter is settings and here’s an example of the shortcut you would need.&lt;/p&gt;  &lt;p&gt;Microsoft.Dynamics.Nav.Client.exe -settings:NavLive.config&lt;/p&gt;  &lt;p&gt;But this is where the gotcha comes in. If you use this settings file to start the client and then connect to a different server, the change gets written back to the config file. That’s not so good when you were trying to use different files to point you to either Live or Test systems. It’s even worse if you are using Citrix to publish the application and every user is updating the same config file. Whilst you don’t get errors, it can be a bit confusing if one user starts up the LIVE system and then jumps to the TEST server which writes the settings back to the config file so the next time a user tries to open the LIVE system they end up in TEST. One solution to this is to make the config files read-only, the other is to use the startup URI.&lt;/p&gt;  &lt;h3&gt;Startup URI&lt;/h3&gt;  &lt;p&gt;I quite like this option for a couple of reasons. First of all, it’s really obvious which system you’re connecting to. Secondly, if you’re connecting to a system that is not your default server (remember the ClientUserSettings.config file?) then the RTC puts up a helpful message telling you. This is great for having two shortcuts that will take you into live or test and it’s not going to mess with your ClientUserSettings.config file either.&lt;/p&gt;  &lt;p&gt;The syntax for the URI allows you to specify which company you want to start in too. You could use this to start up on a specific page if you like.&lt;/p&gt;  &lt;p&gt;Microsoft.Dynamics.Nav.Client.exe &amp;quot;dynamicsnav://NAVSERVER/ServiceName/CompanyName&amp;quot;&lt;/p&gt;  &lt;p&gt;The double quotes are needed if your company name contains spaces.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://teachmenav.com/aggbug.aspx?PostID=851" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/LaYHOemHuZE9EYjGTEIWPea7ryg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LaYHOemHuZE9EYjGTEIWPea7ryg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/LaYHOemHuZE9EYjGTEIWPea7ryg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LaYHOemHuZE9EYjGTEIWPea7ryg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/teachmenav/dave/~4/tXpT71eHbsM" height="1" width="1"/&gt;</description><category domain="http://teachmenav.com/blogs/dave/archive/tags/Gotcha/default.aspx">Gotcha</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/NAV+2009+SP1/default.aspx">NAV 2009 SP1</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/Tip/default.aspx">Tip</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/NAV+2009+R2/default.aspx">NAV 2009 R2</category><feedburner:origLink>http://teachmenav.com/blogs/dave/archive/2012/02/03/config-file-gotcha.aspx</feedburner:origLink></item><item><title>Service Tier and Classic Client Monstrous Nightmare with FieldRef</title><link>http://feedproxy.google.com/~r/teachmenav/dave/~3/GfaqCZ_XTXY/service-tier-and-classic-client-monstrous-nightmare-with-fieldref.aspx</link><pubDate>Fri, 12 Aug 2011 09:49:27 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:541</guid><dc:creator>David Roys</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://teachmenav.com/blogs/dave/rsscomments.aspx?PostID=541</wfw:commentRss><comments>http://teachmenav.com/blogs/dave/archive/2011/08/12/service-tier-and-classic-client-monstrous-nightmare-with-fieldref.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://www.daemonsmovies.com/wp-content/uploads/2010/01/monstrous-nightmare-01.jpg"&gt;&lt;img title="Monstrous Nightmare" alt="Monstrous Nightmare" src="http://s1.daemonsmovies.com/mov/up/2010/01/monstrous-nightmare-01-550x319.jpg" width="550" height="319" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I came across an error today that was a monstrous nightmare to track down. First of all, it worked in the Classic client but not in the RoleTailored client. Sigh. Don’t you just hate that? It means going through the pain of debugging the RoleTailored client. &lt;/p&gt;  &lt;p&gt;The error was caused because the FieldRef.Value function for a FieldRef that points to an Option type field returns different values in the Classic client and RoleTailored client.&lt;/p&gt;  &lt;p&gt;If you want proof, try running this Codeunit in both the RTC and Classic.&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;font face="Courier New"&gt;// ServiceTier returns different values for FieldRef.Value for Option      &lt;br /&gt;// fields compared to Classic client.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;lRecordRef.OPEN(DATABASE::&amp;quot;Sales Header&amp;quot;);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;lFieldRef := lRecordRef.FIELD(1);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;MESSAGE(&amp;#39;ISSERVICETIER=%1\Document Type=%2&amp;#39;,ISSERVICETIER,lFieldRef.VALUE);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;You’ll see the following results. Classic client first…&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_2154264A.png"&gt;&lt;img style="background-image:none;border-right-width:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_75372958.png" width="234" height="175" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Then the RoleTailored client…&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_5F010E06.png"&gt;&lt;img style="background-image:none;border-right-width:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_5A1E5A4A.png" width="230" height="135" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You see that? One returns the string value and the other returns the numeric value for the option string.&lt;/p&gt;  &lt;p&gt;The error we were getting was because the field was being used as an Integer which was throwing a run time error whenever it hit that particular bit of code but only when using the RTC.&lt;/p&gt;  &lt;p&gt;Most of the time in finding this error was in tracking down the line of code that was causing the error to be thrown. I was reading the Statement of Direction for NAV the other day and noticed it suggests we’ll be getting an easy-to-use debugger for the RTC in a future version – I can’t wait! Let’s hope in the future I can say “break on error” and just run my RoleTailored client and find out what the issue is straight away.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://teachmenav.com/aggbug.aspx?PostID=541" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/gM3P9sIaQCtWzw5WfgxTdfKbUm0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gM3P9sIaQCtWzw5WfgxTdfKbUm0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/gM3P9sIaQCtWzw5WfgxTdfKbUm0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gM3P9sIaQCtWzw5WfgxTdfKbUm0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/teachmenav/dave/~4/GfaqCZ_XTXY" height="1" width="1"/&gt;</description><category domain="http://teachmenav.com/blogs/dave/archive/tags/Programming/default.aspx">Programming</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/Gotcha/default.aspx">Gotcha</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/Tip/default.aspx">Tip</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/NAV+2009+R2/default.aspx">NAV 2009 R2</category><feedburner:origLink>http://teachmenav.com/blogs/dave/archive/2011/08/12/service-tier-and-classic-client-monstrous-nightmare-with-fieldref.aspx</feedburner:origLink></item><item><title>Creating New Windows Logins in NAV Through a SQL Sproc</title><link>http://feedproxy.google.com/~r/teachmenav/dave/~3/OFCWhZse9-c/creating-new-windows-logins-in-nav-through-a-sql-sproc.aspx</link><pubDate>Sat, 23 Jul 2011 09:02:42 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:531</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://teachmenav.com/blogs/dave/rsscomments.aspx?PostID=531</wfw:commentRss><comments>http://teachmenav.com/blogs/dave/archive/2011/07/23/creating-new-windows-logins-in-nav-through-a-sql-sproc.aspx#comments</comments><description>&lt;p&gt;If you’ve been following my on-going battle against the pigs, you’ll be pleased to know that I now have attained three stars on all of the levels in Angry Birds Seasons, Angry Birds, and Angry Birds Rio, so with no more pigs to kill until the next update, I figured I’d write another NAV blog.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/photo_5F00_39C3F057.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="photo" border="0" alt="photo" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/photo_5F00_thumb_5F00_0109207D.png" width="244" height="164" /&gt;&lt;/a&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/photo1_5F00_442478DD.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="photo1" border="0" alt="photo1" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/photo1_5F00_thumb_5F00_5F995513.png" width="244" height="164" /&gt;&lt;/a&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/photo2_5F00_7C52CA28.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="photo2" border="0" alt="photo2" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/photo2_5F00_thumb_5F00_1CAA5A1B.png" width="244" height="164" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;One of the reasons I started blogging was to have a place where I could save little gems so they can be easily found later on. One of the directors at Intergen suggested that I blogged the information and then use Google to find it – so that’s what I did. This week I needed to find something I knew I’d done before, but it took me quite a while to track it down, so I figured it’s time to blog the solution so I need never struggle again – and who knows, it may help some of you out too.&lt;/p&gt;  &lt;p&gt;Have you ever had a SQL Backup to restore to a SQL Server that does not allow mixed mode (no database logins, only Windows users) and you need to open the NAV database using NAV but don’t have a login? I created the following SQL code to do this, but you may find it useful to be able quickly add all of the Windows users for your team to a customer’s database. Or how about using the ability to call SQL Stored Procs from NAV (recently blogged about by &lt;a href="http://dynamicsuser.net/blogs/waldo/archive/2011/07/19/net-interop-calling-stored-procedures-on-sql-server-example-1.aspx"&gt;Waldo&lt;/a&gt;) to allow new Windows users to be added to NAV from the RoleTailored client – now that sounds useful!&lt;/p&gt;  &lt;h4&gt;Don’t forget to tell SID&lt;/h4&gt;  &lt;p&gt;NAV stores security for Windows users with a SID which is a funny string that starts with “S” and the first thing I need is something that will give me the SID string for a Windows login.&lt;/p&gt;  &lt;p&gt;Create the following function in the master database.&lt;/p&gt; &lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;USE&lt;/span&gt; master     &lt;br /&gt;GO     &lt;br /&gt;&lt;span style="color:blue;"&gt;CREATE&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;FUNCTION&lt;/span&gt; fn_SIDToString     &lt;br /&gt;(     &lt;br /&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@BinSID&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;VARBINARY&lt;/span&gt;(100)     &lt;br /&gt;)     &lt;br /&gt;RETURNS &lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(100)     &lt;br /&gt;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160; &lt;br /&gt;&amp;#160;&lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;IF&lt;/span&gt;&amp;#160;&lt;span style="color:#ff00dc;"&gt;LEN&lt;/span&gt;(&lt;span style="color:#8b0000;"&gt;@BinSID&lt;/span&gt;)%4&amp;lt;&amp;gt;0 &lt;span style="color:blue;"&gt;RETURN&lt;/span&gt;(&lt;span style="color:#a9a9a9;"&gt;NULL&lt;/span&gt;)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@StringSID&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(100)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@i&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;INT&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@j&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;INT&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@StringSID&lt;/span&gt;=&lt;span style="color:red;"&gt;&amp;#39;S-&amp;#39;&lt;/span&gt;+&lt;span style="color:blue;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;,&lt;span style="color:blue;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:blue;"&gt;INT&lt;/span&gt;,&lt;span style="color:blue;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:blue;"&gt;VARBINARY&lt;/span&gt;,&lt;span style="color:#ff00dc;"&gt;SUBSTRING&lt;/span&gt;(&lt;span style="color:#8b0000;"&gt;@BinSID&lt;/span&gt;,1,1))))     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@StringSID&lt;/span&gt;=&lt;span style="color:#8b0000;"&gt;@StringSID&lt;/span&gt;+&lt;span style="color:red;"&gt;&amp;#39;-&amp;#39;&lt;/span&gt;+&lt;span style="color:blue;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;,&lt;span style="color:blue;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:blue;"&gt;INT&lt;/span&gt;,&lt;span style="color:blue;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:blue;"&gt;VARBINARY&lt;/span&gt;,&lt;span style="color:#ff00dc;"&gt;SUBSTRING&lt;/span&gt;(&lt;span style="color:#8b0000;"&gt;@BinSID&lt;/span&gt;,3,6))))     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@j&lt;/span&gt;=9     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@i&lt;/span&gt;=&lt;span style="color:#ff00dc;"&gt;LEN&lt;/span&gt;(&lt;span style="color:#8b0000;"&gt;@BinSID&lt;/span&gt;)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;WHILE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@j&lt;/span&gt;&amp;lt;&lt;span style="color:#8b0000;"&gt;@i&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@val&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;BINARY&lt;/span&gt;(4)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@val&lt;/span&gt;=&lt;span style="color:#ff00dc;"&gt;SUBSTRING&lt;/span&gt;(&lt;span style="color:#8b0000;"&gt;@BinSID&lt;/span&gt;,&lt;span style="color:#8b0000;"&gt;@j&lt;/span&gt;,4)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@StringSID&lt;/span&gt;=&lt;span style="color:#8b0000;"&gt;@StringSID&lt;/span&gt;+&lt;span style="color:red;"&gt;&amp;#39;-&amp;#39;&lt;/span&gt;+&lt;span style="color:blue;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;,&lt;span style="color:blue;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:blue;"&gt;BIGINT&lt;/span&gt;,&lt;span style="color:blue;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:blue;"&gt;VARBINARY&lt;/span&gt;,&lt;span style="color:#ff00dc;"&gt;REVERSE&lt;/span&gt;(&lt;span style="color:blue;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:blue;"&gt;VARBINARY&lt;/span&gt;,&lt;span style="color:#8b0000;"&gt;@val&lt;/span&gt;)))))     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@j&lt;/span&gt;=&lt;span style="color:#8b0000;"&gt;@j&lt;/span&gt;+4     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;END&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;RETURN&lt;/span&gt;(&lt;span style="color:#8b0000;"&gt;@StringSID&lt;/span&gt;)     &lt;br /&gt;&lt;span style="color:blue;"&gt;END&lt;/span&gt;     &lt;br /&gt;&lt;/code&gt;  &lt;h4&gt;Between a Sproc and a Hard Place&lt;/h4&gt;  &lt;p&gt;Once you have this function, the following stored procedure will create a Windows Login, add it as a windows user, and finally make the user a member of the SUPER role. I’ve hard-coded the database name in this sproc, but you should be able to easily make this a parameter to the sproc if you wish.&lt;/p&gt; &lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;CREATE&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;PROCEDURE&lt;/span&gt; [dbo].[proc_CreateNavUser]    &lt;br /&gt;&lt;span style="color:#8b0000;"&gt;@User&lt;/span&gt;&amp;#160; &lt;span style="color:blue;"&gt;sysname&lt;/span&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160; &lt;br /&gt;&lt;span style="color:blue;"&gt;SET&lt;/span&gt; NOCOUNT &lt;span style="color:blue;"&gt;ON&lt;/span&gt;    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQL&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(&lt;span style="color:#ff00dc;"&gt;MAX&lt;/span&gt;)    &lt;br /&gt;&lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@RetVal&lt;/span&gt; INTEGER    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@RetVal&lt;/span&gt;=0    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt; TRY    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;IF&lt;/span&gt;(&lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&lt;span style="color:#ff00dc;"&gt;COUNT&lt;/span&gt;(*)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FROM&lt;/span&gt; master.sys.server_principals    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;WHERE&lt;/span&gt; name=&lt;span style="color:#8b0000;"&gt;@User&lt;/span&gt;)=0    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQL&lt;/span&gt;=&lt;span style="color:red;"&gt;&amp;#39;use master CREATE LOGIN [&amp;#39;&lt;/span&gt;+&lt;span style="color:#8b0000;"&gt;@User&lt;/span&gt;+&lt;span style="color:red;"&gt;&amp;#39;] FROM WINDOWS WITH DEFAULT_DATABASE=[master]&amp;#39;&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;EXECUTE&lt;/span&gt;(&lt;span style="color:#8b0000;"&gt;@SQL&lt;/span&gt;);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;END&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;IF&lt;/span&gt;(&lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&lt;span style="color:#ff00dc;"&gt;COUNT&lt;/span&gt;(*)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FROM&lt;/span&gt; [Demo &lt;span style="color:blue;"&gt;Database&lt;/span&gt; NAV (6-0)].sys.database_principals    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;WHERE&lt;/span&gt; name=&lt;span style="color:#8b0000;"&gt;@User&lt;/span&gt;)=0    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQL&lt;/span&gt;=&lt;span style="color:red;"&gt;&amp;#39;use [Demo Database NAV (6-0)] CREATE USER [&amp;#39;&lt;/span&gt;+&lt;span style="color:#8b0000;"&gt;@User&lt;/span&gt;+&lt;span style="color:red;"&gt;&amp;#39;] FOR LOGIN [&amp;#39;&lt;/span&gt;+&lt;span style="color:#8b0000;"&gt;@User&lt;/span&gt;+&lt;span style="color:red;"&gt;&amp;#39;]&amp;#39;&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;EXECUTE&lt;/span&gt;(&lt;span style="color:#8b0000;"&gt;@SQL&lt;/span&gt;);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;END&lt;/span&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;END&lt;/span&gt; TRY    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt; CATCH    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SELECT&lt;/span&gt; Retval=&lt;span style="color:#8b0000;"&gt;@RetVal&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;RETURN&lt;/span&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;END&lt;/span&gt; CATCH    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt; TRY    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@RetVal&lt;/span&gt;=1    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;INSERT&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;INTO&lt;/span&gt; [Demo &lt;span style="color:blue;"&gt;Database&lt;/span&gt; NAV (6-0)].dbo.[Windows Login]([SID])    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SELECT&lt;/span&gt; master.dbo.fn_SIDToString(sp.sid)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FROM&lt;/span&gt; master.sys.server_principals sp    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;WHERE&lt;/span&gt; sp.name=&lt;span style="color:#8b0000;"&gt;@User&lt;/span&gt;&amp;#160;&lt;span style="color:gray;"&gt;AND&lt;/span&gt; master.dbo.fn_SIDToString(sp.sid) &lt;span style="color:gray;"&gt;NOT&lt;/span&gt;&amp;#160;&lt;span style="color:gray;"&gt;IN&lt;/span&gt;(&lt;span style="color:blue;"&gt;SELECT&lt;/span&gt; sid    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FROM&lt;/span&gt; [Demo &lt;span style="color:blue;"&gt;Database&lt;/span&gt; NAV (6-0)].dbo.[Windows Login])    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&lt;span style="color:#008000;"&gt;--Add Roles (SUPER)&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;INSERT&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;INTO&lt;/span&gt; [Demo &lt;span style="color:blue;"&gt;Database&lt;/span&gt; NAV (6-0)].dbo.[Windows Access Control]([Login SID],[Role ID],[Company Name])    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SELECT&lt;/span&gt; master.dbo.fn_SIDToString(sp.sid),&lt;span style="color:red;"&gt;&amp;#39;SUPER&amp;#39;&lt;/span&gt;,&lt;span style="color:red;"&gt;&amp;#39;&amp;#39;&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FROM&lt;/span&gt; master.sys.server_principals sp    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;WHERE&lt;/span&gt; sp.name=&lt;span style="color:#8b0000;"&gt;@User&lt;/span&gt;&amp;#160;&lt;span style="color:gray;"&gt;AND&lt;/span&gt; master.dbo.fn_SIDToString(sp.sid) &lt;span style="color:gray;"&gt;NOT&lt;/span&gt;&amp;#160;&lt;span style="color:gray;"&gt;IN&lt;/span&gt;(&lt;span style="color:blue;"&gt;SELECT&lt;/span&gt; [Login SID]    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FROM&lt;/span&gt; [Demo &lt;span style="color:blue;"&gt;Database&lt;/span&gt; NAV (6-0)].dbo.[Windows Access Control]    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;WHERE&lt;/span&gt; [Role ID]=&lt;span style="color:red;"&gt;&amp;#39;BASIC&amp;#39;&lt;/span&gt;)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SELECT&lt;/span&gt; Retval=&lt;span style="color:#8b0000;"&gt;@RetVal&lt;/span&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;END&lt;/span&gt; TRY    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt; CATCH    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&lt;span style="color:blue;"&gt;END&lt;/span&gt; CATCH    &lt;br /&gt;&lt;/code&gt;  &lt;p&gt;Enjoy the srpoc. If you do write something that uses this – like a tool to create Windows logins in the RoleTailored client, why not share your solution too?&lt;/p&gt;  &lt;p&gt;Now it’s time to play Cut the Rope.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://teachmenav.com/aggbug.aspx?PostID=531" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zR2BSYdDI2t0Avs4-8FDC4xUqlg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zR2BSYdDI2t0Avs4-8FDC4xUqlg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zR2BSYdDI2t0Avs4-8FDC4xUqlg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zR2BSYdDI2t0Avs4-8FDC4xUqlg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/teachmenav/dave/~4/OFCWhZse9-c" height="1" width="1"/&gt;</description><category domain="http://teachmenav.com/blogs/dave/archive/tags/Programming/default.aspx">Programming</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/NAV+2009+SP1/default.aspx">NAV 2009 SP1</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/NAV+2009/default.aspx">NAV 2009</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/Tip/default.aspx">Tip</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/SQL/default.aspx">SQL</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/NAV+2009+R2/default.aspx">NAV 2009 R2</category><feedburner:origLink>http://teachmenav.com/blogs/dave/archive/2011/07/23/creating-new-windows-logins-in-nav-through-a-sql-sproc.aspx</feedburner:origLink></item><item><title>Make me squeal</title><link>http://feedproxy.google.com/~r/teachmenav/dave/~3/z5aqDYXT1PM/make-me-squeal.aspx</link><pubDate>Mon, 20 Jun 2011 10:07:14 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:510</guid><dc:creator>David Roys</dc:creator><slash:comments>6</slash:comments><wfw:commentRss>http://teachmenav.com/blogs/dave/rsscomments.aspx?PostID=510</wfw:commentRss><comments>http://teachmenav.com/blogs/dave/archive/2011/06/20/make-me-squeal.aspx#comments</comments><description>&lt;p&gt;If God had wanted me to work, he wouldn’t have given me Angry Birds.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/photo_5F00_2A9CFBFF.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="photo" border="0" alt="photo" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/photo_5F00_thumb_5F00_7B1E6765.png" width="244" height="164" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I figured it was about time I wrote something about Dynamics NAV again, so setting my continuing mission to get three stars on all levels to one side, I’ve finally taken time to pass on a couple of tips around .NET Interop and executing SQL Stored Procs from within NAV (I used to work with someone that pronounced SQL as “Squeal” instead of “Sequel” hence the title of this post).&lt;/p&gt;  &lt;p&gt;Way back in April (wow has it been that long?) I wrote about how you could &lt;a href="http://teachmenav.com/blogs/dave/archive/2011/04/13/execute-sql-command-using-net-interop.aspx"&gt;use .NET Interop to execute SQL commands&lt;/a&gt; using NAV 2009 R2. In my example I executed a simple SQL command and showed how you could parse the dataset returned from the command.&lt;/p&gt;  &lt;p&gt;When I finally came to put this into practice I discovered I had made two errors in my original post which proved to me that I am better at Angry Birds than I am at NAV programming and that, whilst I get many people reading my blog, it’s rare that people actually try out the things I write about.&lt;/p&gt;  &lt;h4&gt;The Host with the Most&lt;/h4&gt;  &lt;p&gt;My first mistake was when I said that I would use the session table to get the machine name of the SQL Server. Wrong! Yes it worked in my example, but that was only because I was running the NAV Server on the same box as the SQL Server. The “Host Name” field on the Session table is the machine name that initiated the connection, so when I moved my code to three tiers it didn’t work. So how do you find the name of the SQL Server you are connecting to?&lt;/p&gt;  &lt;p&gt;Here’s one way that works. I created a view that includes the server name like so:&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;CREATE VIEW [dbo].[SQLConnectionDetails] AS      &lt;br /&gt;SELECT @@ServerName AS [Server Name],       &lt;br /&gt;DB_NAME() AS [Database Name]&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Then I made a linked table in NAV over the top of the view. Now I can use SQLConnectionDetails.[Server Name] as part of my connect string. Phew!&lt;/p&gt;  &lt;h4&gt;Enum Nuts&lt;/h4&gt;  &lt;p&gt;My next mistake was when I assumed that the enumerated value for a SQL Stored Proc command type was 1. Wrong again! I’d made that assumption because the documentation on the &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.commandtype.aspx"&gt;properties of the CommandType&lt;/a&gt; showed a table with three options then they would be numbered 0, 1, and 2. Finding the correct integer value was not easy but in the end it was Waldo to the rescue. I knew I had read &lt;a href="http://dynamicsuser.net/blogs/waldo/archive/2011/04/19/nav-2009-r2-net-interop-using-enumerations-part-1.aspx"&gt;a post from Waldo about using enumerated types in .NET interop&lt;/a&gt; so I used his code to parse the value. Here’s how to do it for the SQL command type.&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;//Set the command type as StoredProcedure.      &lt;br /&gt;dnCommandType := dnSQLCommand.CommandType;       &lt;br /&gt;dnSQLCommand.CommandType := dnCommandType.Parse(dnCommandType.GetType(),&amp;#39;StoredProcedure&amp;#39;);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Much better to have this code that is self-documenting than put in the numeric values but if you’re feeling lazy, the number values are: Text is 1, StoredProcedure is 4 and TableDirect is 512.&lt;/p&gt;  &lt;h4&gt;Pulling my heir out&lt;/h4&gt;  &lt;p&gt;My final problem (not a mistake this time but something I thought I would pass on) was when I came to try to add parameters to my stored procedure I hit a problem I thought I couldn’t get past.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_7B5AEA9A.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_55F0F72C.png" width="424" height="232" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I could not instantiate a Parameter collection on my SQL Command because NAV thought for some crazy reason that there were two Parameters properties. Now .NET (as far as I know) does not support overloaded properties so this is not possible and I can only put it down to a bug in the R2 release. I have reported this to the product team and I am assured this problem will be fixed in a later release.&lt;/p&gt;  &lt;p&gt;So if I can’t add parameters to my stored proc, how can I get around it? My solution was to instantiate a variable of type System.Data.Common.DbCommand which the SQLCommand class inherits. I could then use the Parameters property of the Common.DbCommand and assign this to my SQLParameterCollection. Don’t you just love object oriented?&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;dnCommonDBCommand := dnSQLCommand;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;// Need to use the dnCommonDBCommand.Parameters becuase the SQLCommand.Parameters gets confused in the R2 Release      &lt;br /&gt;dnSQLParameterCollection := dnCommonDBCommand.Parameters();       &lt;br /&gt;dnSQLParameterCollection.Add(pParameterName,pParameterValue);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Now I have instantiated my SQLParameterCollection, I can use the Add method and add my new parameters.&lt;/p&gt;  &lt;p&gt;Well that’s it for now. Time to try to crack three stars on level 10. Die pigs, die!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://teachmenav.com/aggbug.aspx?PostID=510" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/HiSvbBd_qsWTHSPme2hh26PP--Y/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/HiSvbBd_qsWTHSPme2hh26PP--Y/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/HiSvbBd_qsWTHSPme2hh26PP--Y/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/HiSvbBd_qsWTHSPme2hh26PP--Y/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/teachmenav/dave/~4/z5aqDYXT1PM" height="1" width="1"/&gt;</description><category domain="http://teachmenav.com/blogs/dave/archive/tags/.NET/default.aspx">.NET</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/Programming/default.aspx">Programming</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/Gotcha/default.aspx">Gotcha</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/Tip/default.aspx">Tip</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/SQL/default.aspx">SQL</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/NAV+2009+R2/default.aspx">NAV 2009 R2</category><feedburner:origLink>http://teachmenav.com/blogs/dave/archive/2011/06/20/make-me-squeal.aspx</feedburner:origLink></item><item><title>20-30% Discount on Dynamics Books During May 2011</title><link>http://feedproxy.google.com/~r/teachmenav/dave/~3/jOmGwYZLmxI/20-30-discount-on-dynamics-books-during-may-2011.aspx</link><pubDate>Tue, 17 May 2011 07:25:11 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:509</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://teachmenav.com/blogs/dave/rsscomments.aspx?PostID=509</wfw:commentRss><comments>http://teachmenav.com/blogs/dave/archive/2011/05/17/20-30-discount-on-dynamics-books-during-may-2011.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://www.packtpub.com/article/exclusive-offer-microsoft-dynamics-books"&gt;&lt;img border="0" src="http://www.packtpub.com/sites/default/files/Dynamics%20May%20Logo.png" width="543" height="216" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Those people at PACKT have been busy making more and more books on Dynamics covering GP 2010, NAV 2009, AX 2009, and Sure Step, so whichever flavour of Dynamics you prefer, there’s something for you to get your teeth into.&lt;/p&gt;  &lt;p&gt;To celebrate the recent publication of the &lt;a href="https://www.packtpub.com/microsoft-dynamics-gp-2010-reporting/book?utm_source=microsoft_dynamics_may&amp;amp;utm_medium=campaign_page&amp;amp;utm_term=Microsoft%2BDynamics%2BGP%2B2010%2BReporting%3A%2BRAW&amp;amp;utm_campaign=enterprise"&gt;Microsoft Dynamics GP 2010 Reporting&lt;/a&gt; book, PACKT has announced a series of attractive discounts on their Dynamics books:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Buy any Microsoft Dynamics printbook and get 20% off &lt;/li&gt;    &lt;li&gt;Buy any Microsoft Dynamics eBook and get 30% off &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;So if you’ve been waiting to buy a copy of the book I wrote with Vjeko (&lt;a href="http://www.packtpub.com/implementing-microsoft-dynamics-nav-2009/book/mid/190109h5mbvn"&gt;Implementing Microsoft Dynamics NAV 2009&lt;/a&gt;) now’s your chance to order your copy and save some money. Our book has funny references and quotes, a comparison between the Chart of Accounts and a Hippo’s Bottom, and a section on how to perform analysis and design that uses super villains from a comic book as the users. There’s even some sensible stuff in there too. OK I’ll admit that some of the details about Web services is old news now and was written for NAV 2009, and there’s nothing on the things that came with SP1 and R2, but it’s a good fun read and, who knows, you might learn a thing or two along the way.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://teachmenav.com/aggbug.aspx?PostID=509" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/k7Di6a0btLBDdEKmyHBR2Z1jVsM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/k7Di6a0btLBDdEKmyHBR2Z1jVsM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/k7Di6a0btLBDdEKmyHBR2Z1jVsM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/k7Di6a0btLBDdEKmyHBR2Z1jVsM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/teachmenav/dave/~4/jOmGwYZLmxI" height="1" width="1"/&gt;</description><category domain="http://teachmenav.com/blogs/dave/archive/tags/Book+News/default.aspx">Book News</category><feedburner:origLink>http://teachmenav.com/blogs/dave/archive/2011/05/17/20-30-discount-on-dynamics-books-during-may-2011.aspx</feedburner:origLink></item><item><title>Execute SQL Command using .NET Interop</title><link>http://feedproxy.google.com/~r/teachmenav/dave/~3/YJCnmzhoQls/execute-sql-command-using-net-interop.aspx</link><pubDate>Wed, 13 Apr 2011 10:12:00 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:508</guid><dc:creator>David Roys</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://teachmenav.com/blogs/dave/rsscomments.aspx?PostID=508</wfw:commentRss><comments>http://teachmenav.com/blogs/dave/archive/2011/04/13/execute-sql-command-using-net-interop.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_7D0DD8E7.png"&gt;&lt;img height="44" width="126" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_10BAC27C.png" alt="image" border="0" title="image" style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;OK, I&amp;rsquo;ll admit it, I&amp;rsquo;m obsessed with the .NET Interop features in NAV 2009 R2. My last two blog posts have been on this and now here&amp;rsquo;s another one.&lt;/p&gt;
&lt;p&gt;Today I wanted to see if I could use the .NET Interop features in NAV 2009 R2 to execute a SQL Stored Procedure and extract the results. I know you can do this using COM, but I figured it would be fun to try this using .NET. The great thing about .NET is it&amp;rsquo;s so well documented. My starting point for this exercise was to search for executing a SQL Stored Procedure in C# which gave me this post &lt;a href="http://support.microsoft.com/kb/320916" title="http://support.microsoft.com/kb/320916"&gt;http://support.microsoft.com/kb/320916&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I then used that to figure out which .NET classes I needed to write my C/AL code.&lt;/p&gt;
&lt;p&gt;In this sample I&amp;rsquo;m using a SQL Command rather than a stored procedure call, but that&amp;rsquo;s just so you can try it for yourself easily without needing to create a stored procedure. It&amp;rsquo;s easy enough to change it to a stored procedure and I left the code in there but commented out.&lt;/p&gt;
&lt;p&gt;The worst thing about using this stuff is the number of variables you need to define. I put this down to the fact that the .NET interop does not support multi-dotting where I can write things like foo.bar.thing(). I&amp;rsquo;m hoping we&amp;rsquo;ll get multi-dotting in a future version.&lt;/p&gt;
&lt;p&gt;So for this to work, you&amp;rsquo;ll need to create a whole bunch of variables. Rather than list them here, I&amp;rsquo;ve included a text export of my Codeunit as a download.&lt;/p&gt;
&lt;p&gt;The example is really simple. I select the names of the companies in the current database and display the Row Count and then the first 5 company names.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s my code:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;//Use the session table to find the database and server name for the current connection &lt;br /&gt;Session.SETRANGE(&amp;quot;My Session&amp;quot;,TRUE); &lt;br /&gt;Session.FINDFIRST;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;//Open a connection using windows authentication to the current session database and server &lt;br /&gt;dnSQLConnection := dnSQLConnection.SqlConnection(&amp;#39;server=&amp;#39;+Session.&amp;quot;Host Name&amp;quot;+&amp;#39;;&amp;#39;+ &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#39;database=&amp;#39;+Session.&amp;quot;Database Name&amp;quot;+&amp;#39;;&amp;#39;+ &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#39;Trusted_Connection=sspi&amp;#39;);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;//Create a DataAdapter &lt;br /&gt;dnSQLDataAdapter := dnSQLDataAdapter.SqlDataAdapter();&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;{ &lt;br /&gt;// Example of using a stored procedure and not a select string&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;//Create a SQL Command on our connection &lt;br /&gt;dnSQLCommand := dnSQLCommand.SqlCommand(&amp;#39;myStoredProc&amp;#39;,dnSQLConnection); &lt;br /&gt;//Set the command type as StoredProcedure. &lt;br /&gt;dnSQLCommand.CommandType := 1; &lt;br /&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;//Create a SQL Command on our connection &lt;br /&gt;dnSQLCommand := dnSQLCommand.SqlCommand(&amp;#39;select * from Company&amp;#39;,dnSQLConnection);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;//Assign the SQL command as the select command on my data adapter. &lt;br /&gt;dnSQLDataAdapter.SelectCommand := dnSQLCommand;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;//Create a dataset &lt;br /&gt;dnDataSet := dnDataSet.DataSet;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;//Fill the dataset by executing my command on the data adapter. &lt;br /&gt;dnSQLDataAdapter.Fill(dnDataSet);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;//Get the collection of tables &lt;br /&gt;dnDataTableCollection := dnDataSet.Tables;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;//Get the first table &lt;br /&gt;dnDataTable := dnDataTableCollection.Item(0);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;//Get the collection of rows &lt;br /&gt;dnDataRowCollection := dnDataTable.Rows;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;MESSAGE(&amp;#39;There are %1 Rows&amp;#39;, dnDataRowCollection.Count);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;currentRow := 0;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;REPEAT &lt;br /&gt;&amp;nbsp; //Get the currentRow row &lt;br /&gt;&amp;nbsp; dnDataRow := dnDataRowCollection.Item(currentRow); &lt;br /&gt;&amp;nbsp; MESSAGE(&amp;#39;%1&amp;#39;,dnDataRow.Item(1)); &lt;br /&gt;&amp;nbsp; currentRow += 1; &lt;br /&gt;UNTIL (currentRow = 5) OR (currentRow = dnDataRowCollection.Count); &lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;//Tidy up &lt;br /&gt;dnSQLDataAdapter.Dispose(); &lt;br /&gt;dnSQLConnection.Close();&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In a New Zealand demo database this gives the following messages:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/SNAGHTML851fe47_5F00_7AF0DA1E.png"&gt;&lt;img height="134" width="193" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/SNAGHTML851fe47_5F00_thumb_5F00_55F319A5.png" alt="SNAGHTML851fe47" border="0" title="SNAGHTML851fe47" style="background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/SNAGHTML8524d6f_5F00_18EEE813.png"&gt;&lt;img height="133" width="244" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/SNAGHTML8524d6f_5F00_thumb_5F00_140C3457.png" alt="SNAGHTML8524d6f" border="0" title="SNAGHTML8524d6f" style="background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/SNAGHTML85295e4_5F00_2510623A.png"&gt;&lt;img height="133" width="244" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/SNAGHTML85295e4_5F00_thumb_5F00_4453090D.png" alt="SNAGHTML85295e4" border="0" title="SNAGHTML85295e4" style="background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You can download the Codeunit &lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/Call-SQL-from-.NET.txt"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://teachmenav.com/aggbug.aspx?PostID=508" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/oU6MDvx9RBsTYsGHxOuTIwcD06M/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/oU6MDvx9RBsTYsGHxOuTIwcD06M/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/oU6MDvx9RBsTYsGHxOuTIwcD06M/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/oU6MDvx9RBsTYsGHxOuTIwcD06M/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/teachmenav/dave/~4/YJCnmzhoQls" height="1" width="1"/&gt;</description><category domain="http://teachmenav.com/blogs/dave/archive/tags/.NET/default.aspx">.NET</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/Programming/default.aspx">Programming</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/SQL/default.aspx">SQL</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/NAV+2009+R2/default.aspx">NAV 2009 R2</category><feedburner:origLink>http://teachmenav.com/blogs/dave/archive/2011/04/13/execute-sql-command-using-net-interop.aspx</feedburner:origLink></item><item><title>.NET Interop—I’m Lovin’ It!</title><link>http://feedproxy.google.com/~r/teachmenav/dave/~3/cAQvOwhesOg/net-interop-i-m-lovin-it.aspx</link><pubDate>Wed, 16 Feb 2011 08:33:37 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:506</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://teachmenav.com/blogs/dave/rsscomments.aspx?PostID=506</wfw:commentRss><comments>http://teachmenav.com/blogs/dave/archive/2011/02/16/net-interop-i-m-lovin-it.aspx#comments</comments><description>&lt;p&gt;If this was a blog about grammar, I might be asking whether a verb like “to love” can be conjugated in a progressive tense to give us the phrase “I’m Lovin’ It”. But it’s not, it’s a blog about Dynamics NAV and I’m writing about .NET Interop in Dynamics NAV 2009 R2 which has got to be &lt;em&gt;the&lt;/em&gt; coolest feature for NAV ever!&lt;/p&gt;  &lt;p&gt;Let’s assume that you’re into Dynamics NAV and not dynamic verbs. The question I’m really asking here is how do you find the temporary path in Dynamics NAV? Easy, I hear your shout. You just use ENVIRON(‘TEMP’);&lt;/p&gt;  &lt;p&gt;Aha, but what if you’re using the RoleTailored client and you want to find the temp directory on the client? If you try using the ENVIRON command you’ll get the following error message:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_33B9D4BC.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_24A2F5E2.png" width="244" height="112" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Previously I solved this problem in quite a convoluted way. I created a temporary file (albeit an empty one) in the temporary path on the NAV Server, then I transferred it to the client using the&amp;#160; magic path, then I found the path of the location of the file where it got transferred to.&lt;/p&gt;  &lt;p&gt;Does that sound crazy? Take a look at the ClientTempFileName() function in the 3-Tier Automation Mgt. codeunit if you don’t believe me. I used that function to get a client temporary file and then used&amp;#160; the Path function to find the client temporary file path.&lt;/p&gt;  &lt;p&gt;But now with the .NET Interop there is a better way.&lt;/p&gt;  &lt;p&gt;Simply create a local variable of type DotNet and Subtype &amp;#39;mscorlib&amp;#39;.System.Environment. Make sure you bring up the properties of the variable and set the RunOnClient property to Yes.&lt;/p&gt;  &lt;p&gt;Now you can write code like this:&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;font face="Courier New"&gt;IF ISSERVICETIER THEN     &lt;br /&gt;&amp;#160; MESSAGE(&amp;#39;Temp is %1&amp;#39;,dnEnvironment.GetEnvironmentVariable(&amp;#39;temp&amp;#39;))      &lt;br /&gt;ELSE      &lt;br /&gt;&amp;#160; MESSAGE(&amp;#39;Temp is %1&amp;#39;,ENVIRON(&amp;#39;temp&amp;#39;));      &lt;br /&gt;EXIT;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Aaah. I’m Lovin’ It!&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;P.S. If you’re more interested in grammar than Dynamics NAV, check out &lt;a title="http://grammar.quickanddirtytips.com/im-loving-it-grammar.aspx" href="http://grammar.quickanddirtytips.com/im-loving-it-grammar.aspx"&gt;http://grammar.quickanddirtytips.com/im-loving-it-grammar.aspx&lt;/a&gt; to find out why McDonald’s slogan is such bad grammar.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://teachmenav.com/aggbug.aspx?PostID=506" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/txhXpSf7TGmaNCAPalKca3iPzlU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/txhXpSf7TGmaNCAPalKca3iPzlU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/txhXpSf7TGmaNCAPalKca3iPzlU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/txhXpSf7TGmaNCAPalKca3iPzlU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/teachmenav/dave/~4/cAQvOwhesOg" height="1" width="1"/&gt;</description><category domain="http://teachmenav.com/blogs/dave/archive/tags/.NET/default.aspx">.NET</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/Programming/default.aspx">Programming</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/NAV+2009+R2/default.aspx">NAV 2009 R2</category><feedburner:origLink>http://teachmenav.com/blogs/dave/archive/2011/02/16/net-interop-i-m-lovin-it.aspx</feedburner:origLink></item><item><title>Regular Expressions in NAV</title><link>http://feedproxy.google.com/~r/teachmenav/dave/~3/WdNhD8FOp9o/regular-expressions-in-nav.aspx</link><pubDate>Wed, 02 Feb 2011 07:32:55 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:458</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://teachmenav.com/blogs/dave/rsscomments.aspx?PostID=458</wfw:commentRss><comments>http://teachmenav.com/blogs/dave/archive/2011/02/02/regular-expressions-in-nav.aspx#comments</comments><description>&lt;p&gt;A friend of mine recently asked if there was a standard NAV function to find the first alphabetical character in a string. STRPOS comes close but you can&amp;#39;t say &amp;quot;tell me the first position for any one of these characters in this string&amp;quot; because it looks for an exact match of the substring and not any character from the substring.&lt;/p&gt;  &lt;p&gt;The AL code to do this isn&amp;#39;t hard but I figured this was a perfect excuse to play with the new .NET Interop feature in NAV 2009 R2.&lt;/p&gt;  &lt;p&gt;With the release of NAV 2009 R2, we have the ability to use the . NET Framework directly from within AL code. Now we can use simple .NET classes to do things with strings that previously required several lines of code. I&amp;#39;m thinking of regular expressions of course.&lt;/p&gt;  &lt;p&gt;The regular expression for any character between A and Z or a and z is [A-Z,a-z].&lt;/p&gt;  &lt;p&gt;I created a function in a Codeunit called RegExFind that takes two parameters (a string to be search and a string containing the regular expression to match on). It returns an Integer which is the matching position of the first matching character (it returns 0 if it doesn&amp;#39;t find a match).&lt;/p&gt;  &lt;p&gt;To run the code, you need to add the Codeunit to a RoleTailored MenuSuite as .NET Interop only works on the service tier. You could put this code in a button on a page too, if you wish.&lt;/p&gt;  &lt;p&gt;Here is the function:&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;font face="Courier New"&gt;RegExFind(SearchString : Text[250];RegEx : Text[250]) : Integer     &lt;br /&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;dnMatch := dnRegEx.Match(SearchString,RegEx);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;IF dnMatch.Success THEN      &lt;br /&gt;&amp;#160; EXIT(dnMatch.Index+1)      &lt;br /&gt;ELSE      &lt;br /&gt;&amp;#160; EXIT(0);      &lt;br /&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;In my Function I have the following local variables:&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="2" width="733"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="128"&gt;&lt;strong&gt;Name&lt;/strong&gt;&lt;/td&gt;        &lt;td valign="top" width="128"&gt;&lt;strong&gt;DataType&lt;/strong&gt;&lt;/td&gt;        &lt;td valign="top" width="475"&gt;&lt;strong&gt;Subtype&lt;/strong&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="125"&gt;dnRegEx&lt;/td&gt;        &lt;td valign="top" width="126"&gt;DotNet&lt;/td&gt;        &lt;td valign="top" width="480"&gt;&amp;#39;System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&amp;#39;.System.Text.RegularExpressions.Regex&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="123"&gt;dnMatch&lt;/td&gt;        &lt;td valign="top" width="126"&gt;DotNet&lt;/td&gt;        &lt;td valign="top" width="484"&gt;&amp;#39;System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&amp;#39;.System.Text.RegularExpressions.Match&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Notice that we return the Index +1 (as in .NET all arrays start at 0 where in AL they start at 1).&lt;/p&gt;  &lt;p&gt;The code to call the function is shown here:&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;font face="Courier New"&gt;SearchString := &amp;#39;1234 Lines of Code&amp;#39;;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;FoundPos := RegExFind(SearchString,&amp;#39;[a-z,A-Z]&amp;#39;);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;IF FoundPos &amp;gt; 0 THEN     &lt;br /&gt;&amp;#160; MESSAGE (&amp;#39;Found %1 at position %2 in %3&amp;#39;,COPYSTR(SearchString,FoundPos,1),FoundPos,SearchString);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;font face="Courier New"&gt;SearchString := &amp;#39;Now I look for 1 or 2 numbers.&amp;#39;;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;FoundPos := RegExFind(SearchString,&amp;#39;[0-9]&amp;#39;);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;IF FoundPos &amp;gt; 0 THEN     &lt;br /&gt;&amp;#160; MESSAGE (&amp;#39;Found %1 at position %2 in %3&amp;#39;,COPYSTR(SearchString,FoundPos,1),FoundPos,SearchString);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;As you would expect, when I run this Codeunit from my RoleTailored client, I get the following output:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_198D1D0F.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_38CFC3E2.png" width="330" height="134" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_7C37C544.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_306BEE8B.png" width="397" height="134" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The only problem with the new .NET Interop is knowing what&amp;#39;s out there in the framework. The chances are, there&amp;#39;s something to handle your requirement and the good news is there&amp;#39;ll be plenty of examples of how to use it - just as long as you can translate the C# code into an AL equivalent.&lt;/p&gt;  &lt;p&gt;This simple example is just the tip of the iceberg for what you can do with regular expressions. Wouldn&amp;#39;t it be nice to use regular expressions to validate user input?&lt;/p&gt;  &lt;p&gt;Have you got any favourite .NET tricks that you’d like to do in AL code?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://teachmenav.com/aggbug.aspx?PostID=458" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/JQ24iTmmtXGyGJXkmmmbBzGxaec/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/JQ24iTmmtXGyGJXkmmmbBzGxaec/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/JQ24iTmmtXGyGJXkmmmbBzGxaec/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/JQ24iTmmtXGyGJXkmmmbBzGxaec/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/teachmenav/dave/~4/WdNhD8FOp9o" height="1" width="1"/&gt;</description><category domain="http://teachmenav.com/blogs/dave/archive/tags/.NET/default.aspx">.NET</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/Programming/default.aspx">Programming</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/NAV+2009+R2/default.aspx">NAV 2009 R2</category><feedburner:origLink>http://teachmenav.com/blogs/dave/archive/2011/02/02/regular-expressions-in-nav.aspx</feedburner:origLink></item><item><title>Book Review: Microsoft Dynamics NAV Administration</title><link>http://feedproxy.google.com/~r/teachmenav/dave/~3/khTANID3bNc/book-review-microsoft-dynamics-nav-administration.aspx</link><pubDate>Fri, 31 Dec 2010 03:18:03 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:456</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://teachmenav.com/blogs/dave/rsscomments.aspx?PostID=456</wfw:commentRss><comments>http://teachmenav.com/blogs/dave/archive/2010/12/31/book-review-microsoft-dynamics-nav-administration.aspx#comments</comments><description>&lt;table border="0" cellspacing="0" cellpadding="2" width="551"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="213"&gt;&lt;a href="https://www.packtpub.com/microsoft-dynamics-nav-administration/book"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="8761EN_Microsoft Dynamics NAV Administration" border="0" alt="8761EN_Microsoft Dynamics NAV Administration" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/8761EN_5F00_Microsoft_2D00_Dynamics_2D00_NAV_2D00_Administration_5F00_37646415.jpg" width="198" height="244" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td valign="top" width="336"&gt;&lt;strong&gt;Authors:&lt;/strong&gt; Sharan Oberoi, Amit Sachdev           &lt;br /&gt;          &lt;br /&gt;&lt;strong&gt;Publisher:&lt;/strong&gt; PACKT           &lt;br /&gt;          &lt;br /&gt;&lt;strong&gt;ISBN:&lt;/strong&gt; 978-1-84719-876-1           &lt;br /&gt;          &lt;br /&gt;&lt;strong&gt;Published:&lt;/strong&gt; September 2010&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;Once upon a time you couldn’t get books on Dynamics NAV for love nor money, then in October 2007 PACKT published David Studebaker’s book &lt;em&gt;Programming Microsoft Dynamics NAV&lt;/em&gt;. I read David’s book and wrote a review (&lt;a title="http://gaspodethewonderdog.blogspot.com/2007/12/book-review-programming-microsoft.html" href="http://gaspodethewonderdog.blogspot.com/2007/12/book-review-programming-microsoft.html"&gt;http://gaspodethewonderdog.blogspot.com/2007/12/book-review-programming-microsoft.html&lt;/a&gt;) and became inspired to co-write my own book on Dynamics NAV.&lt;/p&gt;  &lt;p&gt;Things are very different now; there are loads of books on Dynamics NAV for everyone covering Programming, Implementing, Designing, Cooking, and now &lt;a href="https://www.packtpub.com/microsoft-dynamics-nav-administration/book"&gt;Administrating&lt;/a&gt;. OK so maybe not cooking, but there is a programming cookbook which I reviewed on this blog (&lt;a title="http://www.teachmenav.com/blogs/dave/archive/2010/11/28/book-review-microsoft-dynamics-nav-2009-programming-cookbook.aspx" href="http://www.teachmenav.com/blogs/dave/archive/2010/11/28/book-review-microsoft-dynamics-nav-2009-programming-cookbook.aspx"&gt;http://www.teachmenav.com/blogs/dave/archive/2010/11/28/book-review-microsoft-dynamics-nav-2009-programming-cookbook.aspx&lt;/a&gt;).&lt;/p&gt;  &lt;p&gt;With so many books around, you may be wondering what this new book from Canadian-based authors Sharan and Amit offers that can’t be found elsewhere. This is the first book on Dynamics NAV that appears to be aimed squarely at beginners. I can see how this book may appeal to someone who has landed a job with a company that uses Dynamics NAV and wants a quick guide to some of the capabilities of the product and a high level view of how to perform some admin tasks. The book covers essential tasks like creating new users and assigning security permissions, taking backups and restoring backups, and importing programming modifications from a FOB file delivered by a partner. This is all useful stuff for anyone working as a system administrator for NAV. There are only 175 pages (not including index and preface) spread over nine chapters with lots of screen images so it’s not going to take you long to read this.&lt;/p&gt;  &lt;p&gt;According to the blurb on the PACKT site, “this book is a tutorial guide that illustrates the steps needed to install, configure, deploy, and administer Dynamics NAV”. Dynamics NAV is a very complex system and this book does not even begin to cover all of the various tasks needed to install and configure the system, but if you need to know how to run the install wizard, this book will show you how to do it and give you a bit more of an idea of what is happening. There are some fundamental things missing, like how to configure the Service Principal Names (SPNs) needed to allow the system to run on three separate machines (SQL Server, NAV Server, and Client); however, this topic is well covered in the MSDN Library (&lt;a title="http://msdn.microsoft.com/en-us/library/dd301254.aspx?ppud=4" href="http://msdn.microsoft.com/en-us/library/dd301254.aspx?ppud=4"&gt;http://msdn.microsoft.com/en-us/library/dd301254.aspx?ppud=4&lt;/a&gt;).&lt;/p&gt;  &lt;p&gt;There was an interesting section on virtualisation, but like the rest of the book, it doesn’t go in to a great amount of detail. I guess for an administrator, this lack of detail is a good thing as you don’t want to get bogged down with pages and pages of technicalities, but you’re not going to be able to fly solo on most of these topics without getting help from a partner or reading some of the other material available through Customer Source, the online help, or the MSDN library.&lt;/p&gt;  &lt;p&gt;Coincidentally, I used to work with one of the authors, Sharan Oberoi, when he worked for Ernst and Young in New Zealand, so I feel I need to focus on the positive aspects of this book and not dwell on the areas where, for me, it fell short. At times I felt as though I was reading a giant product brochure from Microsoft about Dynamics NAV, but on a more positive note, this book provides a good introduction to a wide variety of topics that may be of interest to a systems administrator.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://teachmenav.com/aggbug.aspx?PostID=456" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/KymsLqBBgnAoRLNWXAFIEZ2tv4Y/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KymsLqBBgnAoRLNWXAFIEZ2tv4Y/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/KymsLqBBgnAoRLNWXAFIEZ2tv4Y/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KymsLqBBgnAoRLNWXAFIEZ2tv4Y/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/teachmenav/dave/~4/khTANID3bNc" height="1" width="1"/&gt;</description><category domain="http://teachmenav.com/blogs/dave/archive/tags/Book+Review/default.aspx">Book Review</category><feedburner:origLink>http://teachmenav.com/blogs/dave/archive/2010/12/31/book-review-microsoft-dynamics-nav-administration.aspx</feedburner:origLink></item><item><title>Is there anybody out there?</title><link>http://feedproxy.google.com/~r/teachmenav/dave/~3/xlwzwR2lBt8/is-there-anybody-out-there.aspx</link><pubDate>Sat, 27 Nov 2010 22:07:22 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:450</guid><dc:creator>David Roys</dc:creator><slash:comments>5</slash:comments><wfw:commentRss>http://teachmenav.com/blogs/dave/rsscomments.aspx?PostID=450</wfw:commentRss><comments>http://teachmenav.com/blogs/dave/archive/2010/11/28/is-there-anybody-out-there.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/Visual_2D00_Studio_2D00_2010_2D00_Ultimate_5F00_6C1C17EC.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:block;float:none;border-top:0px;border-right:0px;padding-top:0px;" title="Visual Studio 2010 Ultimate" border="0" alt="Visual Studio 2010 Ultimate" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/Visual_2D00_Studio_2D00_2010_2D00_Ultimate_5F00_thumb_5F00_21D15D47.png" width="240" height="159" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Way way back in July I ran a competition to give away 2 Microsoft Visual Studio 2010 Ultimate with MSDN subscription cards. I said I would announce the winners in September, but didn’t. You see the thing is, the response was pathetic. Only one entry who is of course now the proud owner of an MSDN subscription worth several thousand dollars.&lt;/p&gt;  &lt;p&gt;I’ve got one more subscription card still to give away, so the first person to tell me which Pink Floyd song includes the lyrics “Is there anybody out there?” gets it.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;The 12-month MSDN subscription has some restrictions with it being a NFR version (technical support benefits and MSDN Magazine are not included, and all software benefits, including Microsoft Office 2010 products, are for development and test purposes only).&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;The subscriptions need to be registered within 180 days of when I received them (that means you have until around the end of December 2010 to register, but I won’t be responsible for you neglecting to register—if you win a prize, register it straight away).&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://teachmenav.com/aggbug.aspx?PostID=450" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/83AON7EJlJk-94zO-rmTv4JxsTc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/83AON7EJlJk-94zO-rmTv4JxsTc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/83AON7EJlJk-94zO-rmTv4JxsTc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/83AON7EJlJk-94zO-rmTv4JxsTc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/teachmenav/dave/~4/xlwzwR2lBt8" height="1" width="1"/&gt;</description><feedburner:origLink>http://teachmenav.com/blogs/dave/archive/2010/11/28/is-there-anybody-out-there.aspx</feedburner:origLink></item><item><title>Book Review: Microsoft Dynamics NAV 2009 Programming Cookbook</title><link>http://feedproxy.google.com/~r/teachmenav/dave/~3/q8lVlNni6SQ/book-review-microsoft-dynamics-nav-2009-programming-cookbook.aspx</link><pubDate>Sat, 27 Nov 2010 21:34:18 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:449</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://teachmenav.com/blogs/dave/rsscomments.aspx?PostID=449</wfw:commentRss><comments>http://teachmenav.com/blogs/dave/archive/2010/11/28/book-review-microsoft-dynamics-nav-2009-programming-cookbook.aspx#comments</comments><description>&lt;table border="0" cellspacing="0" cellpadding="2" width="637"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="200"&gt;         &lt;p&gt;&lt;a href="http://link.packtpub.com/36XzE2" target="_blank"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="0943ENEN_MockupCover%20Coock%20book_0" border="0" alt="0943ENEN_MockupCover%20Coock%20book_0" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/0943ENEN_5F00_MockupCover20Coock20book_5F00_0_5F00_30245DB5.jpg" width="198" height="244" /&gt;&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="435"&gt;&lt;strong&gt;Author&lt;/strong&gt;: Matt Traxinger          &lt;br /&gt;          &lt;br /&gt;&lt;strong&gt;Publisher&lt;/strong&gt;: PACKT          &lt;br /&gt;          &lt;br /&gt;&lt;strong&gt;ISBN&lt;/strong&gt;: 978-1-84968-094-3          &lt;br /&gt;          &lt;br /&gt;&lt;strong&gt;Published&lt;/strong&gt;: October 2010&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;Long ago when I was co-writing &lt;i&gt;Implementing Microsoft Dynamics NAV 2009&lt;/i&gt; one of my colleagues said to me, “You don’t want to write a book like that, you want to write a NAV cookbook.” I must admit I hadn’t read any programming cookbooks and didn’t know what he was talking about so I just smiled and nodded reassuringly before totally ignoring him.&lt;/p&gt;  &lt;p&gt;Then, lo and behold, along comes a request from PACKT asking me to do the technical reviewing of a new book being written by Matt Traxinger called &lt;i&gt;&lt;a href="http://link.packtpub.com/36XzE2" target="_blank"&gt;Microsoft Dynamics NAV 2009 Programming Cookbook&lt;/a&gt;&lt;/i&gt;. Now if there’s one thing I like, it’s getting free stuff, and I remember from my authoring of &lt;i&gt;Implementing&lt;/i&gt; that the technical reviewers get a free book or two. I also remembered that the work of the technical reviewers on our book helped us (me and Vjeko) immensely and so I looked forward to helping Matt out if I could. Today I received my shiny new copy of Matt’s book (free stuff is so cool, heh, heh, heh) and I figured it was time I wrote something about it on my blog.&lt;/p&gt;  &lt;p&gt;So who is Matt Traxinger? I thought I recognised the name, but had never dealt with him directly as far as I was aware. He’s on dynamicsuser.net under the user name MattTrax and he’s made more than 500 posts. Chances are he’s helped me out more than a couple of times. If you want the bio from the book, you can &lt;a href="https://www.packtpub.com/authors/profiles/matt-traxinger"&gt;read all about Matt here&lt;/a&gt;. I can tell you that after working on reviewing this book he seems like a really great guy and when it comes to knowing about NAV well…&lt;/p&gt;  &lt;p&gt;This book is packed full of useful stuff. I’ve been doing NAV programming for quite a while now and I know a thing or two, but I found plenty in the book that I could use straight away in my day to day work. The book is divided into 112 recipes that go from the noddy stuff (like basic building blocks of programming NAV) to pretty advanced topics that require creating .NET controls and automations using Visual Studio. It seems like there is no problem too big for Matt. If NAV can’t do it, he rolls up his sleeves, cranks up Visual Studio and finds a solution. That was the thing I loved about this book. Matt has a great attitude to working with NAV and shows what can be done if you’re prepared to think outside the box.&lt;/p&gt;  &lt;p&gt;I loved this book. There’s something in it for everyone. The recipes are fun-sized morsels of knowledge and you can dib in and out when you need to solve a particular problem, or you can start from the beginning and work your way through if you just want to learn as much as you can.&lt;/p&gt;  &lt;p&gt;There are plenty of sources of knowledge on NAV now including various books, blogs, and online articles; if you’re a completely stingy git, you may prefer to spend your time trawling through forums and trying lots of things rather than shelling out for Matt’s book. I know I’d rather save my time and go straight to one reference where I can get an easy step-by-step guide on how to get past my current problem and then move on.&lt;/p&gt;  &lt;p&gt;If you program NAV, you need this book. Well done Matt!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://teachmenav.com/aggbug.aspx?PostID=449" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/xzzjGOPhi-VA9XROSUQln2pa1co/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/xzzjGOPhi-VA9XROSUQln2pa1co/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/xzzjGOPhi-VA9XROSUQln2pa1co/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/xzzjGOPhi-VA9XROSUQln2pa1co/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/teachmenav/dave/~4/q8lVlNni6SQ" height="1" width="1"/&gt;</description><category domain="http://teachmenav.com/blogs/dave/archive/tags/Book+Review/default.aspx">Book Review</category><feedburner:origLink>http://teachmenav.com/blogs/dave/archive/2010/11/28/book-review-microsoft-dynamics-nav-2009-programming-cookbook.aspx</feedburner:origLink></item><item><title>Creating a view across all companies–part 3</title><link>http://feedproxy.google.com/~r/teachmenav/dave/~3/BpPrH2VLJ0A/creating-a-view-across-all-companies-part-3.aspx</link><pubDate>Sun, 29 Aug 2010 02:31:22 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:447</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://teachmenav.com/blogs/dave/rsscomments.aspx?PostID=447</wfw:commentRss><comments>http://teachmenav.com/blogs/dave/archive/2010/08/29/creating-a-view-across-all-companies-part-3.aspx#comments</comments><description>&lt;p&gt;&lt;img style="margin:5px;display:inline;" align="left" src="http://i19.photobucket.com/albums/b160/psuedoemo/bear-sitting-picnic-table.jpg" width="200" height="200" alt="" /&gt;&lt;/p&gt;  &lt;p&gt;This is the final part in a three part series of blog posts. In &lt;a href="http://www.teachmenav.com/blogs/dave/archive/2010/08/15/creating-a-view-across-all-companies-part-1.aspx"&gt;part 1&lt;/a&gt; I wrote about how you could use a couple of fields in the $ndo$dbproperty table to create a ConvertInvalidChars() function that would turn your NAV company name into the prefix for the table name as it is used in the SQL database. Then in &lt;a href="http://www.teachmenav.com/blogs/dave/archive/2010/08/22/creating-a-view-across-all-companies-part-2.aspx"&gt;part 2&lt;/a&gt; I showed you how to create a SQL script that would dynamically create your view for all companies that exist in the database. In this final part, I’m going to show you how to link the view to a NAV table and talk about some of the things to watch out for.&lt;/p&gt;  &lt;p&gt;If you’ve followed the previous parts, you should now have a SQL view called Company Vendor that contains every field from the Vendor table in NAV plus a new field called Company Name that contains the company name.&lt;/p&gt;  &lt;h2&gt;Linked Tables&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_52EA26FE.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:5px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" align="right" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_65DAE243.png" width="363" height="275" /&gt;&lt;/a&gt;&lt;/h2&gt;  &lt;p&gt;NAV has a neat property on the table definition that allows you to say a table is linked to a view in the database that has the same name as the table name. You can see this property by bringing up the properties for the table and looking at Linked Object. In the next image, you can see the property for my table 50001 is set to Yes. There is another property called LinkedInTransaction and the use of this has often been mysterious, I think because the online help definition is so poor and also because it is very rare for me to try to update the data in the linked object. According to a &lt;a href="http://dynamicsuser.net/forums/p/24642/131913.aspx"&gt;dynamicsuser.net post&lt;/a&gt; from Dean McCrae, when you have LinkedInTransaction set to No, NAV uses a separate connection and separate transaction for accessing the linked tables. This means that if your main connection rollsback due to an error, it does not affect the transaction performed for the linked object. The purpose of LinkedInTransaction is to make the transactions performed on the linked objects isolated from the main transaction. So it only matters if you plan to allow transactions such as inserts, updates and deletes on this linked object. In this example we are not allowing that.&lt;/p&gt;  &lt;h2&gt;Creating the Linked Table&lt;/h2&gt;  &lt;p&gt;I have found the quickest way to create my linked table is to edit my original table (in this case the Vendor table) and then edit the properties to change the ID, Name and set the LinkedObject property to Yes and DataPerCompany to no. I can then save my table. Since my view already exists, it all gets plumbed up correctly. I can now run my table and I see data from both of my companies – but unfortunately I can’t see the company name, and that is because I haven’t added the Company Name field. When I edit my table and add the new Company Name field, I come across the first of the problems with this simple technique. I get a message telling me that “The Record variable must belong to 23 and not to 50001”. The reason for this error is that there is programming logic attached to various triggers on the table that is expecting the table to be the Vendor table (23) and not our new Company Vendor table (50001). In short, you are going to need to remove all programming triggers from your table definition. You can do this easily by pressing Ctrl+S to save the table, the error message will be displayed and when you click OK, you will be taken to the code editing window. Now simply press Ctrl+Home to get to the start of the code, hold the Shift key down and press Ctrl+End so that all text in all programming triggers is selected. Then press delete. Finally, call up the Global variables window, open the Functions tab and select all of the functions, then delete. This will remove those functions that get left behind as empty functions when we deleted the code.&lt;/p&gt;  &lt;h2&gt;Gotchas&lt;/h2&gt;  &lt;p&gt;Although it was really easy for me to create my linked table by saving the existing table, there are a couple of things wrong with this. First of all, I need to remember to remove the programming code from the table, otherwise bad things could happen unexpectedly (such as data being updated in related tables on validates). The other issue relates to FlowFields. The system does not complain about the flowfield definitions in the table but you should be careful of these. The flow fields (such as Balance) are used to sum up the remaining amount on the Vendor Ledger entries for this Vendor, but the system does not know that the Vendor actually exists in a different company. If you are lucky, the flow fields will simply display 0. If you are unlucky there will be a Vendor with the same code in different companies and as a result, you will see a value that is related to the wrong company. My advice to you is to remove the flowfields and flowfilters from your table definition. On the vendor table this is 56 different fields. It’s at this point that I’m starting to wonder whether I actually saved any time by copying the existing table. It’s not actually that hard to go down the list of fields and delete the ones you don’t think you’ll need. You may find that when you delete certain fields from the table, the system complains that the fields are used in an active key. This is a good reason to delete the keys from the table definition too and make the primary key “Company Name”, “No.”.&lt;/p&gt;  &lt;h2&gt;Making the Page&lt;/h2&gt;  &lt;p&gt;My final step is to make a page over my new table. Remember to make the page non-editable and to say Insert Allowed, Delete Allowed and Modify Allowed = No. We don’t want someone accidentally deleting records from the view, because this will delete the actual records from the linked tables (and I have found that it doesn’t care what the underlying table is, even tables like the General Ledger Entry table which you wouldn’t normally be allowed to delete from using a regular user’s license). Here’s a picture of my final page showing how I can search across multiple companies for a specific vendor name.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_0445232D.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_77D70003.png" width="644" height="433" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Have fun with your linked tables.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://teachmenav.com/aggbug.aspx?PostID=447" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/lnxnpGXVR0PDWIAN6vZ0CCwPvCA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lnxnpGXVR0PDWIAN6vZ0CCwPvCA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/lnxnpGXVR0PDWIAN6vZ0CCwPvCA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lnxnpGXVR0PDWIAN6vZ0CCwPvCA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/teachmenav/dave/~4/BpPrH2VLJ0A" height="1" width="1"/&gt;</description><category domain="http://teachmenav.com/blogs/dave/archive/tags/Programming/default.aspx">Programming</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/NAV+2009+SP1/default.aspx">NAV 2009 SP1</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/NAV+2009/default.aspx">NAV 2009</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/SQL/default.aspx">SQL</category><feedburner:origLink>http://teachmenav.com/blogs/dave/archive/2010/08/29/creating-a-view-across-all-companies-part-3.aspx</feedburner:origLink></item><item><title>Creating a view across all companies—part 2</title><link>http://feedproxy.google.com/~r/teachmenav/dave/~3/fFonxvRHG7E/creating-a-view-across-all-companies-part-2.aspx</link><pubDate>Sun, 22 Aug 2010 04:12:14 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:443</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://teachmenav.com/blogs/dave/rsscomments.aspx?PostID=443</wfw:commentRss><comments>http://teachmenav.com/blogs/dave/archive/2010/08/22/creating-a-view-across-all-companies-part-2.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://serverperformancemonitor.com/images/magnifying-glass.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;margin:0px 4px 4px 0px;display:inline;border-top:0px;border-right:0px;" border="0" align="left" src="http://ts3.mm.bing.net/images/thumbnail.aspx?q=202861448386&amp;amp;id=b1c9a2ea4da7eb04c8bb18b4ca57a871&amp;amp;url=http%3a%2f%2fserverperformancemonitor.com%2fimages%2fmagnifying-glass.jpg" width="160" height="120" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In &lt;a href="http://www.teachmenav.com/blogs/dave/archive/2010/08/15/creating-a-view-across-all-companies-part-1.aspx" target="_blank"&gt;last week’s post&lt;/a&gt; I wrote about how you could use a couple of fields in the $ndo$dbproperty table to create a ConvertInvalidChars() function that would turn your NAV company name into the prefix for the table name as it is used in the SQL database. This week we’re going to write some SQL that will create a dynamic select statement that we can use to create our view.&lt;/p&gt;  &lt;h2&gt;What is Dynamic SQL?&lt;/h2&gt;  &lt;p&gt;Dynamic SQL is when we use programming code to build up our SQL Select statement in a text variable and then execute that statement. In the case of our all company view, we don’t know how many companies we have or what they’re called, so we’re going to need to write something that will read the companies in the database and generate the correct SQL statement for us.&lt;/p&gt;  &lt;p&gt;Here a simple example that shows that you can build up your SQL statement as a string and then use the EXEC() command to execute it.&lt;/p&gt; &lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(4000)     &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt; = &lt;span style="color:red;"&gt;&amp;#39;SELECT Name FROM Company&amp;#39;&lt;/span&gt;     &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;EXEC&lt;/span&gt;( &lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt;)     &lt;br /&gt;&lt;/code&gt;  &lt;p&gt;The results of running this SQL is exactly the same as typing SELECT Name FROM Company into a query window and pressing F5.&lt;/p&gt;  &lt;h2&gt;Going Loopy with Cursors&lt;/h2&gt;  &lt;p&gt;Now we need to build up our SQL statement by looping through each of the companies in the database. To do this we’re going to use a cursor. A cursor is good because it allows you to fetch data back from the database one row at a time and then do something with the results. The downside to cursors is that they are slow (and this is one of the reasons that the performance of NAV is not as good as it could be as it makes extensive use of cursors when fetching data from the server).&lt;/p&gt;  &lt;p&gt;In addition to using a cursor, we’re going to use the UNION ALL statement that will join the results from our select statements together into a single dataset – this is useful since we are trying to create a combined view, which means we need a single result set. Here’s the code:&lt;/p&gt; &lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@CompanyName&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(30)     &lt;br /&gt;&lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(4000) = &lt;span style="color:red;"&gt;&amp;#39;&amp;#39;&lt;/span&gt;     &lt;br /&gt;&lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt; mycur &lt;span style="color:blue;"&gt;CURSOR&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;FOR&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Name     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FROM&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Company;     &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;OPEN&lt;/span&gt; mycur     &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;FETCH&lt;/span&gt; mycur &lt;span style="color:blue;"&gt;INTO&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@CompanyName&lt;/span&gt;     &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;WHILE&lt;/span&gt;&amp;#160;&lt;span style="color:#ff00dc;"&gt;@@FETCH_STATUS&lt;/span&gt; = 0     &lt;br /&gt;&lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;IF&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt; &amp;lt;&amp;gt; &lt;span style="color:red;"&gt;&amp;#39;&amp;#39;&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt; += &lt;span style="color:red;"&gt;&amp;#39;UNION ALL &amp;#39;&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt; += &lt;span style="color:red;"&gt;&amp;#39;SELECT [Company Name] = &amp;#39;&lt;/span&gt;&lt;span style="color:red;"&gt;&amp;#39;&amp;#39;&lt;/span&gt; + &lt;span style="color:#8b0000;"&gt;@CompanyName&lt;/span&gt; + &lt;span style="color:red;"&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span style="color:red;"&gt;&amp;#39;, * FROM [&amp;#39;&lt;/span&gt; + dbo.ConvertInvalidChars( &lt;span style="color:#8b0000;"&gt;@CompanyName&lt;/span&gt;) + &lt;span style="color:red;"&gt;&amp;#39;$Vendor] &amp;#39;&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FETCH&lt;/span&gt; mycur &lt;span style="color:blue;"&gt;INTO&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@CompanyName&lt;/span&gt;     &lt;br /&gt;&lt;span style="color:blue;"&gt;END&lt;/span&gt;;     &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:#008000;"&gt;--EXEC(@SQLCommand)&lt;/span&gt;     &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;PRINT&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt;     &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;CLOSE&lt;/span&gt; mycur     &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;DEALLOCATE&lt;/span&gt; mycur     &lt;br /&gt;&lt;/code&gt;  &lt;p&gt;As you can see I’ve commented out my EXEC command and replaced it with a PRINT command so we can see the SQL that gets generated in the message window. Here’s the SQL code it generates (obviously it doesn’t generate all of the formatting, I just inserted that to make it easier to follow the code):&lt;/p&gt; &lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [Company Name] = &lt;span style="color:red;"&gt;&amp;#39;CRONUS Australia Pty. Ltd.&amp;#39;&lt;/span&gt;,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *     &lt;br /&gt;&lt;span style="color:blue;"&gt;FROM&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [CRONUS Australia Pty_ Ltd_$Vendor]     &lt;br /&gt;&lt;span style="color:blue;"&gt;UNION&lt;/span&gt;&amp;#160;&lt;span style="color:gray;"&gt;ALL&lt;/span&gt;     &lt;br /&gt;&lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [Company Name] = &lt;span style="color:red;"&gt;&amp;#39;CRONUS New Zealand Ltd.&amp;#39;&lt;/span&gt;,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *     &lt;br /&gt;&lt;span style="color:blue;"&gt;FROM&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [CRONUS New Zealand Ltd_$Vendor]     &lt;br /&gt;&lt;/code&gt;  &lt;p&gt;If you copied that SQL statement into a query window, you’d see a dataset that contains all of the fields from our Vendor table for each of the companies with a new first column called “Company Name”. Obviously you’d need to change this if you had an actual field called “Company Name” in your table. &lt;/p&gt;  &lt;h2&gt;Making the View&lt;/h2&gt;  &lt;p&gt;The only thing left to do now is put in the CREATE VIEW AS code to create our view. I’m going to call my view Company Vendor. Here’s the final SQL that will create my view.&lt;/p&gt; &lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@CompanyName&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(30)    &lt;br /&gt;&lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(4000) = &lt;span style="color:red;"&gt;&amp;#39;&amp;#39;&lt;/span&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt; mycur &lt;span style="color:blue;"&gt;CURSOR&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;FOR&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Name    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FROM&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Company;    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;OPEN&lt;/span&gt; mycur    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;FETCH&lt;/span&gt; mycur &lt;span style="color:blue;"&gt;INTO&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@CompanyName&lt;/span&gt;    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;WHILE&lt;/span&gt;&amp;#160;&lt;span style="color:#ff00dc;"&gt;@@FETCH_STATUS&lt;/span&gt; = 0    &lt;br /&gt;&lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;IF&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt; &amp;lt;&amp;gt; &lt;span style="color:red;"&gt;&amp;#39;&amp;#39;&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt; += &lt;span style="color:red;"&gt;&amp;#39;UNION ALL &amp;#39;&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;ELSE&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt; += &lt;span style="color:red;"&gt;&amp;#39;CREATE VIEW [Company Vendor] AS &amp;#39;&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt; += &lt;span style="color:red;"&gt;&amp;#39;SELECT [Company Name] = &amp;#39;&lt;/span&gt;&lt;span style="color:red;"&gt;&amp;#39;&amp;#39;&lt;/span&gt; + &lt;span style="color:#8b0000;"&gt;@CompanyName&lt;/span&gt; + &lt;span style="color:red;"&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span style="color:red;"&gt;&amp;#39;, * FROM [&amp;#39;&lt;/span&gt; + dbo.ConvertInvalidChars( &lt;span style="color:#8b0000;"&gt;@CompanyName&lt;/span&gt;) + &lt;span style="color:red;"&gt;&amp;#39;$Vendor] &amp;#39;&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FETCH&lt;/span&gt; mycur &lt;span style="color:blue;"&gt;INTO&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@CompanyName&lt;/span&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;END&lt;/span&gt;;    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;EXEC&lt;/span&gt;( &lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt;)    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;PRINT&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt;    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;CLOSE&lt;/span&gt; mycur    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;DEALLOCATE&lt;/span&gt; mycur    &lt;br /&gt;&lt;/code&gt;  &lt;p&gt;Next week we&amp;#39;ll look at the final steps of making this view available as a linked table in NAV and talk about some of the potential gotcha’s.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://teachmenav.com/aggbug.aspx?PostID=443" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/-gVUaAa_HNr7PFFeeg0rNhtZlww/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-gVUaAa_HNr7PFFeeg0rNhtZlww/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/-gVUaAa_HNr7PFFeeg0rNhtZlww/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-gVUaAa_HNr7PFFeeg0rNhtZlww/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/teachmenav/dave/~4/fFonxvRHG7E" height="1" width="1"/&gt;</description><category domain="http://teachmenav.com/blogs/dave/archive/tags/Programming/default.aspx">Programming</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/NAV+2009+SP1/default.aspx">NAV 2009 SP1</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/NAV+2009/default.aspx">NAV 2009</category><category domain="http://teachmenav.com/blogs/dave/archive/tags/SQL/default.aspx">SQL</category><feedburner:origLink>http://teachmenav.com/blogs/dave/archive/2010/08/22/creating-a-view-across-all-companies-part-2.aspx</feedburner:origLink></item><item><title>Creating a view across all companies–part 1</title><link>http://feedproxy.google.com/~r/teachmenav/dave/~3/mnvwKyts5BM/creating-a-view-across-all-companies-part-1.aspx</link><pubDate>Sun, 15 Aug 2010 00:31:11 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:442</guid><dc:creator>David Roys</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://teachmenav.com/blogs/dave/rsscomments.aspx?PostID=442</wfw:commentRss><comments>http://teachmenav.com/blogs/dave/archive/2010/08/15/creating-a-view-across-all-companies-part-1.aspx#comments</comments><description>&lt;h2&gt;The Linked Table&lt;/h2&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_47D3F8C2.png"&gt;&lt;img style="border-right-width:0px;margin:0px 10px 10px 0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" class="wlDisabledImage" title="image" border="0" alt="image" align="left" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_127AC090.png" width="125" height="123" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Have you ever wanted to search across multiple companies in a NAV database simultaneously? It&amp;#39;s really not that difficult as long as you&amp;#39;re using a SQL database. In this series of blog posts, I&amp;#39;ll give you a step by step guide on how to create a combined vendor list. This principal can be applied to any of the tables in NAV. First of all, we need to cover some basics.&lt;/p&gt;  &lt;p&gt;NAV has the facility to create a table definition that is linked to a view in the database that has the same name as the table. This can be a useful way to directly access data from other systems from within NAV, but it can also be useful for aggregating data that already exists in the NAV database. This could be combining data from multiple companies into a single view, as in this example, or could be combining G/L Entries and Dimensions into a single screen with the ability to search and filter on the dimensions. You could even use this technique to speed up slow processes by using SQL&amp;#39;s powerful set-based queries to replace a lot of effort needed by NAV&amp;#39;s much slower cursor-based operations.&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;To follow this example you&amp;#39;ll need a sample NAV database that you can play in without breaking anything and access to SQL Management Studio.&lt;/p&gt;  &lt;h2&gt;Getting Rid of Invalid Characters&lt;/h2&gt;  &lt;p&gt;If you’ve ever looked at the table names in a SQL database for Dynamics NAV, you’ll have noticed that the table names have the company name at the start and that certain characters have been replaced. In the demo database for New Zealand, we have two companies: CRONUS Australia Pty. Ltd. and CRONUS New Zealand Ltd. If I look for the Vendor table in SQL I’ll see the following two table names:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;CRONUS Australia Pty_ Ltd_$Vendor &lt;/li&gt;    &lt;li&gt;CRONUS New Zealand Ltd_$Vendor&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;As you can see it’s basically the company name with a dollar sign followed by the table name, but some characters have been replaced. This is because when NAV creates the underlying SQL tables, it replaces some “invalid characters”. It does the same for the field names too.&lt;/p&gt;  &lt;p&gt;In this first part of our series on creating a view across all companies, we’ll create a function that will help us find the correct company name as used as the prefix for NAV tables.&lt;/p&gt;  &lt;p&gt;The characters that get replaced are stored in a field called invalididentifierchars in a system table [$ndo$dbproperty] (the square brackets aren’t actually part of the table name, they just make tell SQL to ignore funny characters like the dollar sign and any spaces that may be part of the table name). There’s another useful field in the [$ndo$dbproperty] table that we’ll need for this exercise called convertidentifiers. This tells the system whether we want to bother converting identifiers or not. You can change both of these fields by going to the Classic Client for SQL and selecting &lt;strong&gt;Database &amp;gt; Alter&lt;/strong&gt; from the &lt;strong&gt;File&lt;/strong&gt; menu. Click on the Integration tab and you’ll see the options.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_0363E1B6.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" class="wlDisabledImage" title="image" border="0" alt="image" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_7761F181.png" width="644" height="274" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;We need to check to see if the Convert identifiers flag is set and, if it is, remove each of the characters from our company name and replace with an underscore.&lt;/p&gt;  &lt;p&gt;I’m going to create a SQL Function called ConvertInvalidChars that will do this for me. Here’s the SQL code. You should execute this in the NAV database.&lt;/p&gt; &lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;IF&lt;/span&gt; OBJECT_ID( &lt;span style="color:red;"&gt;N&amp;#39;dbo.ConvertInvalidChars&amp;#39;&lt;/span&gt;,&lt;span style="color:red;"&gt;N&amp;#39;FN&amp;#39;&lt;/span&gt;) &lt;span style="color:gray;"&gt;IS&lt;/span&gt;&amp;#160;&lt;span style="color:gray;"&gt;NOT&lt;/span&gt;&amp;#160;&lt;span style="color:#a9a9a9;"&gt;NULL&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;DROP&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;FUNCTION&lt;/span&gt; dbo.ConvertInvalidChars;     &lt;br /&gt;GO     &lt;br /&gt;&lt;span style="color:blue;"&gt;CREATE&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;FUNCTION&lt;/span&gt; dbo.ConvertInvalidChars     &lt;br /&gt;(&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#8b0000;"&gt;@p_StringToConvert&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(250)     &lt;br /&gt;)     &lt;br /&gt;RETURNS     &lt;br /&gt;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(250)     &lt;br /&gt;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160; &lt;br /&gt;&amp;#160;&lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@InvalidIdentifierChars&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(128)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@X&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt; INTEGER     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@ConvertIdentifiers&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt; INTEGER     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#8b0000;"&gt;@ConvertIdentifiers&lt;/span&gt; = convertidentifiers,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#8b0000;"&gt;@InvalidIdentifierChars&lt;/span&gt; = invalididentifierchars     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FROM&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [$ndo$dbproperty]     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;IF&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@ConvertIdentifiers&lt;/span&gt; &amp;lt;&amp;gt; 1 &lt;span style="color:blue;"&gt;RETURN&lt;/span&gt;(&lt;span style="color:#8b0000;"&gt;@p_StringToConvert&lt;/span&gt;)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@X&lt;/span&gt; = 1     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;WHILE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@X&lt;/span&gt; &amp;lt;= &lt;span style="color:#ff00dc;"&gt;LEN&lt;/span&gt;( &lt;span style="color:#8b0000;"&gt;@InvalidIdentifierChars&lt;/span&gt;)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@p_StringToConvert&lt;/span&gt; = &lt;span style="color:#ff00dc;"&gt;REPLACE&lt;/span&gt;( &lt;span style="color:#8b0000;"&gt;@p_StringToConvert&lt;/span&gt;,&lt;span style="color:#ff00dc;"&gt;SUBSTRING&lt;/span&gt;( &lt;span style="color:#8b0000;"&gt;@InvalidIdentifierChars&lt;/span&gt;,&lt;span style="color:#8b0000;"&gt;@X&lt;/span&gt;,1),&lt;span style="color:red;"&gt;&amp;#39;_&amp;#39;&lt;/span&gt;)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@X&lt;/span&gt; = &lt;span style="color:#8b0000;"&gt;@X&lt;/span&gt; + 1     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;END&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;RETURN&lt;/span&gt;(&lt;span style="color:#8b0000;"&gt;@p_StringToConvert&lt;/span&gt;)     &lt;br /&gt;&lt;span style="color:blue;"&gt;END&lt;/span&gt;     &lt;br /&gt;GO     &lt;br /&gt;    &lt;br /&gt;&lt;/code&gt;  &lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;  &lt;h2&gt;&lt;font face="Calibri"&gt;Testing our Function&lt;/font&gt;&lt;/h2&gt;  &lt;p&gt;&lt;font face="Calibri"&gt;That previous bit of SQL will give us a SQL function that we can use in our code later on. Here’s an example of a select statement that uses the function.&lt;/font&gt;&lt;/p&gt; &lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Name,    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [No Invalid Chars Name] = dbo.ConvertInvalidChars( Name),    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [NAV Vendor &lt;span style="color:blue;"&gt;Table&lt;/span&gt; Name] = &lt;span style="color:red;"&gt;&amp;#39;[&amp;#39;&lt;/span&gt; + dbo.ConvertInvalidChars( Name) + &lt;span style="color:red;"&gt;&amp;#39;$&amp;#39;&lt;/span&gt; + dbo.ConvertInvalidChars( &lt;span style="color:red;"&gt;&amp;#39;Vendor&amp;#39;&lt;/span&gt;) + &lt;span style="color:red;"&gt;&amp;#39;]&amp;#39;&lt;/span&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;FROM&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Company    &lt;br /&gt;&lt;/code&gt;  &lt;p&gt;&lt;font face="Calibri"&gt;and here’s the output from that select statement.&lt;/font&gt;&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="683"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="192"&gt;&lt;strong&gt;Name&amp;#160;&amp;#160;&amp;#160; &lt;/strong&gt;&lt;/td&gt;        &lt;td valign="top" width="195"&gt;&lt;strong&gt;No Invalid Chars Name&lt;/strong&gt;&lt;/td&gt;        &lt;td valign="top" width="294"&gt;&lt;strong&gt;NAV Vendor Table Name&lt;/strong&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="192"&gt;CRONUS Australia Pty. Ltd.&lt;/td&gt;        &lt;td valign="top" width="195"&gt;CRONUS Australia Pty_ Ltd_&lt;/td&gt;        &lt;td valign="top" width="294"&gt;[CRONUS Australia Pty_ Ltd_$Vendor]&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="192"&gt;CRONUS New Zealand Ltd.&lt;/td&gt;        &lt;td valign="top" width="195"&gt;CRONUS New Zealand Ltd_&lt;/td&gt;        &lt;td valign="top" width="294"&gt;[CRONUS New Zealand Ltd_$Vendor]&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;code&gt;&lt;font face="Calibri"&gt;Hopefully you can see where I’m going with this. Next week, I’ll show you how we are going to use this function to build a SQL View for combining multiple company tables together.&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://teachmenav.com/aggbug.aspx?PostID=442" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/yhm83ajCZ2bxAC-mIhO_KZvyYu8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yhm83ajCZ2bxAC-mIhO_KZvyYu8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/yhm83ajCZ2bxAC-mIhO_KZvyYu8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yhm83ajCZ2bxAC-mIhO_KZvyYu8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/teachmenav/dave/~4/mnvwKyts5BM" height="1" width="1"/&gt;</description><feedburner:origLink>http://teachmenav.com/blogs/dave/archive/2010/08/15/creating-a-view-across-all-companies-part-1.aspx</feedburner:origLink></item><item><title>You Could Win Visual Studio 2010 Ultimate + MSDN</title><link>http://feedproxy.google.com/~r/teachmenav/dave/~3/0czzFHVqpgc/you-could-win-visual-studio-2010-ultimate-msdn.aspx</link><pubDate>Sun, 25 Jul 2010 00:02:17 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:440</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://teachmenav.com/blogs/dave/rsscomments.aspx?PostID=440</wfw:commentRss><comments>http://teachmenav.com/blogs/dave/archive/2010/07/25/you-could-win-visual-studio-2010-ultimate-msdn.aspx#comments</comments><description>&lt;p&gt;&lt;img src="http://www.microsoft.com/visualstudio/_base_v1/images/boxshots/hero_single_ultimate_boxshot.png" alt="" /&gt;&lt;/p&gt;  &lt;p&gt;In order to drive awareness of the recent launch of Visual Studio 2010, Microsoft has given me &lt;font size="4"&gt;&lt;strong&gt;2&lt;/strong&gt;&lt;/font&gt; x Not for Resale (NFR) &lt;strong&gt;&lt;font size="3"&gt;Visual Studio 2010 Ultimate with MSDN subscription cards to give away&lt;/font&gt;&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;Take a look on the &lt;a href="http://www.microsoft.com/visualstudio/en-us/products/2010-editions/ultimate" target="_blank"&gt;Visual Studio Product Site&lt;/a&gt; and you’ll see that to buy one of these subscriptions will set you back a lot of money—but I’m giving them away for free!&lt;/p&gt;  &lt;h3&gt;What do you need to do?&lt;/h3&gt;  &lt;p&gt;As you know, Microsoft Dynamics NAV 2009 SP1 introduced a new feature called Control Add-ins. These are .NET controls that let you do all kinds of stuff like display customer locations using Bing Maps, display Visio diagrams, capture signatures, display charts, have spell checking, edit HTML…all within the RoleTailored client. What a lot of stuff! The thing is, you’re only really limited by your imagination – these are just some examples of controls that have already been created. What control would you create?&lt;/p&gt;  &lt;p&gt;I’m not asking you to build one of these controls to win the prize, I just want you to &lt;strong&gt;&lt;font size="4"&gt;think of an idea for a control add-in and write about it&lt;/font&gt;&lt;/strong&gt;. Write a Word document describing your concept and include pictures (mock-ups or sketches) of how you see it working. You can use any version of Word for your submission, but don’t use other formats because if I can’t read it, you can’t win. Also all submissions must be in English and if you write in Text Speak or some strange form of English that I can’t understand, you’re chances of winning are slim. You’re submission should be around two pages in Word with a picture or two.&lt;/p&gt;  &lt;h3&gt;How do you submit your entry?&lt;/h3&gt;  &lt;p&gt;The purpose of this competition is to get people thinking about custom controls for NAV 2009 SP1 and sharing their ideas. I have created a Forum for you to upload your ideas so they are then shared with everyone. Write a forum post giving a brief outline of your idea and you should be able to attach a Word document to the forum post. The &lt;a href="http://www.teachmenav.com/forums/22.aspx" target="_blank"&gt;Control Add-ins Forum&lt;/a&gt; is here. You need to be registered on TeachMeNAV to be able to make posts. I will need to send an e-mail to you about the prize if you win, so make sure you use a real e-mail address when you register. I’ll put in a sample posting so you know what I’m looking for. I’ll be searching for your idea online so don’t bother just posting someone else’s idea or blog post.&lt;/p&gt;  &lt;h3&gt;Closing Date and Terms and Conditions&lt;/h3&gt;  &lt;ol&gt;   &lt;li&gt;I’ll leave the forum open until the end of August 2010. You must make your submission before then to be in to win.&lt;/li&gt;    &lt;li&gt;Only submissions made through the &lt;a href="http://www.teachmenav.com/forums/22.aspx" target="_blank"&gt;Control Add-ins Forum&lt;/a&gt; will be considered.&lt;/li&gt;    &lt;li&gt;I am going to pick the winners and my decision is final.&lt;/li&gt;    &lt;li&gt;The Visual Studio 2010 MSDN subscription cards are the only prizes. There is no cash alternative and if for any reason your subscription card does not work, you’ll need to sort this out with Microsoft and not with me.&lt;/li&gt;    &lt;li&gt;I’ll announce the winning entries before the end of September 2010.&lt;/li&gt;    &lt;li&gt;The competition is not open to Dynamics NAV MVPs (sorry guys but you already have an MSDN subscription, so let’s give someone else a chance).&lt;/li&gt;    &lt;li&gt;By submitting your ideas, they are shared with the world. If someone decides to build your idea, good luck to them.&lt;/li&gt; &lt;/ol&gt;  &lt;h3&gt;What’s the catch?&lt;/h3&gt;  &lt;p&gt;There’s no catch, but there are some conditions and limitations surrounding the prize.&lt;/p&gt;  &lt;p&gt;The 12-month MSDN subscription has some restrictions with it being a NFR version (technical support benefits and MSDN Magazine are not included, and all software benefits, including Microsoft Office 2010 products, are for development and test purposes only).&lt;/p&gt;  &lt;p&gt;The subscriptions need to be registered within 180 days of when &lt;em&gt;I&lt;/em&gt; received them (that means you have until around the end of December 2010 to register, but I won’t be responsible for you neglecting to register—if you win a prize, register it straight away).&lt;/p&gt;  &lt;h3&gt;Resources&lt;/h3&gt;  &lt;p&gt;The official Microsoft documentation about add-ins online at &lt;a href="http://msdn.microsoft.com/en-us/library/dd983700.aspx"&gt;http://msdn.microsoft.com/en-us/library/dd983700.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Freddy Kristiansen’s Blog &lt;a href="http://blogs.msdn.com/b/freddyk/archive/2009/06/07/integration-to-virtual-earth-part-4-of-4.aspx"&gt;http://blogs.msdn.com/b/freddyk/archive/2009/06/07/integration-to-virtual-earth-part-4-of-4.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Christian Abeln’s blog on Add-ins &lt;a href="http://blogs.msdn.com/b/cabeln/archive/2009/05/06/add-ins-for-the-roletailored-client-of-microsoft-dynamicsnav-2009-sp1-part1.aspx"&gt;http://blogs.msdn.com/b/cabeln/archive/2009/05/06/add-ins-for-the-roletailored-client-of-microsoft-dynamicsnav-2009-sp1-part1.aspx&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://teachmenav.com/aggbug.aspx?PostID=440" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/4IOaXxdexipZE_3uNhG7G1wwLxA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4IOaXxdexipZE_3uNhG7G1wwLxA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/4IOaXxdexipZE_3uNhG7G1wwLxA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4IOaXxdexipZE_3uNhG7G1wwLxA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/teachmenav/dave/~4/0czzFHVqpgc" height="1" width="1"/&gt;</description><feedburner:origLink>http://teachmenav.com/blogs/dave/archive/2010/07/25/you-could-win-visual-studio-2010-ultimate-msdn.aspx</feedburner:origLink></item></channel></rss>

