Dynamic PIVOT With Microsoft SQL Server
Posted by Michael Bowersox (Admin) in SQL Server on March 18, 2013
The PIVOT keyword in Microsoft SQL Server is a godsend when you need to manipulate row values into their own columns. Unfortunately, to use this PIVOT keyword, you need to supply all of the possible values that you would like to PIVOT into columns in the query. What if there you do not know the [...]
Using a Custom IDataReader to Stream Data Into a Database
Posted by Michael Bowersox (Admin) in .NET, C#, SQL Server on December 22, 2011
In a previous post, I discussed how to use the SqlBulkCopy class along with a SqlDataReader to quickly stream data from one database to another. The reason that you can use a SqlDataReader as a parameter in the WriteToServer method of SqlBulkCopy is because it implements the IDataReader interface. The great thing about this, is [...]
Streaming Data Between Databases using SqlBulkCopy and SqlDataReader
Posted by Michael Bowersox (Admin) in .NET, C#, SQL Server on December 1, 2011
One little known fact about SqlBulkCopy is that not only can the WriteToServer method use a DataTable, but it can also use any object that implements IDataReader. Since the SqlDataReader object implements the IDataReader interface, it is a perfect candidate for use with a SqlBulkCopy object. One instance where I found this extremely useful, is [...]
Recursive Queries Using CTEs
Posted by Michael Bowersox in SQL Server on November 9, 2011
I previously explained the basics of common table expressions (CTEs) as well as how to chain them in sequence when you need multiple temporary result sets to get the results you desire. One of the topics I have not covered yet is using CTEs to write recursive queries. The classic example of using a recursive [...]
NSMutableDictionary Example
Posted by Michael Bowersox in Cocoa, Objective-C on September 21, 2011
The NSMutableDictionary object is very useful item in the Cocoa toolbox. It allows you to store values which are indexed by key. It is similar to the NSDictionary object with the exception that items can be added and removed dynamically. So let’s jump right in and take a look at some sample code. Creating an [...]
Determining Database Size in Microsoft SQL Server
Posted by Michael Bowersox in SQL Server on September 2, 2011
We’ve all experienced a database administrator coming up to us and questioning why a SQL Server database is consuming so much disk space. If you’re like me, you would immediately run the sp_helpdb stored procedure to see if the log file has grown out of control: EXEC sp_helpdb 'AdventureWorks' The output of the sp_helpdb shown [...]
My Favorite Visual Studio 2010 Theme
Posted by Michael Bowersox in Development on May 8, 2011
I’ve always been a fan of visual studio themes with a darker background as I find that the white background of the default theme tends to hurt my eyes after working for a few hours straight. When starting my last job, I stuck with the default theme for a month or two before I noticed [...]
Converting From WPF Foreground to Windows Forms ForeColor
Posted by Michael Bowersox in .NET, C#, WPF on February 18, 2011
I recently had the need to read the foreground color of a WPF control to assign to the foreground color of a Windows Forms control that I had hosted in a Windows Forms Host control. Once I started investigating, I realized that this wasn’t going to be as straight forward as I planned since the [...]
Multiple CTEs in Sequence
Posted by Michael Bowersox in SQL Server on February 13, 2011
In a previous post, I discussed how to use common table expressions to generate temporary result sets that can read from and written to. In this post, I’ll show how to use two CTEs together for more complex scenarios. To illustrate how to use CTEs this way, we’ll code up a simple example using the [...]
Intro to Common Table Expressions
Posted by Michael Bowersox in SQL Server on January 28, 2011
Common table expressions (CTEs) are a powerful feature that was added to Microsoft SQL Server 2005. Common table expressions can be thought of as a temporary result set that can be used with one single SELECT, INSERT, UPDATE, or DELETE statement. The basic syntax for a CTE is the following: WITH <cte_name> (column1, column2, column3, [...]