<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TechKnowSolve Blog</title>
	<atom:link href="http://www.techknowsolve.com/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.techknowsolve.com/blog</link>
	<description>Technical Hints and Tips from TechKnowSolve.com</description>
	<lastBuildDate>Thu, 17 Jun 2010 17:33:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>DELETE button not captured by KeyPress event</title>
		<link>http://www.techknowsolve.com/blog/?p=63</link>
		<comments>http://www.techknowsolve.com/blog/?p=63#comments</comments>
		<pubDate>Thu, 17 Jun 2010 17:33:05 +0000</pubDate>
		<dc:creator>MaryD</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.techknowsolve.com/blog/?p=63</guid>
		<description><![CDATA[A small but important thing &#8211; if you want to capture pressing the DELETE button in a WinForms project, you&#8217;ll need to do it in the KeyDown or KeyUp event, not the KeyPress event.  As the documentation (here and here) points out, KeyPress deals mostly with character keys, and non-character keys won&#8217;t raise it.
]]></description>
			<content:encoded><![CDATA[<p>A small but important thing &#8211; if you want to capture pressing the DELETE button in a WinForms project, you&#8217;ll need to do it in the KeyDown or KeyUp event, not the KeyPress event.  As the documentation (<a title="Control.KeyPressEvent" href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress.aspx" target="_blank">here</a> and <a title="KeyPress Event (Office 12)" href="http://msdn.microsoft.com/en-us/library/ee414757(office.12).aspx" target="_blank">here</a>) points out, KeyPress deals mostly with character keys, and non-character keys won&#8217;t raise it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techknowsolve.com/blog/?feed=rss2&amp;p=63</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remove items from Visual Studio Recent Projects list</title>
		<link>http://www.techknowsolve.com/blog/?p=59</link>
		<comments>http://www.techknowsolve.com/blog/?p=59#comments</comments>
		<pubDate>Wed, 19 May 2010 17:05:27 +0000</pubDate>
		<dc:creator>MaryD</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.techknowsolve.com/blog/?p=59</guid>
		<description><![CDATA[Here are a couple handy links describing how to remove items from the Recent Projects list on the Visual Studio start page.  Basically, in versions prior to VS2010, it&#8217;s a registry hack (I&#8217;ve read that VS2010 provides a way to do this within the IDE, but I haven&#8217;t played with 2010 yet so I can&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Here are a couple handy links describing how to remove items from the Recent Projects list on the Visual Studio start page.  Basically, in versions prior to VS2010, it&#8217;s a registry hack (I&#8217;ve read that VS2010 provides a way to do this within the IDE, but I haven&#8217;t played with 2010 yet so I can&#8217;t attest to that myself).</p>
<p><a href="http://aspnetcoe.wordpress.com/2007/02/06/how-to-remove-recent-projects-from-visual-studio-start-page/" target="_blank">http://aspnetcoe.wordpress.com/2007/02/06/how-to-remove-recent-projects-from-visual-studio-start-page/</a></p>
<p><a href="http://mvantzet.wordpress.com/2009/09/15/remove-recent-projects-from-visual-studio-2008/" target="_blank">http://mvantzet.wordpress.com/2009/09/15/remove-recent-projects-from-visual-studio-2008/</a></p>
<p>When I removed some items from my version of VS 2008, I found that I also needed to rename the remaining registry keys so that there were no gaps in the order (ie, File1, File2, etc with no gaps)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techknowsolve.com/blog/?feed=rss2&amp;p=59</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with winmm.dll to play audio files in .NET</title>
		<link>http://www.techknowsolve.com/blog/?p=55</link>
		<comments>http://www.techknowsolve.com/blog/?p=55#comments</comments>
		<pubDate>Fri, 30 Apr 2010 00:38:24 +0000</pubDate>
		<dc:creator>MaryD</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.techknowsolve.com/blog/?p=55</guid>
		<description><![CDATA[I&#8217;m working on a little utility application that will transfer audio files from a recorder to a computer drive.  Part of the functionality is to display the audio files, and let users listen to a little snippet of the audio file if they so desire.  A quick google search led me to this page containing [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a little utility application that will transfer audio files from a recorder to a computer drive.  Part of the functionality is to display the audio files, and let users listen to a little snippet of the audio file if they so desire.  A quick google search led me to <a href="http://www.vbforfree.com/?p=219" target="_blank">this page </a>containing a good description of the process, with example code.  Using the examples, I came up with the utility class shown below.  And here&#8217;s how I&#8217;d use the class in a button event handler:</p>
<p>Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked<br />
    Using player As New PlayAudioFile(&#8220;C:\Misc\WS400001.WMA&#8221;)<br />
         player.PlaySnippet(5)<br />
    End Using<br />
End Sub</p>
<p>Public Class PlayAudioFile<br />
    Implements IDisposable</p>
<p>    &#8216;Private data member &#8211; file path<br />
    Private fileToPlay As String</p>
<p>    &#8216;Private function to send commands to the Windows OS MultiMedia API<br />
    Private Declare Function mciSendString Lib &#8220;winmm.dll&#8221; Alias &#8220;mciSendStringA&#8221; _<br />
    (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _<br />
    ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer</p>
<p>    &#8216;Private wrapper method for API function<br />
    Private Sub SendCommand(ByVal command As String)<br />
        mciSendString(String.Format(&#8220;{0} {1}&#8221;, command, fileToPlay), Nothing, 0, 0)<br />
    End Sub</p>
<p>    &#8221;&#8217; &lt;summary&gt;<br />
    &#8221;&#8217; Class Constructor &#8211; accepts an audio file (must be MP3, WAV or WMA file)<br />
    &#8221;&#8217; &lt;/summary&gt;<br />
    &#8221;&#8217; &lt;param name=&#8221;soundFile&#8221;&gt;Full path of audio file to be played&lt;/param&gt;<br />
    Public Sub New(ByVal soundFile As String)<br />
        Dim ext As String = IO.Path.GetExtension(soundFile)<br />
        Select Case ext.ToLower<br />
            Case &#8220;.mp3&#8243;, &#8220;.wav&#8221;, &#8220;.wma&#8221;<br />
                fileToPlay = Chr(34) + soundFile + Chr(34)<br />
            Case Else<br />
                Throw New ArgumentException(&#8220;File must be an .MP3, .wav or .WMA file&#8221;)<br />
        End Select<br />
    End Sub</p>
<p>    &#8221;&#8217; &lt;summary&gt;<br />
    &#8221;&#8217; Play audio file<br />
    &#8221;&#8217; &lt;/summary&gt;<br />
    Public Sub Play()<br />
        Me.SendCommand(&#8220;open&#8221;)<br />
        Me.SendCommand(&#8220;play&#8221;)<br />
    End Sub</p>
<p>    &#8221;&#8217; &lt;summary&gt;<br />
    &#8221;&#8217; Stop audio file playback<br />
    &#8221;&#8217; &lt;/summary&gt;<br />
    Public Sub StopPlay()<br />
        Me.SendCommand(&#8220;stop&#8221;)<br />
    End Sub</p>
<p>    &#8221;&#8217; &lt;summary&gt;<br />
    &#8221;&#8217; Pause audio file playback<br />
    &#8221;&#8217; &lt;/summary&gt;<br />
    Public Sub PausePlay()<br />
        Me.SendCommand(&#8220;pause&#8221;)<br />
    End Sub</p>
<p>    &#8221;&#8217; &lt;summary&gt;<br />
    &#8221;&#8217; Resume playback of paused audio file<br />
    &#8221;&#8217; &lt;/summary&gt;<br />
    Public Sub ResumePlay()<br />
        Me.SendCommand(&#8220;resume&#8221;)<br />
    End Sub</p>
<p>    &#8221;&#8217; &lt;summary&gt;<br />
    &#8221;&#8217; Close audio file<br />
    &#8221;&#8217; &lt;/summary&gt;<br />
    Public Sub CloseFile()<br />
        Me.SendCommand(&#8220;close&#8221;)<br />
    End Sub</p>
<p>    &#8221;&#8217; &lt;summary&gt;<br />
    &#8221;&#8217; Play the first part of the sound file (default 15 seconds)<br />
    &#8221;&#8217; &lt;/summary&gt;<br />
    Public Sub PlaySnippet()<br />
        PlaySnippet(15)<br />
    End Sub</p>
<p>    &#8221;&#8217; &lt;summary&gt;<br />
    &#8221;&#8217; Play the first part of the sound file<br />
    &#8221;&#8217; &lt;/summary&gt;<br />
    &#8221;&#8217; &lt;param name=&#8221;snippetLength&#8221;&gt;Length of snippet (in seconds)&lt;/param&gt;<br />
    Public Sub PlaySnippet(ByVal snippetLength As Integer)<br />
        Me.Play()<br />
        System.Threading.Thread.Sleep(snippetLength * 1000)<br />
        Me.StopPlay()<br />
    End Sub</p>
<p>#Region &#8221; IDisposable Support &#8221;</p>
<p>    Private disposedValue As Boolean = False        &#8216; To detect redundant calls</p>
<p>    &#8216; IDisposable<br />
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)<br />
        If Not Me.disposedValue Then<br />
            If disposing Then<br />
                &#8216; TODO: free unmanaged resources when explicitly called<br />
                Me.CloseFile()<br />
            End If</p>
<p>            &#8216; TODO: free shared unmanaged resources<br />
            Me.CloseFile()<br />
        End If<br />
        Me.disposedValue = True<br />
    End Sub</p>
<p>    &#8216; This code added by Visual Basic to correctly implement the disposable pattern.<br />
    Public Sub Dispose() Implements IDisposable.Dispose<br />
        &#8216; Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.<br />
        Dispose(True)<br />
        GC.SuppressFinalize(Me)<br />
    End Sub<br />
#End Region</p>
<p>End Class</p>
<p>There should probably be more error handling in the class (for example, to make sure that the file is opened before calling ResumePlay, that sort of thing), but I thought this was a good start.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techknowsolve.com/blog/?feed=rss2&amp;p=55</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DataGridViewComboBox Column Properties</title>
		<link>http://www.techknowsolve.com/blog/?p=45</link>
		<comments>http://www.techknowsolve.com/blog/?p=45#comments</comments>
		<pubDate>Mon, 26 Apr 2010 22:34:06 +0000</pubDate>
		<dc:creator>Lis</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.techknowsolve.com/blog/?p=45</guid>
		<description><![CDATA[I am copying this verbatim from a post I found by Kevin Spencer which is the clearest explanation I have seen of the main properties of a DataGridViewComboBox.  It&#8217;s here for my reference.  Yay if it helps you too!
The DataGridView itself has a DataSource property that determines what columns are in it. The [...]]]></description>
			<content:encoded><![CDATA[<p>I am copying this verbatim from a post I found by Kevin Spencer which is the clearest explanation I have seen of the main properties of a DataGridViewComboBox.  It&#8217;s here for my reference.  Yay if it helps you too!</p>
<p>The DataGridView itself has a DataSource property that determines what columns are in it. The DataGridViewComboBox column also has a DataSource property, but that isn&#8217;t the same as the DataSource of the DataGridView. It is the DataSource that is used to populate the ComboBox in each cell. The DataMember and ValueMember properties are the column names of the columns in the ComboBox&#8217;s DataSource that define what is displayed in the ComboBox, and the underlying value for that item. It is the DataPropertyName property of the DataGridViewComboBoxColumn that determines the column name in the DataGridView&#8217;s DataSource that the ataGridViewComboBoxColumn is associated with. The ValueMember determines the value that will be set for that column in the DataGridView&#8217;s DataSource.</p>
<p>Here&#8217;s the original <a href="http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework/topic43757.aspx" target="_blank"> link</a>.  Thanks, Kevin Spencer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techknowsolve.com/blog/?feed=rss2&amp;p=45</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>System.Data.OleDb.OleDbException: Unspecified error</title>
		<link>http://www.techknowsolve.com/blog/?p=16</link>
		<comments>http://www.techknowsolve.com/blog/?p=16#comments</comments>
		<pubDate>Wed, 17 Mar 2010 22:13:31 +0000</pubDate>
		<dc:creator>MaryD</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[All]]></category>

		<guid isPermaLink="false">http://techknowsolve.com/blog/?p=16</guid>
		<description><![CDATA[I ran across this error in an ASP.NET project that was using ADO.NET to access the data in a .csv file (more info here). After much gnashing of teeth, I finally ran across this blog post, that explained the problem and provided a link to this MSDN article.
Basically, you need to make sure that the [...]]]></description>
			<content:encoded><![CDATA[<p>I ran across this error in an ASP.NET project that was using ADO.NET to access the data in a .csv file (more info <a href="http://weblogs.asp.net/fmarguerie/archive/2003/10/01/29964.aspx" target="_blank">here</a>). After much gnashing of teeth, I finally ran across this <a href="http://msmvps.com/blogs/rakeshrajan/archive/2005/07/04/56461.aspx" target="_blank">blog post</a>, that explained the problem and provided a link to this <a href="http://support.microsoft.com/default.aspx?scid=kb;EN-US;825738" target="_blank">MSDN article</a>.</p>
<p>Basically, you need to make sure that the user has permissions on both the file in which the .csv file resides, and also the file in which the <a href="http://en.wikipedia.org/wiki/Microsoft_Jet_Database_Engine" target="_blank">Jet Engine</a> will create temporary files. It is this last piece that I didn&#8217;t know, and lead to days of heartache.</p>
<p>So I thought I&#8217;d post, in the hopes of minimizing the heartache for others&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techknowsolve.com/blog/?feed=rss2&amp;p=16</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Query SQL Server Role Members</title>
		<link>http://www.techknowsolve.com/blog/?p=39</link>
		<comments>http://www.techknowsolve.com/blog/?p=39#comments</comments>
		<pubDate>Wed, 17 Mar 2010 21:55:11 +0000</pubDate>
		<dc:creator>Lis</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.techknowsolve.com/blog/?p=39</guid>
		<description><![CDATA[You can use SQL Server Database Roles to control access to various parts of your application.  Let&#8217;s say I have created a .NET application.  I have a menu called Administration and I only want certain users to be able to see the menu.  One way to do this is to use Active [...]]]></description>
			<content:encoded><![CDATA[<p>You can use SQL Server Database Roles to control access to various parts of your application.  Let&#8217;s say I have created a .NET application.  I have a menu called Administration and I only want certain users to be able to see the menu.  One way to do this is to use Active Directory Groups.  Another way is to use SQL Server Database roles.</p>
<p>For this example I create a role called MyAppAdmin.  Only members of MyAppAdmin should be able to see the Administration menu.  After creating the role and assigning appropriate permissions to the role, I want to check, within my .NET application, to see if the logged on user is a member of the MyAppAdmin role.  Here&#8217;s how to do this:</p>
<p>Create a stored procedure:</p>
<p>CREATE procedure [dbo].[uspTestDatabaseRole]<br />
&#8211; Returns 1 if user is a member of the specified role or if user is dbo<br />
@RoleName varchar(30)<br />
as<br />
declare @Return integer<br />
if USER_NAME() = &#8216;dbo&#8217;<br />
select @Return = 1<br />
else<br />
select @Return = IS_MEMBER(@RoleName)<br />
select @Return</p>
<p>In this procedure the variable @RoleName refers to the Database Role you are checking.  You can also use it to check membership in a Windows group.  You may notice if the person calling the stored procedure is dbo, I return 1 no matter what.  You may not want the procedure to work this way so you should modify for your own purposes.</p>
<p>Now all you need to do is call this procedure from your .NET code and it will return 1 if the person is a member of the database role you are checking or if the person is dbo.  Otherwise, it will return 0.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techknowsolve.com/blog/?feed=rss2&amp;p=39</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use HttpModule to turn tracing on via the querystring</title>
		<link>http://www.techknowsolve.com/blog/?p=37</link>
		<comments>http://www.techknowsolve.com/blog/?p=37#comments</comments>
		<pubDate>Mon, 18 May 2009 20:45:40 +0000</pubDate>
		<dc:creator>MaryD</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[All]]></category>

		<guid isPermaLink="false">http://techknowsolve.com/blog/?p=37</guid>
		<description><![CDATA[Sometimes I want to turn tracing on in a production application to troubleshoot issues that I can&#8217;t replicate on my development machine.  It&#8217;s easy enough to do this by turning on application-level tracing in the web.config file, like so:
&#60;configuration&#62;
 &#60;system.web&#62;
  &#60;trace enabled=&#8221;true&#8221; pageOutput=&#8221;true&#8221; /&#62;
 &#60;/system.web&#62;
&#60;/configuration&#62;
The problem with this is that changes to the web.config file cause the app domain to [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes I want to turn tracing on in a production application to troubleshoot issues that I can&#8217;t replicate on my development machine.  It&#8217;s easy enough to do this by turning on application-level tracing in the web.config file, like so:</p>
<p>&lt;configuration&gt;<br />
 &lt;system.web&gt;<br />
  &lt;trace enabled=&#8221;true&#8221; pageOutput=&#8221;true&#8221; /&gt;<br />
 &lt;/system.web&gt;<br />
&lt;/configuration&gt;</p>
<p>The problem with this is that changes to the web.config file cause the app domain to recycle, which can cause users currently in the application to lose data.  So I have to schedule a time when all users have to get out, or I have to work after hours, which is a drag.</p>
<p>It&#8217;s easy enough to turn on tracing programmatically &#8211; Page.Trace.IsEnabled = true.  Then you could write code in the page&#8217;s Load event, turning tracing on if the page detects a particular querystring.  The problem here is that you&#8217;d have to add the code to every page that you might someday want to trace.</p>
<p>So I decided to create an <a target="_blank" href="http://msdn.microsoft.com/en-us/library/zec9k340(VS.85).aspx" title="HttpModule">HttpModule</a> that would turn on tracing via the querystring.  HttpModules allow you to tap in to the HttpRequest pipeline, so your code will run at a designated point in every ASP.NET request.  You can hook up your module to run at various points in the page life cycle, such as BeginRequest, AuthenticateRequest, Error, etc.  (HttpModules are also excellent for application-level error handling). </p>
<p>In order to create an HttpModule, you have to create a class that implements the IHttpModule interface.  Do this by creating your class, and then typing &#8220;Implements IHttpModule&#8221; directly under the &#8221;Public Class Whatever&#8221; line.  Once you hit enter, the two methods that your class must invoke, Init and Dispose, are automatically created for you.</p>
<p>Here&#8217;s what my HttpModule class looks like (be sure to import the System.Web namespace):</p>
<p>Option Strict On</p>
<p>Imports Microsoft.VisualBasic<br />
Imports System.Web</p>
<p>Public Class TraceModule<br />
    Implements IHttpModule</p>
<p>    Dim WithEvents app As HttpApplication = Nothing</p>
<p>    Public Sub Init(ByVal context As HttpApplication) Implements IHttpModule.Init<br />
        app = context<br />
    End Sub</p>
<p>    Public Sub context_BeginRequest(ByVal sender As Object, ByVal e As EventArgs) _<br />
    Handles app.BeginRequest</p>
<p>        Dim c As HttpContext = HttpContext.Current<br />
        Dim strTrace As String = c.Request.QueryString(&#8220;trace&#8221;)</p>
<p>        If strTrace = &#8220;on&#8221; Then<br />
            c.Trace.IsEnabled = True<br />
        End If</p>
<p>    End Sub</p>
<p>    Public Sub Dispose() Implements IHttpModule.Dispose<br />
        app = Nothing<br />
    End Sub</p>
<p>End Class</p>
<p>After you&#8217;ve created your module, you just need to add a setting in the web.config file telling ASP.NET to use your module, as shown below.  If the class is in an assembly in the bin folder, you just need to provide the class name.  If it&#8217;s in the App_Code folder, then you need to add that to the setting.</p>
<p>&lt;configuration&gt;<br />
 &lt;system.web&gt;<br />
  &lt;httpModules&gt;<br />
   &lt;!&#8211; Module class in assembly called TKS.dll in bin folder &#8211;&gt;<br />
   &lt;add name=&#8221;WebTraceModule&#8221; type=&#8221;TKS.TraceModule&#8221;/&gt;<br />
   &lt;!&#8211; Module class in App_Code folder &#8211;&gt;<br />
   &lt;add name=&#8221;WebTraceModule&#8221; type=&#8221;TraceModule, App_Code&#8221; /&gt;<br />
  &lt;/httpModules&gt;<br />
 &lt;/system.web&gt;<br />
&lt;/configuration&gt;</p>
<p>Now if you want to see the trace for any page in your application, just add the querystring &#8220;?trace=on&#8221; at the end of the URL, and the trace will display in the page without making any other changes.  If you want to add some security to this, so that not just anybody can run the trace, you can require additional querystrings, or only turn tracing on for certain users or groups, or just about anything else that you can do in code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techknowsolve.com/blog/?feed=rss2&amp;p=37</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ordinal Numbers in T-SQL</title>
		<link>http://www.techknowsolve.com/blog/?p=36</link>
		<comments>http://www.techknowsolve.com/blog/?p=36#comments</comments>
		<pubDate>Fri, 27 Feb 2009 21:06:49 +0000</pubDate>
		<dc:creator>Lis</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://techknowsolve.com/blog/?p=36</guid>
		<description><![CDATA[I wanted to write a query that took numbers and turned them into ordinal numbers – re: 1 = 1st, 2 = 2nd, 3 = 3rd, etc.
I took this code from Chip Pearson&#8217;s web site. His posting was about ordinal numbers in Excel. I converted the code to a T-SQL function, and I can now [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to write a query that took numbers and turned them into ordinal numbers – re: 1 = 1st, 2 = 2nd, 3 = 3rd, etc.</p>
<p>I took this code from <a target="_blank" href="http://www.cpearson.com/excel/ordinal.htm">Chip Pearson&#8217;s web site</a>. His posting was about ordinal numbers in Excel. I converted the code to a T-SQL function, and I can now use it in any other T-SQL queries I write. Here it is:</p>
<p>create Function dbo.OrdinalNumber<br />
/* used to return an ordinal number */<br />
(@Number integer)<br />
returns varchar(6)<br />
as begin</p>
<p>declare @N int<br />
declare @Suffix char(18)<br />
declare @Result varchar(6)</p>
<p>select @N = @Number%100<br />
select @Suffix = &#8217;stndrdthththththth&#8217;</p>
<p>If ((Abs(@N) &gt;= 10) And (Abs(@N) &lt;= 19))<br />
Or ((Abs(@N) % 10) = 0)<br />
begin<br />
select @Result= cast(@Number as varchar) + &#8216;th&#8217;<br />
end<br />
else<br />
begin<br />
select @Result = cast(@Number as varchar) + substring(@Suffix,<br />
((Abs(@N) % 10) * 2) &#8211; 1, 2)<br />
end<br />
return @Result<br />
end</p>
<p>To use it just feed it the number you want to convert.</p>
<p>select dbo.ordinalnumber(1)<br />
will return “1st”</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techknowsolve.com/blog/?feed=rss2&amp;p=36</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using &#8220;Execute As&#8221; to Test a Stored Procedure as a Different User</title>
		<link>http://www.techknowsolve.com/blog/?p=34</link>
		<comments>http://www.techknowsolve.com/blog/?p=34#comments</comments>
		<pubDate>Thu, 19 Feb 2009 19:18:22 +0000</pubDate>
		<dc:creator>Lis</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://techknowsolve.com/blog/?p=34</guid>
		<description><![CDATA[In an earlier blog post, I wrote about how to use “Execute As” in a stored procedure to access a separate database. When you include “Execute As” in a stored procedure, you can pull data from a separate database without giving your users direct permissions on that database.
Another way I really like to use “Execute [...]]]></description>
			<content:encoded><![CDATA[<p>In an earlier <a href="http://techknowsolve.com/blog/?p=22">blog post</a>, I wrote about how to use “Execute As” in a stored procedure to access a separate database. When you include “Execute As” in a stored procedure, you can pull data from a separate database without giving your users direct permissions on that database.</p>
<p>Another way I really like to use “Execute As” is to test the permissions on my stored procedures. You may have had a time or two where a stored procedure ran great when you ran it, but when your user tried it… not so great.</p>
<p>Here’s how to test as that user from either Query Analyzer or SQL Server Management Studio. First, run this line of code, substituting SOMEDOMAIN and Someuser with the appropriate information.</p>
<p><span style="color: blue">execute as login = &#8216;SOMEDOMAIN\Someuser&#8217;</span></p>
<p>Now run this line of code. It should return the login you just entered.</p>
<p><span style="color: blue">SELECT SUSER_NAME(), USER_NAME();</span></p>
<p>Now run your stored procedure.</p>
<p>When you are done testing, make sure you run this line (word, actually) of code:</p>
<p><span style="color: blue">Revert</span></p>
<p>This will set the login back to your login.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techknowsolve.com/blog/?feed=rss2&amp;p=34</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple way to renumber records in SQL Server</title>
		<link>http://www.techknowsolve.com/blog/?p=29</link>
		<comments>http://www.techknowsolve.com/blog/?p=29#comments</comments>
		<pubDate>Tue, 17 Feb 2009 19:56:28 +0000</pubDate>
		<dc:creator>MaryD</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://techknowsolve.com/blog/?p=29</guid>
		<description><![CDATA[Recently I needed to renumber a column in a database.  Specifically, I needed to be able to take a Report Number series that started with 1 (1, 2, 3, 4) and change the start number and renumber all subsequent Report Numbers (e.g, change above to 14, 15, 16, 17).
I thought I&#8217;d probably be able to [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I needed to renumber a column in a database.  Specifically, I needed to be able to take a Report Number series that started with 1 (1, 2, 3, 4) and change the start number and renumber all subsequent Report Numbers (e.g, change above to 14, 15, 16, 17).</p>
<p>I thought I&#8217;d probably be able to use a table variable with an identity column &#8211; hoped I wouldn&#8217;t have to use a cursor.  I did a quick Google search, to see how other people handled similar things and hopefully get some examples.</p>
<p>I saw the table variable solutions I expected, but then came across a <a href="http://www.tek-tips.com/faqs.cfm?fid=207" title="Renumber records" target="_blank">post</a> containing this really nifty bit of code that did the trick in four lines &#8211; very slick.  Here&#8217;s the example as it appeared in the post:</p>
<p><span name="intelliTxt" id="intelliTxt">declare @variable int<br />
set @variable = 0<br />
update &lt;tablename&gt;<br />
SET @variable = &lt;columnname&gt; = @variable + 1  </span></p>
<p>and here&#8217;s how I implemented it, along with a WHERE statement so that I only renumber the Report Numbers associated with a particular Job (@ReportNum is the new starting number, and is a parameter fed in to the stored procedure):</p>
<p>declare @counter int<br />
set @counter = @ReportNum &#8211; 1<br />
update tblReport<br />
set @counter = ReportNumber = @counter + 1<br />
where JobID = @JobID</p>
<p>Works like a charm.  I repeat &#8211; very, very slick:)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techknowsolve.com/blog/?feed=rss2&amp;p=29</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
