improve.dk
Just another mindless drone looking for the perfect stack
posts - 220, comments - 475

SQL Server: Tricks


Converting between base 2, 10 and 16 in T-SQL

Written on Monday, July 11, 2011 by Mark S. Rasmussen in SQL Server: Tricks

Lean how to convert between binary (base 2), decimal integers (base 10) and hexadecimal (base 16) using T-SQL.

8 comments | Read comments
 

Copying a SQL Server database file that’s in use using Volume Shadow Copy

Written on Tuesday, June 21, 2011 by Mark S. Rasmussen in Development: .NET, SQL Server: Tricks

Learn how to copy an online SQL Server data file that is in use, using the AlphaVSS Volume Shadow Copy (VSS) functionality in C#.

No comments | Write first comment
 

Saving space by storing decimal values in integer data types

Written on Tuesday, May 31, 2011 by Mark S. Rasmussen in SQL Server: Internals, SQL Server: Tricks, SQL Server: Data Types

Learn how to effectively store decimal values in SQL Server while taking up as little space as possible.

4 comments | Read comments
 

Converting page pointers into a human readable format

Written on Thursday, April 28, 2011 by Mark S. Rasmussen in SQL Server: Internals, SQL Server: Tricks

Learn how to convert the first_page, root_page, first_iam_page and general page pointers from hexadecimal to a human readable format.

2 comments | Read comments
 

Working with identity column seed & increment values

Written on Wednesday, October 28, 2009 by Mark S. Rasmussen in SQL Server: Tricks

Learn how to find the current identity value of an identity column, how to change the seed & increment values, as well as how to retrieve the maximum and minimum values.

No comments | Write first comment
 

Controlling SqlConnection timeouts

Written on Monday, March 10, 2008 by Mark S. Rasmussen in Development: .NET, SQL Server: Tricks

Controlling the SqlConnection timeout can be tricky as there are multiple timeouts in effect. In this post I'll describe how to automatically timeout an open connection.

7 comments | Read comments
 

Weighted random selections in SQL Server

Written on Sunday, November 25, 2007 by Mark S. Rasmussen in SQL Server: Tricks

UPDATE After testing my code through based on JP’s comments, I’ve realized my implementation was way too naïve and cannot be used for most datasets. For a correct weighted random implementation, see Dems’ answer on StackOverflow. Original (flawed) implementation There are no built-in functions for selecting weighted averages in SQL Server. Fortunately it's a simple task to do so oneself. We'll use this table as an example: CREATE TABLE #tmp ( Name varchar(64), Points int ) INSERT INTO #tmp VALUES ('Mark', 25); INSERT INTO #tmp VALUES ('Jakob', 12); INSERT INTO #tmp VALUES ('Peter', 17); INSERT INTO #tmp VALUES ('Anders', 0); INSERT INTO #tmp VALUES...

20 comments | Read comments
 

SQL Server datetime rounding made easy

Written on Wednesday, December 13, 2006 by Mark S. Rasmussen in SQL Server: Tricks

Learn how to truncate & round SQL Server date & datetime values.

7 comments | Read comments